diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 474ec74bd..8e854ea5a 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,7 +1,7 @@ Changes towards version 0.7: +- Remove MEM_HANDLEs from everywhere outside of memlib - Michael - Split out RESOURCEs from the loaded data in RACE_DESC and LOCDATA structures - Michael -- Normalized all loaded resources to be flat MEM_HANDLEs - Michael - Prevent overflow for planet weight when scanning a planet (bug #1025) - from Benjamin Alan Weaver - Don't set _POSIX_THREAD_SAFE_FUNCTIONS - SvdB diff --git a/sc2/src/sc2code/cleanup.c b/sc2/src/sc2code/cleanup.c index 158dfd7a8..ffd2a691c 100644 --- a/sc2/src/sc2code/cleanup.c +++ b/sc2/src/sc2code/cleanup.c @@ -74,12 +74,12 @@ UninitKernel (BOOLEAN ships) UninitSpace (); DestroySound (ReleaseSound (MenuSounds)); - DestroyFont (ReleaseFont (MicroFont)); + DestroyFont (MicroFont); DestroyStringTable (ReleaseStringTable (GameStrings)); DestroyDrawable (ReleaseDrawable (StatusFrame)); DestroyDrawable (ReleaseDrawable (ActivityFrame)); - DestroyFont (ReleaseFont (TinyFont)); - DestroyFont (ReleaseFont (StarConFont)); + DestroyFont (TinyFont); + DestroyFont (StarConFont); UninitQueue (&race_q[0]); UninitQueue (&race_q[1]); diff --git a/sc2/src/sc2code/cnctdlg.c b/sc2/src/sc2code/cnctdlg.c index ae40ee342..2eff63403 100644 --- a/sc2/src/sc2code/cnctdlg.c +++ b/sc2/src/sc2code/cnctdlg.c @@ -609,7 +609,7 @@ MeleeConnectDialog (int side) { CONNECT_DIALOG_STATE state; - PlayerFont = CaptureFont ((FONT_REF)LoadFont (PLAYER_FONT)); + PlayerFont = LoadFont (PLAYER_FONT); state.Initialized = FALSE; state.which_side = side; @@ -622,7 +622,7 @@ MeleeConnectDialog (int side) current_state = NULL; - DestroyFont (ReleaseFont (PlayerFont)); + DestroyFont (PlayerFont); return state.confirmed; } diff --git a/sc2/src/sc2code/coderes.h b/sc2/src/sc2code/coderes.h index cccf9fd49..f7562980b 100644 --- a/sc2/src/sc2code/coderes.h +++ b/sc2/src/sc2code/coderes.h @@ -21,16 +21,15 @@ #include "reslib.h" -extern MEM_HANDLE LoadCodeResFile (const char *pStr); +extern void *LoadCodeResFile (const char *pStr); extern BOOLEAN InstallCodeResType (COUNT code_type); -extern MEM_HANDLE LoadCodeResInstance (RESOURCE res); -extern void* CaptureCodeRes (MEM_HANDLE hCode, void *pData, void **ppLocData); -extern MEM_HANDLE ReleaseCodeRes (void *CodeRef); -extern BOOLEAN DestroyCodeRes (MEM_HANDLE hCode); +extern void *LoadCodeResInstance (RESOURCE res); +extern void *CaptureCodeRes (void *hCode, void *pData, void **ppLocData); +extern void *ReleaseCodeRes (void *CodeRef); +extern BOOLEAN DestroyCodeRes (void *hCode); typedef struct { - MEM_HANDLE hCode; UWORD size; } CODE_REF; diff --git a/sc2/src/sc2code/comm.c b/sc2/src/sc2code/comm.c index ec72d5959..5d072544b 100644 --- a/sc2/src/sc2code/comm.c +++ b/sc2/src/sc2code/comm.c @@ -1298,7 +1298,7 @@ DoResponsePhrase (RESPONSE_REF R, RESPONSE_FUNC response_func, static void HailAlien (void) { - MEM_HANDLE hOldIndex; + RESOURCE_INDEX hOldIndex; ENCOUNTER_STATE ES; FONT PlayerFont, OldFont; MUSIC_REF SongRef = 0; @@ -1309,13 +1309,12 @@ HailAlien (void) ES.InputFunc = DoCommunication; hOldIndex = SetResourceIndex (hResIndex); - PlayerFont = CaptureFont ((FONT_REF)LoadFont (PLAYER_FONT)); + PlayerFont = LoadFont (PLAYER_FONT); SetResourceIndex (hOldIndex); CommData.AlienFrame = CaptureDrawable ( LoadGraphic (CommData.AlienFrameRes)); - CommData.AlienFont = CaptureFont ((FONT_REF) - LoadFont (CommData.AlienFontRes)); + CommData.AlienFont = LoadFont (CommData.AlienFontRes); CommData.AlienColorMap = CaptureColorMap ( LoadColorMap (CommData.AlienColorMapRes)); if ((CommData.AlienSongFlags & LDASF_USE_ALTERNATE) @@ -1417,7 +1416,7 @@ HailAlien (void) DestroyStringTable (ReleaseStringTable (CommData.ConversationPhrases)); DestroyMusic (CommData.AlienSong); DestroyColorMap (ReleaseColorMap (CommData.AlienColorMap)); - DestroyFont (ReleaseFont (CommData.AlienFont)); + DestroyFont (CommData.AlienFont); DestroyDrawable (ReleaseDrawable (CommData.AlienFrame)); DestroyContext (TextCacheContext); @@ -1425,7 +1424,7 @@ HailAlien (void) SetContext (SpaceContext); SetContextFont (OldFont); - DestroyFont (ReleaseFont (PlayerFont)); + DestroyFont (PlayerFont); CommData.ConversationPhrases = 0; pCurInputState = 0; @@ -1435,7 +1434,7 @@ COUNT InitCommunication (RESOURCE which_comm) { COUNT status; - MEM_HANDLE hOldIndex, hIndex; + RESOURCE_INDEX hOldIndex, hIndex; LOCDATA *LocDataPtr; #ifdef DEBUG diff --git a/sc2/src/sc2code/comm/arilou/arilouc.c b/sc2/src/sc2code/comm/arilou/arilouc.c index e690ba10b..00fc08b0a 100644 --- a/sc2/src/sc2code/comm/arilou/arilouc.c +++ b/sc2/src/sc2code/comm/arilou/arilouc.c @@ -223,7 +223,7 @@ static LOCDATA arilou_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/blackur/blackurc.c b/sc2/src/sc2code/comm/blackur/blackurc.c index 9abc7c203..33a79a1f9 100644 --- a/sc2/src/sc2code/comm/blackur/blackurc.c +++ b/sc2/src/sc2code/comm/blackur/blackurc.c @@ -125,7 +125,7 @@ static LOCDATA blackurq_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/chmmr/chmmrc.c b/sc2/src/sc2code/comm/chmmr/chmmrc.c index 5d3c3688e..e9c051033 100644 --- a/sc2/src/sc2code/comm/chmmr/chmmrc.c +++ b/sc2/src/sc2code/comm/chmmr/chmmrc.c @@ -111,7 +111,7 @@ static LOCDATA chmmr_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/comandr/comandr.c b/sc2/src/sc2code/comm/comandr/comandr.c index 17b7389f3..e971f7ccf 100644 --- a/sc2/src/sc2code/comm/comandr/comandr.c +++ b/sc2/src/sc2code/comm/comandr/comandr.c @@ -86,7 +86,7 @@ static LOCDATA commander_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/druuge/druugec.c b/sc2/src/sc2code/comm/druuge/druugec.c index 94f6e124a..e85d5a482 100644 --- a/sc2/src/sc2code/comm/druuge/druugec.c +++ b/sc2/src/sc2code/comm/druuge/druugec.c @@ -152,7 +152,7 @@ static LOCDATA druuge_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/ilwrath/ilwrathc.c b/sc2/src/sc2code/comm/ilwrath/ilwrathc.c index bebab2f72..258af3d69 100644 --- a/sc2/src/sc2code/comm/ilwrath/ilwrathc.c +++ b/sc2/src/sc2code/comm/ilwrath/ilwrathc.c @@ -95,7 +95,7 @@ static LOCDATA ilwrath_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/melnorm/melnorm.c b/sc2/src/sc2code/comm/melnorm/melnorm.c index 5cc0ca73e..803e7a3b1 100644 --- a/sc2/src/sc2code/comm/melnorm/melnorm.c +++ b/sc2/src/sc2code/comm/melnorm/melnorm.c @@ -106,7 +106,7 @@ static LOCDATA melnorme_desc = &melnorme_numbers_english, /* AlienNumberSpeech - default */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/mycon/myconc.c b/sc2/src/sc2code/comm/mycon/myconc.c index 3c2634b79..60be1a17a 100644 --- a/sc2/src/sc2code/comm/mycon/myconc.c +++ b/sc2/src/sc2code/comm/mycon/myconc.c @@ -104,7 +104,7 @@ static LOCDATA mycon_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/orz/orzc.c b/sc2/src/sc2code/comm/orz/orzc.c index eb42136c2..e0b4c2008 100644 --- a/sc2/src/sc2code/comm/orz/orzc.c +++ b/sc2/src/sc2code/comm/orz/orzc.c @@ -166,7 +166,7 @@ static LOCDATA orz_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/pkunk/pkunkc.c b/sc2/src/sc2code/comm/pkunk/pkunkc.c index 1b907b12d..8d07a7323 100644 --- a/sc2/src/sc2code/comm/pkunk/pkunkc.c +++ b/sc2/src/sc2code/comm/pkunk/pkunkc.c @@ -91,7 +91,7 @@ static LOCDATA pkunk_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/rebel/rebel.c b/sc2/src/sc2code/comm/rebel/rebel.c index 61faf2893..fd4ad1c1f 100644 --- a/sc2/src/sc2code/comm/rebel/rebel.c +++ b/sc2/src/sc2code/comm/rebel/rebel.c @@ -188,7 +188,7 @@ static LOCDATA yehat_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/shofixt/shofixt.c b/sc2/src/sc2code/comm/shofixt/shofixt.c index f0364e114..a49fb6e21 100644 --- a/sc2/src/sc2code/comm/shofixt/shofixt.c +++ b/sc2/src/sc2code/comm/shofixt/shofixt.c @@ -152,7 +152,7 @@ static LOCDATA shofixti_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/slyhome/slyhome.c b/sc2/src/sc2code/comm/slyhome/slyhome.c index 1c7679910..6028d54a9 100644 --- a/sc2/src/sc2code/comm/slyhome/slyhome.c +++ b/sc2/src/sc2code/comm/slyhome/slyhome.c @@ -166,7 +166,7 @@ static LOCDATA slylandro_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/slyland/slyland.c b/sc2/src/sc2code/comm/slyland/slyland.c index 7008e92d6..a8751a5de 100644 --- a/sc2/src/sc2code/comm/slyland/slyland.c +++ b/sc2/src/sc2code/comm/slyland/slyland.c @@ -113,7 +113,7 @@ static LOCDATA slylandro_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/spahome/spahome.c b/sc2/src/sc2code/comm/spahome/spahome.c index 881ee1af7..06a49b0f0 100644 --- a/sc2/src/sc2code/comm/spahome/spahome.c +++ b/sc2/src/sc2code/comm/spahome/spahome.c @@ -179,7 +179,7 @@ static LOCDATA spahome_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/spathi/spathic.c b/sc2/src/sc2code/comm/spathi/spathic.c index 312202a3f..a8ad831ea 100644 --- a/sc2/src/sc2code/comm/spathi/spathic.c +++ b/sc2/src/sc2code/comm/spathi/spathic.c @@ -140,7 +140,7 @@ static LOCDATA spathi_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/starbas/starbas.c b/sc2/src/sc2code/comm/starbas/starbas.c index 667ae2bd1..bf20a8908 100644 --- a/sc2/src/sc2code/comm/starbas/starbas.c +++ b/sc2/src/sc2code/comm/starbas/starbas.c @@ -154,7 +154,7 @@ static LOCDATA commander_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/supox/supoxc.c b/sc2/src/sc2code/comm/supox/supoxc.c index 60fc51bea..683fe5f89 100644 --- a/sc2/src/sc2code/comm/supox/supoxc.c +++ b/sc2/src/sc2code/comm/supox/supoxc.c @@ -96,7 +96,7 @@ static LOCDATA supox_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/syreen/syreenc.c b/sc2/src/sc2code/comm/syreen/syreenc.c index 2e98298be..3147ebfb7 100644 --- a/sc2/src/sc2code/comm/syreen/syreenc.c +++ b/sc2/src/sc2code/comm/syreen/syreenc.c @@ -186,7 +186,7 @@ static LOCDATA syreen_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/talkpet/talkpet.c b/sc2/src/sc2code/comm/talkpet/talkpet.c index e39b7106c..49954360d 100644 --- a/sc2/src/sc2code/comm/talkpet/talkpet.c +++ b/sc2/src/sc2code/comm/talkpet/talkpet.c @@ -193,7 +193,7 @@ static LOCDATA talkpet_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/thradd/thraddc.c b/sc2/src/sc2code/comm/thradd/thraddc.c index 6581e45b8..3a95efc79 100644 --- a/sc2/src/sc2code/comm/thradd/thraddc.c +++ b/sc2/src/sc2code/comm/thradd/thraddc.c @@ -129,7 +129,7 @@ static LOCDATA thradd_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/umgah/umgahc.c b/sc2/src/sc2code/comm/umgah/umgahc.c index 39bc04dcd..d16f5ab14 100644 --- a/sc2/src/sc2code/comm/umgah/umgahc.c +++ b/sc2/src/sc2code/comm/umgah/umgahc.c @@ -191,7 +191,7 @@ static LOCDATA umgah_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/urquan/urquanc.c b/sc2/src/sc2code/comm/urquan/urquanc.c index 78fb26ac4..ecc39a3cd 100644 --- a/sc2/src/sc2code/comm/urquan/urquanc.c +++ b/sc2/src/sc2code/comm/urquan/urquanc.c @@ -116,7 +116,7 @@ static LOCDATA urquan_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/utwig/utwigc.c b/sc2/src/sc2code/comm/utwig/utwigc.c index 00943e632..d6e3de148 100644 --- a/sc2/src/sc2code/comm/utwig/utwigc.c +++ b/sc2/src/sc2code/comm/utwig/utwigc.c @@ -193,7 +193,7 @@ static LOCDATA utwig_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/vux/vuxc.c b/sc2/src/sc2code/comm/vux/vuxc.c index c27a1fed1..a8c357bfc 100644 --- a/sc2/src/sc2code/comm/vux/vuxc.c +++ b/sc2/src/sc2code/comm/vux/vuxc.c @@ -196,7 +196,7 @@ static LOCDATA vux_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/yehat/yehatc.c b/sc2/src/sc2code/comm/yehat/yehatc.c index 48240a2f7..99455b835 100644 --- a/sc2/src/sc2code/comm/yehat/yehatc.c +++ b/sc2/src/sc2code/comm/yehat/yehatc.c @@ -187,7 +187,7 @@ static LOCDATA yehat_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/comm/zoqfot/zoqfotc.c b/sc2/src/sc2code/comm/zoqfot/zoqfotc.c index 046bd9507..ae627ff1a 100644 --- a/sc2/src/sc2code/comm/zoqfot/zoqfotc.c +++ b/sc2/src/sc2code/comm/zoqfot/zoqfotc.c @@ -105,7 +105,7 @@ static LOCDATA zoqfot_desc = NULL, /* AlienNumberSpeech - none */ /* Filler for loaded resources */ NULL, NULL, NULL, - NULL_HANDLE, + NULL, NULL, }; diff --git a/sc2/src/sc2code/credits.c b/sc2/src/sc2code/credits.c index bf8c1b93a..580743773 100644 --- a/sc2/src/sc2code/credits.c +++ b/sc2/src/sc2code/credits.c @@ -554,7 +554,7 @@ StartCredits (void) CreditsBack = CaptureDrawable (LoadGraphic (CREDITS_BACK_ANIM)); // load fonts for (fdef = CreditsFont; fdef->size; ++fdef) - fdef->font = CaptureFont (LoadFont (fdef->res)); + fdef->font = LoadFont (fdef->res); CreditsRate = CREDITS_BASE_RATE; CreditsRunning = FALSE; @@ -578,7 +578,7 @@ FreeCredits (void) // free fonts for (fdef = CreditsFont; fdef->size; ++fdef) { - DestroyFont (ReleaseFont (fdef->font)); + DestroyFont (fdef->font); fdef->font = 0; } } diff --git a/sc2/src/sc2code/dummy.c b/sc2/src/sc2code/dummy.c index 59c7861d4..12f55ba0c 100644 --- a/sc2/src/sc2code/dummy.c +++ b/sc2/src/sc2code/dummy.c @@ -33,18 +33,17 @@ typedef struct { - MEM_HANDLE handle; RACE_DESC data _ALIGNED_ANY; } CODERES_STRUCT; -MEM_HANDLE +void * LoadCodeResFile (const char *pStr) { (void) pStr; /* Satisfying compiler (unused parameter) */ - return (0); + return NULL; } -static MEM_HANDLE +static void * GetCodeResData (uio_Stream *fp, DWORD length) { enum @@ -81,15 +80,15 @@ enum }; BYTE which_res; - MEM_HANDLE hData; + void *hData; which_res = GetResFileChar (fp); - hData = mem_allocate (sizeof (CODERES_STRUCT), DEFAULT_MEM_FLAGS); + hData = HMalloc (sizeof (CODERES_STRUCT)); if (hData) { RACE_DESC *RDPtr; - RDPtr = 0; + RDPtr = NULL; switch (which_res) { case ANDROSYN_CODE_RES: @@ -295,36 +294,40 @@ enum if (RDPtr == 0) { - mem_release (hData); + HFree (hData); hData = 0; } else { CODERES_STRUCT *cs; - cs = (CODERES_STRUCT *) mem_lock (hData); - cs->data = *RDPtr; - // Structure assignment. - mem_unlock (hData); + cs = (CODERES_STRUCT *) hData; + cs->data = *RDPtr; // Structure assignment. } } (void) length; /* Satisfying compiler (unused parameter) */ return (hData); } +BOOLEAN +_ReleaseCodeResData (void *data) +{ + HFree (data); + return TRUE; +} BOOLEAN InstallCodeResType (COUNT code_type) { return (InstallResTypeVectors (code_type, - GetCodeResData, mem_release)); + GetCodeResData, _ReleaseCodeResData)); } -MEM_HANDLE +void * LoadCodeResInstance (DWORD res) { - MEM_HANDLE hData; + void *hData; hData = res_GetResource (res); if (hData) @@ -335,25 +338,25 @@ LoadCodeResInstance (DWORD res) BOOLEAN -DestroyCodeRes (MEM_HANDLE hCode) +DestroyCodeRes (void *hCode) { - return (mem_release (hCode)); + HFree (hCode); + return (TRUE); } void* -CaptureCodeRes (MEM_HANDLE hCode, void *pData, void **ppLocData) +CaptureCodeRes (void *hCode, void *pData, void **ppLocData) { CODERES_STRUCT *cs; - if (hCode == 0) + if (hCode == NULL) { - log_add (log_Fatal, "dummy.c::CaptureCodeRes() hCode==0! FATAL!"); - return(0); + log_add (log_Fatal, "dummy.c::CaptureCodeRes() hCode==NULL! FATAL!"); + return(NULL); } - cs = (CODERES_STRUCT *) mem_lock (hCode); - cs->handle = hCode; + cs = (CODERES_STRUCT *) hCode; *ppLocData = &cs->data; (void) pData; /* Satisfying compiler (unused parameter) */ @@ -361,16 +364,8 @@ CaptureCodeRes (MEM_HANDLE hCode, void *pData, void **ppLocData) } -MEM_HANDLE +void * ReleaseCodeRes (void *CodeRef) { - if (CodeRef) - { - MEM_HANDLE hCode; - - mem_unlock (hCode = *(MEM_HANDLE *)CodeRef); - return (hCode); - } - - return (0); + return CodeRef; } \ No newline at end of file diff --git a/sc2/src/sc2code/encount.c b/sc2/src/sc2code/encount.c index 8e5f9c197..31221219d 100644 --- a/sc2/src/sc2code/encount.c +++ b/sc2/src/sc2code/encount.c @@ -184,7 +184,7 @@ COUNT InitEncounter (void) { COUNT i; - MEM_HANDLE hOldIndex; + RESOURCE_INDEX hOldIndex; FRAME SegueFrame; STAMP s; TEXT t; @@ -713,7 +713,7 @@ ExitUninitEncounter: void EncounterBattle (void) { - MEM_HANDLE hLastIndex; + RESOURCE_INDEX hLastIndex; ACTIVITY OldActivity; extern UWORD nth_frame; diff --git a/sc2/src/sc2code/globdata.c b/sc2/src/sc2code/globdata.c index 0721e123a..dd6644a99 100644 --- a/sc2/src/sc2code/globdata.c +++ b/sc2/src/sc2code/globdata.c @@ -142,7 +142,7 @@ LoadSC2Data (void) { if (FlagStatFrame == 0) { - MEM_HANDLE hOldIndex; + RESOURCE_INDEX hOldIndex; hOldIndex = SetResourceIndex (hResIndex); diff --git a/sc2/src/sc2code/gravwell.c b/sc2/src/sc2code/gravwell.c index 2fdad9caf..fd3952f86 100644 --- a/sc2/src/sc2code/gravwell.c +++ b/sc2/src/sc2code/gravwell.c @@ -31,7 +31,7 @@ load_gravity_well (BYTE selector) RES_TYPE rt; RES_INSTANCE ri; RES_PACKAGE rp; - MEM_HANDLE hLastIndex; + RESOURCE_INDEX hLastIndex; hLastIndex = SetResourceIndex (hResIndex); diff --git a/sc2/src/sc2code/init.c b/sc2/src/sc2code/init.c index 59b2724e6..3eb3f70d9 100644 --- a/sc2/src/sc2code/init.c +++ b/sc2/src/sc2code/init.c @@ -65,19 +65,35 @@ load_animation (FRAME *pixarray, RESOURCE big_res, RESOURCE med_res, RESOURCE return TRUE; } +/* Warning: Some ships (such as the Umgah) will alias their pixarrays, + so we need to track to make sure that we do not double-free. */ BOOLEAN free_image (FRAME *pixarray) { BOOLEAN retval; - COUNT i; + COUNT i, j; + void *already_freed[NUM_VIEWS]; retval = TRUE; for (i = 0; i < NUM_VIEWS; ++i) { if (pixarray[i] != NULL) { - if (!DestroyDrawable (ReleaseDrawable (pixarray[i]))) - retval = FALSE; + BOOLEAN ok = TRUE; + for (j = 0; j < i; j++) + { + if (already_freed[j] == pixarray[i]) + { + ok = FALSE; + break; + } + } + if (ok) + { + if (!DestroyDrawable (ReleaseDrawable (pixarray[i]))) + retval = FALSE; + } + already_freed[i] = pixarray[i]; pixarray[i] = NULL; } } diff --git a/sc2/src/sc2code/intro.c b/sc2/src/sc2code/intro.c index f195f5f76..1b2c5bd7c 100644 --- a/sc2/src/sc2code/intro.c +++ b/sc2/src/sc2code/intro.c @@ -430,8 +430,8 @@ DoPresentation (void *pIS) if (pPIS->Buffer[0]) { /* asked to load a font */ if (*pFont) - DestroyFont (ReleaseFont (*pFont)); - *pFont = CaptureFont ((FONT_REF) LoadFontFile (pPIS->Buffer)); + DestroyFont (*pFont); + *pFont = LoadFontFile (pPIS->Buffer); } if (!pPIS->Batched) @@ -847,7 +847,7 @@ ShowPresentation (STRING PresStr) DestroyDrawable (ReleaseDrawable (pis.RotatedFrame)); DestroyDrawable (ReleaseDrawable (pis.Frame)); for (i = 0; i < MAX_FONTS; ++i) - DestroyFont (ReleaseFont (pis.Fonts[i])); + DestroyFont (pis.Fonts[i]); DestroyStringTable (ReleaseStringTable (pis.SlideShow)); LockMutex (GraphicsLock); diff --git a/sc2/src/sc2code/libs/decomp/lzencode.c b/sc2/src/sc2code/libs/decomp/lzencode.c index fa0f9d0cd..c72ddb2e0 100644 --- a/sc2/src/sc2code/libs/decomp/lzencode.c +++ b/sc2/src/sc2code/libs/decomp/lzencode.c @@ -36,7 +36,7 @@ static SWORD *encode_arrays; #define AllocEncodeArrays() \ HCalloc ( \ - (MEM_SIZE)(((N + 1) + (N + 257) + (N + 1)) \ + (((N + 1) + (N + 257) + (N + 1)) \ * sizeof (lson[0]))) #define FreeCodeArrays HFree diff --git a/sc2/src/sc2code/libs/decomp/lzh.h b/sc2/src/sc2code/libs/decomp/lzh.h index 2423569ef..e46949751 100644 --- a/sc2/src/sc2code/libs/decomp/lzh.h +++ b/sc2/src/sc2code/libs/decomp/lzh.h @@ -75,7 +75,7 @@ typedef LZHCODE_DESC *PLZHCODE_DESC; (*_Stream++ = (BYTE)(c))) -#define AllocCodeDesc() HCalloc ((MEM_SIZE)sizeof (LZHCODE_DESC)) +#define AllocCodeDesc() HCalloc (sizeof (LZHCODE_DESC)) #define FreeCodeDesc HFree extern void _update (COUNT c); diff --git a/sc2/src/sc2code/libs/gfxlib.h b/sc2/src/sc2code/libs/gfxlib.h index 32f606e0d..5186eb7d1 100644 --- a/sc2/src/sc2code/libs/gfxlib.h +++ b/sc2/src/sc2code/libs/gfxlib.h @@ -19,15 +19,17 @@ #ifndef _GFXLIB_H #define _GFXLIB_H -#include "memlib.h" +#include "compiler.h" typedef struct context_desc CONTEXT_DESC; typedef struct frame_desc FRAME_DESC; typedef struct font_desc FONT_DESC; +typedef struct drawable_desc DRAWABLE_DESC; typedef CONTEXT_DESC *CONTEXT; typedef FRAME_DESC *FRAME; typedef FONT_DESC *FONT; +typedef DRAWABLE_DESC *DRAWABLE; typedef UWORD TIME_VALUE; @@ -131,10 +133,6 @@ typedef struct STAMP IntersectStamp; } INTERSECT_CONTROL; -typedef MEM_HANDLE DRAWABLE; - -typedef MEM_HANDLE FONT_REF; - typedef BYTE INTERSECT_CODE; #define INTERSECT_LEFT (INTERSECT_CODE)(1 << 0) @@ -203,15 +201,13 @@ extern BOOLEAN GetFrameRect (FRAME Frame, RECT *pRect); extern HOT_SPOT SetFrameHot (FRAME Frame, HOT_SPOT HotSpot); extern HOT_SPOT GetFrameHot (FRAME Frame); extern BOOLEAN InstallGraphicResTypes (COUNT cel_type, COUNT font_type); -extern DWORD LoadGraphicFile (const char *pStr); -extern DWORD LoadFontFile (const char *pStr); -extern DWORD LoadGraphicInstance (DWORD res); +extern DRAWABLE LoadGraphicFile (const char *pStr); +extern FONT LoadFontFile (const char *pStr); +extern void *LoadGraphicInstance (DWORD res); extern DRAWABLE LoadDisplayPixmap (RECT *area, FRAME frame); extern FRAME SetContextFontEffect (FRAME EffectFrame); extern FONT SetContextFont (FONT Font); -extern BOOLEAN DestroyFont (FONT_REF FontRef); -extern FONT CaptureFont (FONT_REF FontRef); -extern FONT_REF ReleaseFont (FONT Font); +extern BOOLEAN DestroyFont (FONT FontRef); extern BOOLEAN TextRect (TEXT *pText, RECT *pRect, BYTE *pdelta); extern BOOLEAN GetContextFontLeading (SIZE *pheight); extern BOOLEAN GetContextFontLeadingWidth (SIZE *pwidth); @@ -228,7 +224,7 @@ extern void SetFrameTransparentColor (FRAME Frame, COLOR c32k); extern FRAME CaptureDrawable (DRAWABLE Drawable); extern DRAWABLE ReleaseDrawable (FRAME Frame); -extern MEM_HANDLE GetFrameHandle (FRAME Frame); +extern DRAWABLE GetFrameParentDrawable (FRAME Frame); extern BOOLEAN SetColorMap (COLORMAPPTR ColorMapPtr); extern DWORD XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval); diff --git a/sc2/src/sc2code/libs/graphics/context.h b/sc2/src/sc2code/libs/graphics/context.h index 8e6a86377..363503003 100644 --- a/sc2/src/sc2code/libs/graphics/context.h +++ b/sc2/src/sc2code/libs/graphics/context.h @@ -41,7 +41,7 @@ struct context_desc }; -#define AllocContext() HCalloc ((MEM_SIZE)sizeof (CONTEXT_DESC)) +#define AllocContext() HCalloc (sizeof (CONTEXT_DESC)) #define FreeContext HFree extern CONTEXT _pCurContext; diff --git a/sc2/src/sc2code/libs/graphics/drawable.c b/sc2/src/sc2code/libs/graphics/drawable.c index c15fea55e..ad950fb7f 100644 --- a/sc2/src/sc2code/libs/graphics/drawable.c +++ b/sc2/src/sc2code/libs/graphics/drawable.c @@ -83,20 +83,17 @@ DRAWABLE AllocDrawable (COUNT n) { DRAWABLE Drawable; - Drawable = (DRAWABLE)mem_allocate ((MEM_SIZE)(sizeof (DRAWABLE_DESC)), - MEM_ZEROINIT | MEM_GRAPHICS); + Drawable = (DRAWABLE) HCalloc(sizeof (DRAWABLE_DESC)); if (Drawable) { - DRAWABLE_DESC *DrawablePtr; int i; - DrawablePtr = LockDrawable (Drawable); - DrawablePtr->Frame = (FRAME)HMalloc ((MEM_SIZE)(sizeof (FRAME_DESC) * n)); + Drawable->Frame = (FRAME)HMalloc (sizeof (FRAME_DESC) * n); /* Zero out the newly allocated frames, since HMalloc doesn't have MEM_ZEROINIT. */ for (i = 0; i < n; i++) { FRAME F; - F = &DrawablePtr->Frame[i]; - F->parent = DrawablePtr; + F = &Drawable->Frame[i]; + F->parent = Drawable; F->Type = 0; F->Index = 0; F->image = 0; @@ -105,8 +102,6 @@ AllocDrawable (COUNT n) F->HotSpot.x = 0; F->HotSpot.y = 0; } - - UnlockDrawable (Drawable); } return Drawable; } @@ -143,15 +138,11 @@ CreateDrawable (CREATE_FLAGS CreateFlags, SIZE width, SIZE height, COUNT BOOLEAN DestroyDrawable (DRAWABLE Drawable) { - DRAWABLE_DESC *DrawablePtr; + if (_CurFramePtr && (Drawable == _CurFramePtr->parent)) + SetContextFGFrame ((FRAME)NULL); - if (LOWORD (Drawable) == GetFrameHandle (_CurFramePtr)) - SetContextFGFrame ((FRAME)0); - - DrawablePtr = LockDrawable (Drawable); - if (DrawablePtr) + if (Drawable) { - UnlockDrawable (Drawable); FreeDrawable (Drawable); return (TRUE); diff --git a/sc2/src/sc2code/libs/graphics/drawable.h b/sc2/src/sc2code/libs/graphics/drawable.h index e1afac149..bd297dd03 100644 --- a/sc2/src/sc2code/libs/graphics/drawable.h +++ b/sc2/src/sc2code/libs/graphics/drawable.h @@ -50,8 +50,6 @@ struct frame_desc typedef struct drawable_desc { - MEM_HANDLE hDrawable; - CREATE_FLAGS Flags; UWORD MaxIndex; FRAME_DESC *Frame; @@ -66,10 +64,7 @@ typedef struct drawable_desc #define DRAWABLE_PRIORITY DEFAULT_MEM_PRIORITY extern DRAWABLE AllocDrawable (COUNT num_frames); -#define LockDrawable(D) ((DRAWABLE_DESC*)mem_lock (D)) -#define UnlockDrawable(D) mem_unlock (D) #define FreeDrawable(D) _ReleaseCelData (D) -#define GetFrameParentDrawable(F) (F)->parent #define TYPE_GET(f) ((f) & FTYPE_MASK) #define INDEX_GET(f) ((f) & FINDEX_MASK) @@ -86,8 +81,8 @@ extern DRAWABLE _request_drawable (COUNT NumFrames, DRAWABLE_TYPE DrawableType, CREATE_FLAGS flags, SIZE width, SIZE height); extern INTERSECT_CODE _clip_line (RECT *pClipRect, BRESENHAM_LINE *pLine); -extern MEM_HANDLE _GetCelData (uio_Stream *fp, DWORD length); -extern BOOLEAN _ReleaseCelData (MEM_HANDLE handle); +extern void *_GetCelData (uio_Stream *fp, DWORD length); +extern BOOLEAN _ReleaseCelData (void *handle); extern STAMP _save_stamp; extern FRAME _CurFramePtr; diff --git a/sc2/src/sc2code/libs/graphics/filegfx.c b/sc2/src/sc2code/libs/graphics/filegfx.c index 9b43bae20..d2119f298 100644 --- a/sc2/src/sc2code/libs/graphics/filegfx.c +++ b/sc2/src/sc2code/libs/graphics/filegfx.c @@ -21,7 +21,7 @@ #include "libs/reslib.h" -DWORD +DRAWABLE LoadGraphicFile (const char *pStr) { uio_Stream *fp; @@ -34,19 +34,19 @@ LoadGraphicFile (const char *pStr) fp = res_OpenResFile (contentDir, pStr, "rb"); if (fp != NULL) { - MEM_HANDLE hData; + DRAWABLE hData; _cur_resfile_name = pStr; - hData = _GetCelData (fp, LengthResFile (fp)); + hData = (DRAWABLE)_GetCelData (fp, LengthResFile (fp)); _cur_resfile_name = 0; res_CloseResFile (fp); - return ((DWORD)hData); + return hData; } - return (0); + return (NULL); } -DWORD +FONT LoadFontFile (const char *pStr) { uio_Stream *fp; @@ -59,13 +59,13 @@ LoadFontFile (const char *pStr) fp = res_OpenResFile (contentDir, pStr, "rb"); if (fp == (uio_Stream *) ~0) { - MEM_HANDLE hData; + FONT hData; _cur_resfile_name = pStr; - hData = _GetFontData (fp, LengthResFile (fp)); + hData = (FONT)_GetFontData (fp, LengthResFile (fp)); _cur_resfile_name = 0; res_CloseResFile (fp); - return ((DWORD)hData); + return hData; } return (0); diff --git a/sc2/src/sc2code/libs/graphics/font.c b/sc2/src/sc2code/libs/graphics/font.c index a4a3e533a..ac355e1fa 100644 --- a/sc2/src/sc2code/libs/graphics/font.c +++ b/sc2/src/sc2code/libs/graphics/font.c @@ -42,48 +42,17 @@ SetContextFont (FONT Font) } BOOLEAN -DestroyFont (FONT_REF FontRef) +DestroyFont (FONT FontRef) { - if (FontRef == 0) + if (FontRef == NULL) return (FALSE); - if (_CurFontPtr && _CurFontPtr->FontRef == FontRef) - SetContextFont ((FONT)0); + if (_CurFontPtr && _CurFontPtr == FontRef) + SetContextFont ((FONT)NULL); return (FreeFont (FontRef)); } -FONT -CaptureFont (FONT_REF FontRef) -{ - FONT FontPtr; - - FontPtr = LockFont (FontRef); - if (FontPtr) - FontPtr->FontRef = FontRef; - - return FontPtr; -} - -FONT_REF -ReleaseFont (FONT Font) -{ - FONT FontPtr; - - FontPtr = Font; - if (FontPtr) - { - FONT_REF FontRef; - - FontRef = FontPtr->FontRef; - UnlockFont (FontRef); - - return (FontRef); - } - - return (0); -} - void font_DrawText (TEXT *lpText) { diff --git a/sc2/src/sc2code/libs/graphics/font.h b/sc2/src/sc2code/libs/graphics/font.h index 03e123861..b6964bcff 100644 --- a/sc2/src/sc2code/libs/graphics/font.h +++ b/sc2/src/sc2code/libs/graphics/font.h @@ -48,8 +48,6 @@ FreeFontPage (FONT_PAGE *page) struct font_desc { - FONT_REF FontRef; - UWORD Leading; UWORD LeadingWidth; FONT_PAGE *fontPages; @@ -59,17 +57,13 @@ struct font_desc #define FONT_PRIORITY DEFAULT_MEM_PRIORITY -#define AllocFont(size) \ - (FONT_REF)mem_allocate ((MEM_SIZE)(sizeof (FONT_DESC) + (size)), \ - MEM_ZEROINIT | MEM_GRAPHICS) -#define LockFont(h) (FONT)mem_lock (h) -#define UnlockFont(h) mem_unlock (h) +#define AllocFont(size) (FONT)HCalloc (sizeof (FONT_DESC) + (size)) #define FreeFont _ReleaseFontData extern FONT _CurFontPtr; -extern MEM_HANDLE _GetFontData (uio_Stream *fp, DWORD length); -extern BOOLEAN _ReleaseFontData (MEM_HANDLE handle); +extern void *_GetFontData (uio_Stream *fp, DWORD length); +extern BOOLEAN _ReleaseFontData (void *handle); #endif /* _FONT_H */ diff --git a/sc2/src/sc2code/libs/graphics/loaddisp.c b/sc2/src/sc2code/libs/graphics/loaddisp.c index d45de86a5..c1e88e34f 100644 --- a/sc2/src/sc2code/libs/graphics/loaddisp.c +++ b/sc2/src/sc2code/libs/graphics/loaddisp.c @@ -36,7 +36,7 @@ DRAWABLE LoadDisplayPixmap (RECT *area, FRAME frame) { - MEM_HANDLE buffer = GetFrameHandle (frame); + DRAWABLE buffer = GetFrameParentDrawable (frame); COUNT index = GetFrameIndex (frame); if (buffer || (buffer = CreateDrawable ( diff --git a/sc2/src/sc2code/libs/graphics/pixmap.c b/sc2/src/sc2code/libs/graphics/pixmap.c index 7844fefe7..6e68244cf 100644 --- a/sc2/src/sc2code/libs/graphics/pixmap.c +++ b/sc2/src/sc2code/libs/graphics/pixmap.c @@ -19,18 +19,25 @@ #include "gfxintrn.h" #include "libs/log.h" -FRAME -CaptureDrawable (DRAWABLE Drawable) +DRAWABLE +GetFrameParentDrawable (FRAME f) { - DRAWABLE_DESC *DrawablePtr; + if (f != NULL) + { + return f->parent; + } + return NULL; +} - DrawablePtr = LockDrawable (Drawable); +FRAME +CaptureDrawable (DRAWABLE DrawablePtr) +{ if (DrawablePtr) { return &DrawablePtr->Frame[0]; } - return (0); + return NULL; } DRAWABLE @@ -39,28 +46,13 @@ ReleaseDrawable (FRAME FramePtr) if (FramePtr != 0) { DRAWABLE Drawable; - DRAWABLE_DESC *DrawablePtr; - DrawablePtr = GetFrameParentDrawable (FramePtr); - Drawable = DrawablePtr->hDrawable; - UnlockDrawable (Drawable); + Drawable = GetFrameParentDrawable (FramePtr); return (Drawable); } - return NULL_HANDLE; -} - -MEM_HANDLE -GetFrameHandle (FRAME FramePtr) -{ - DRAWABLE_DESC *DrawablePtr; - - if (FramePtr == 0) - return (0); - - DrawablePtr = GetFrameParentDrawable (FramePtr); - return (DrawablePtr->hDrawable); + return NULL; } COUNT diff --git a/sc2/src/sc2code/libs/graphics/resgfx.c b/sc2/src/sc2code/libs/graphics/resgfx.c index 5b899ef0a..8348d6988 100644 --- a/sc2/src/sc2code/libs/graphics/resgfx.c +++ b/sc2/src/sc2code/libs/graphics/resgfx.c @@ -27,15 +27,16 @@ InstallGraphicResTypes (COUNT cel_type, COUNT font_type) return (TRUE); } -DWORD +/* Needs to be void * because it could be either a DRAWABLE or a FONT. */ +void * LoadGraphicInstance (DWORD res) { - MEM_HANDLE hData; + void *hData; hData = res_GetResource (res); if (hData) res_DetachResource (res); - return ((DWORD)hData); + return (hData); } diff --git a/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c b/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c index 28479ee59..910cbab01 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c +++ b/sc2/src/sc2code/libs/graphics/sdl/3do_getbody.c @@ -370,7 +370,7 @@ Uint32 frame_mapRGBA (FRAME FramePtr,Uint8 r, Uint8 g, Uint8 b, Uint8 a) return (SDL_MapRGBA (img->format, r, g, b, a)); } -MEM_HANDLE +void * _GetCelData (uio_Stream *fp, DWORD length) { int cel_total, cel_index, n; @@ -409,7 +409,7 @@ _GetCelData (uio_Stream *fp, DWORD length) { log_add (log_Warning, "Couldn't allocate space for '%s' images", _cur_resfile_name); - return NULL_HANDLE; + return NULL; } ani = HMalloc (sizeof (AniData) * cel_total); @@ -418,7 +418,7 @@ _GetCelData (uio_Stream *fp, DWORD length) HFree (img); log_add (log_Warning, "Couldn't allocate space for '%s' anidata", _cur_resfile_name); - return NULL_HANDLE; + return NULL; } cel_index = 0; @@ -455,36 +455,31 @@ _GetCelData (uio_Stream *fp, DWORD length) break; } - Drawable = NULL_HANDLE; + Drawable = NULL; if (cel_index && (Drawable = AllocDrawable (cel_index))) { - DRAWABLE_DESC *DrawablePtr; - - if ((DrawablePtr = LockDrawable (Drawable)) == 0) + if (!Drawable) { while (cel_index--) SDL_FreeSurface (img[cel_index]); - mem_release ((MEM_HANDLE)Drawable); - Drawable = NULL_HANDLE; + HFree (Drawable); + Drawable = NULL; } else { FRAME FramePtr; - DrawablePtr->hDrawable = Drawable; - DrawablePtr->Flags = WANT_PIXMAP; - DrawablePtr->MaxIndex = cel_index - 1; + Drawable->Flags = WANT_PIXMAP; + Drawable->MaxIndex = cel_index - 1; - FramePtr = &DrawablePtr->Frame[cel_index]; + FramePtr = &Drawable->Frame[cel_index]; while (--FramePtr, cel_index--) process_image (FramePtr, img, ani, cel_index); - - UnlockDrawable (Drawable); } } - if (Drawable == 0) + if (Drawable == NULL) log_add (log_Warning, "Couldn't get cel data for '%s'", _cur_resfile_name); @@ -494,13 +489,13 @@ _GetCelData (uio_Stream *fp, DWORD length) } BOOLEAN -_ReleaseCelData (MEM_HANDLE handle) +_ReleaseCelData (DRAWABLE handle) { DRAWABLE_DESC *DrawablePtr; int cel_ct; FRAME FramePtr = NULL; - if ((DrawablePtr = LockDrawable (handle)) == 0) + if ((DrawablePtr = handle) == 0) return (FALSE); cel_ct = DrawablePtr->MaxIndex + 1; @@ -514,8 +509,8 @@ _ReleaseCelData (MEM_HANDLE handle) } } - UnlockDrawable (handle); - if (mem_release (handle) && FramePtr) + HFree (handle); + if (FramePtr) { int i; for (i = 0; i < cel_ct; i++) @@ -543,17 +538,16 @@ compareBCDIndex(const BuildCharDesc *bcd1, const BuildCharDesc *bcd2) { return (int) bcd1->index - (int) bcd2->index; } -MEM_HANDLE +void * _GetFontData (uio_Stream *fp, DWORD length) { COUNT numDirEntries; - FONT_REF fontRef = 0; - DIRENTRY fontDir = 0; + DIRENTRY fontDir = NULL; BuildCharDesc *bcds = NULL; size_t numBCDs = 0; int dirEntryI; uio_DirHandle *fontDirHandle = NULL; - FONT fontPtr; + FONT fontPtr = NULL; if (_cur_resfile_name == 0) goto err; @@ -613,15 +607,10 @@ _GetFontData (uio_Stream *fp, DWORD length) qsort (bcds, numBCDs, sizeof (BuildCharDesc), (int (*)(const void *, const void *)) compareBCDIndex); - fontRef = AllocFont (0); - if (fontRef == 0) - goto err; - - fontPtr = LockFont (fontRef); + fontPtr = AllocFont (0); if (fontPtr == NULL) goto err; - fontPtr->FontRef = fontRef; fontPtr->Leading = 0; fontPtr->LeadingWidth = 0; @@ -684,17 +673,16 @@ _GetFontData (uio_Stream *fp, DWORD length) } fontPtr->Leading++; - UnlockFont (fontRef); HFree (bcds); (void) fp; /* Satisfying compiler (unused parameter) */ (void) length; /* Satisfying compiler (unused parameter) */ - return fontRef; + return fontPtr; err: - if (fontRef != 0) - mem_release (fontRef); + if (fontPtr != 0) + HFree (fontPtr); if (bcds != NULL) { @@ -713,9 +701,9 @@ err: } BOOLEAN -_ReleaseFontData (MEM_HANDLE handle) +_ReleaseFontData (void *handle) { - FONT font = LockFont (handle); + FONT font = (FONT) handle; if (font == NULL) return FALSE; @@ -743,8 +731,7 @@ _ReleaseFontData (MEM_HANDLE handle) } } - UnlockFont (handle); - mem_release (handle); + HFree (font); return TRUE; } @@ -762,43 +749,31 @@ _request_drawable (COUNT NumFrames, DRAWABLE_TYPE DrawableType, ); if (Drawable) { - DRAWABLE_DESC *DrawablePtr; + int imgw, imgh; + FRAME FramePtr; - if ((DrawablePtr = LockDrawable (Drawable)) == 0) - { - FreeDrawable (Drawable); - Drawable = NULL_HANDLE; - } - else - { - int imgw, imgh; - FRAME FramePtr; + Drawable->Flags = flags; + Drawable->MaxIndex = NumFrames - 1; - DrawablePtr->hDrawable = Drawable; - DrawablePtr->Flags = flags; - DrawablePtr->MaxIndex = NumFrames - 1; - - imgw = width; - imgh = height; + imgw = width; + imgh = height; - FramePtr = &DrawablePtr->Frame[NumFrames - 1]; - while (NumFrames--) + FramePtr = &Drawable->Frame[NumFrames - 1]; + while (NumFrames--) + { + TFB_Image *Image; + + if (DrawableType == RAM_DRAWABLE && imgw > 0 && imgh > 0 + && (Image = TFB_DrawImage_New (TFB_DrawCanvas_New_TrueColor ( + imgw, imgh, (flags & WANT_ALPHA) ? TRUE : FALSE)))) { - TFB_Image *Image; - - if (DrawableType == RAM_DRAWABLE && imgw > 0 && imgh > 0 - && (Image = TFB_DrawImage_New (TFB_DrawCanvas_New_TrueColor ( - imgw, imgh, (flags & WANT_ALPHA) ? TRUE : FALSE)))) - { - FramePtr->image = Image; - } - - FramePtr->Type = DrawableType; - FramePtr->Index = NumFrames; - SetFrameBounds (FramePtr, width, height); - --FramePtr; + FramePtr->image = Image; } - UnlockDrawable (Drawable); + + FramePtr->Type = DrawableType; + FramePtr->Index = NumFrames; + SetFrameBounds (FramePtr, width, height); + --FramePtr; } } diff --git a/sc2/src/sc2code/libs/inplib.h b/sc2/src/sc2code/libs/inplib.h index 058187be3..15a1fd529 100644 --- a/sc2/src/sc2code/libs/inplib.h +++ b/sc2/src/sc2code/libs/inplib.h @@ -19,8 +19,8 @@ #ifndef _INPLIB_H #define _INPLIB_H -#include "memlib.h" #include +#include "compiler.h" #include "libs/uio.h" typedef DWORD INPUT_STATE; diff --git a/sc2/src/sc2code/libs/reslib.h b/sc2/src/sc2code/libs/reslib.h index 1d893d1f4..85a960d60 100644 --- a/sc2/src/sc2code/libs/reslib.h +++ b/sc2/src/sc2code/libs/reslib.h @@ -20,11 +20,13 @@ #define _RESLIB_H //#include +#include "compiler.h" #include "port.h" -#include "memlib.h" +#include "misc.h" #include "libs/uio.h" +typedef struct resource_index *RESOURCE_INDEX; typedef DWORD RESOURCE; typedef BYTE RES_TYPE; @@ -52,8 +54,8 @@ typedef COUNT RES_PACKAGE; extern const char *_cur_resfile_name; -typedef MEM_HANDLE (ResourceLoadFun) (uio_Stream *fp, DWORD len); -typedef BOOLEAN (ResourceFreeFun) (MEM_HANDLE handle); +typedef void *(ResourceLoadFun) (uio_Stream *fp, DWORD len); +typedef BOOLEAN (ResourceFreeFun) (void *handle); extern uio_Stream *res_OpenResFile (uio_DirHandle *dir, const char *filename, const char *mode); @@ -69,35 +71,25 @@ extern long LengthResFile (uio_Stream *fp); extern BOOLEAN res_CloseResFile (uio_Stream *fp); extern BOOLEAN DeleteResFile (uio_DirHandle *dir, const char *filename); -extern MEM_HANDLE InitResourceSystem (const char *mapfile, const char *resfile, +extern RESOURCE_INDEX InitResourceSystem (const char *mapfile, const char *resfile, RES_TYPE resType, BOOLEAN (*FileErrorFun) (const char *filename)); extern void UninitResourceSystem (void); extern BOOLEAN InstallResTypeVectors (RES_TYPE res_type, ResourceLoadFun *loadFun, ResourceFreeFun *freeFun); -extern MEM_HANDLE res_GetResource (RESOURCE res); -extern MEM_HANDLE res_DetachResource (RESOURCE res); +extern void *res_GetResource (RESOURCE res); +extern void *res_DetachResource (RESOURCE res); extern BOOLEAN FreeResource (RESOURCE res); extern COUNT CountResourceTypes (void); -extern MEM_HANDLE OpenResourceIndexFile (const char *resfile); -extern MEM_HANDLE OpenResourceIndexInstance (RESOURCE res); -extern MEM_HANDLE SetResourceIndex (MEM_HANDLE newIndexHandle); -extern BOOLEAN CloseResourceIndex (MEM_HANDLE newIndexHandle); +extern RESOURCE_INDEX OpenResourceIndexFile (const char *resfile); +extern RESOURCE_INDEX OpenResourceIndexInstance (RESOURCE res); +extern RESOURCE_INDEX SetResourceIndex (RESOURCE_INDEX newIndexHandle); +extern BOOLEAN CloseResourceIndex (RESOURCE_INDEX newIndexHandle); -extern MEM_HANDLE GetResourceData (uio_Stream *fp, DWORD length, - MEM_FLAGS mem_flags); +extern void *GetResourceData (uio_Stream *fp, DWORD length); -#define RESOURCE_PRIORITY DEFAULT_MEM_PRIORITY - -#define AllocResourceData(s,mf) \ - mem_allocate ((MEM_SIZE)(s), (mf)) -#define LockResourceData(h,lp) \ -do \ -{ \ - *(lp) = mem_lock ((MEM_HANDLE)(h)); \ -} while (0) -#define UnlockResourceData mem_unlock -#define FreeResourceData mem_release +#define AllocResourceData HMalloc +#define FreeResourceData HFree #include "strlib.h" @@ -105,7 +97,6 @@ typedef STRING_TABLE DIRENTRY_REF; typedef STRING DIRENTRY; typedef STRINGPTR DIRENTRYPTR; - extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path, const char *pattern, match_MatchType matchType); #define CaptureDirEntryTable CaptureStringTable diff --git a/sc2/src/sc2code/libs/resource/direct.c b/sc2/src/sc2code/libs/resource/direct.c index 7dea9047f..35e4830c5 100644 --- a/sc2/src/sc2code/libs/resource/direct.c +++ b/sc2/src/sc2code/libs/resource/direct.c @@ -70,7 +70,7 @@ LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path, } StringTable = AllocStringTable (num_entries, 0); - LockStringTable (StringTable, &lpST); + lpST = StringTable; if (lpST == 0) { FreeStringTable (StringTable); @@ -95,8 +95,7 @@ LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path, } uio_DirList_free(dirList); - UnlockStringTable (StringTable); - return ((DIRENTRY_REF) StringTable); + return StringTable; } diff --git a/sc2/src/sc2code/libs/resource/getres.c b/sc2/src/sc2code/libs/resource/getres.c index db565cdb8..9db0ee029 100644 --- a/sc2/src/sc2code/libs/resource/getres.c +++ b/sc2/src/sc2code/libs/resource/getres.c @@ -61,14 +61,14 @@ loadPackage (ResourceIndex *idx, RES_PACKAGE pkg) { if (GET_PACKAGE (idx->res[i]->res) != pkg) continue; - if (idx->res[i]->handle != NULL_HANDLE) + if (idx->res[i]->resdata != NULL) continue; // Already loaded loadResourceDesc (idx, idx->res[i]); } } -MEM_HANDLE +void * loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc) { RES_TYPE resType = GET_TYPE (desc->res); @@ -79,33 +79,33 @@ loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc) { log_add (log_Warning, "Warning: Unable to load '%s'; no handler " "for type %d defined.", desc->res_id, resType); - return NULL_HANDLE; + return NULL; } path = res_GetString (desc->res_id); if (path == NULL) { log_add (log_Warning, "Could not decode resource '%s'", desc->res_id); - return NULL_HANDLE; + return NULL; } - desc->handle = loadResource (path, + desc->resdata = loadResource (path, idx->typeInfo.handlers[resType].loadFun); - return desc->handle; + return desc->resdata; } -MEM_HANDLE +void * loadResource(const char *path, ResourceLoadFun *loadFun) { uio_Stream *stream; long dataLen; - MEM_HANDLE handle; + void *resdata; stream = res_OpenResFile (contentDir, path, "rb"); if (stream == NULL) { log_add (log_Warning, "Warning: Can't open '%s'", path); - return NULL_HANDLE; + return NULL; } dataLen = LengthResFile (stream); @@ -118,15 +118,15 @@ loadResource(const char *path, ResourceLoadFun *loadFun) } _cur_resfile_name = path; - handle = (*loadFun) (stream, dataLen); + resdata = (*loadFun) (stream, dataLen); _cur_resfile_name = NULL; res_CloseResFile (stream); - return handle; + return resdata; err: res_CloseResFile (stream); - return NULL_HANDLE; + return NULL; } // Get a resource by its resource ID. @@ -135,7 +135,7 @@ err: // NB. It may be better to add an extra flag to res_GetResource() to // indicate whether you really want this, or add a separate function // for preloading the entire package. -MEM_HANDLE +void * res_GetResource (RESOURCE res) { ResourceIndex *resourceIndex; @@ -148,17 +148,17 @@ res_GetResource (RESOURCE res) { log_add (log_Warning, "Trying to get undefined resource %08x", (DWORD) res); - return NULL_HANDLE; + return NULL; } - if (desc->handle != NULL_HANDLE) - return desc->handle; + if (desc->resdata != NULL) + return desc->resdata; // Load the entire package, for historical reasons. loadPackage (resourceIndex, GET_PACKAGE (res)); - return desc->handle; - // May still be NULL_HANDLE, if the load failed. + return desc->resdata; + // May still be NULL, if the load failed. } // NB: this function appears to be never called! @@ -177,7 +177,7 @@ res_FreeResource (RESOURCE res) return; } - if (desc->handle == NULL_HANDLE) + if (desc->resdata == NULL) { log_add (log_Debug, "Warning: trying to free not loaded " "resource."); @@ -186,37 +186,37 @@ res_FreeResource (RESOURCE res) idx = _get_current_index_header (); freeFun = idx->typeInfo.handlers[GET_TYPE (res)].freeFun; - (*freeFun) (desc->handle); - desc->handle = NULL_HANDLE; + (*freeFun) (desc->resdata); + desc->resdata = NULL; } // By calling this function the caller will be responsible of unloading // the resource. If res_GetResource() get called again for this // resource, a NEW copy will be loaded, regardless of whether a detached // copy still exists. -MEM_HANDLE +void * res_DetachResource (RESOURCE res) { ResourceDesc *desc; - MEM_HANDLE result; + void *result; desc = lookupResourceDesc (_get_current_index_header(), res); if (desc == NULL) { log_add (log_Debug, "Warning: trying to detach from an unrecognised " "resource."); - return NULL_HANDLE; + return NULL; } - if (desc->handle == NULL_HANDLE) + if (desc->resdata == NULL) { log_add (log_Debug, "Warning: trying to detach from a not loaded " "resource."); - return NULL_HANDLE; + return NULL; } - result = desc->handle; - desc->handle = NULL_HANDLE; + result = desc->resdata; + desc->resdata = NULL; return result; } diff --git a/sc2/src/sc2code/libs/resource/index.h b/sc2/src/sc2code/libs/resource/index.h index 21fcf0237..b900e022b 100644 --- a/sc2/src/sc2code/libs/resource/index.h +++ b/sc2/src/sc2code/libs/resource/index.h @@ -19,13 +19,14 @@ #ifndef _INDEX_H #define _INDEX_H +#include "reslib.h" #include typedef struct { RESOURCE res; char *res_id; - MEM_HANDLE handle; + void *resdata; //COUNT ref; } ResourceDesc; @@ -44,30 +45,19 @@ typedef struct ResourceHandlers *handlers; } ResourceTypeInfo; -typedef struct +struct resource_index { ResourceDesc **res; ResourceTypeInfo typeInfo; size_t numRes; -} ResourceIndex; +}; +/* XXX: This should almost certainly be folded into RESOURCE_INDEX wherever possible */ +typedef struct resource_index ResourceIndex; void forAllResourceIndices( void (*callback) (ResourceIndex *idx, void *extra), void *extra); - -#define INDEX_HEADER_PRIORITY DEFAULT_MEM_PRIORITY - -static inline ResourceIndex * -lockResourceIndex (MEM_HANDLE h) { - return (ResourceIndex *) mem_lock (h); -} -static inline void -unlockResourceIndex (MEM_HANDLE h) { - mem_unlock (h); -} - - #endif /* _INDEX_H */ diff --git a/sc2/src/sc2code/libs/resource/loadres.c b/sc2/src/sc2code/libs/resource/loadres.c index 4fda94adb..163fa1a9e 100644 --- a/sc2/src/sc2code/libs/resource/loadres.c +++ b/sc2/src/sc2code/libs/resource/loadres.c @@ -19,10 +19,11 @@ #include "resintrn.h" #include "declib.h" -MEM_HANDLE -GetResourceData (uio_Stream *fp, DWORD length, MEM_FLAGS mem_flags) +void * +GetResourceData (uio_Stream *fp, DWORD length) { - MEM_HANDLE RData; + BYTE *RDPtr; + void *result; DECODE_REF fh = 0; if (length == ~(DWORD)0) @@ -32,51 +33,38 @@ GetResourceData (uio_Stream *fp, DWORD length, MEM_FLAGS mem_flags) else length -= sizeof (DWORD); - RData = AllocResourceData (length, mem_flags); - if (RData) + result = AllocResourceData (length); + RDPtr = result; + if (RDPtr) { - BYTE *RDPtr; + COUNT num_read; - LockResourceData (RData, &RDPtr); - if (RDPtr == NULL) + do { - FreeResourceData (RData); - RData = 0; - } - else - { - COUNT num_read; - - do - { #define READ_LENGTH 0x00007FFFL - num_read = length >= READ_LENGTH ? - (COUNT)READ_LENGTH : (COUNT)length; - if (fh) - { - if (cread (RDPtr, 1, num_read, fh) != num_read) - break; - } - else - { - if ((int)(ReadResFile (RDPtr, 1, num_read, fp)) != (int)num_read) - break; - } - RDPtr += num_read; - } while (length -= num_read); - - UnlockResourceData (RData); - if (length > 0) + num_read = length >= READ_LENGTH ? + (COUNT)READ_LENGTH : (COUNT)length; + if (fh) { - FreeResourceData (RData); - RData = 0; + if (cread (RDPtr, 1, num_read, fh) != num_read) + break; } + else + { + if ((int)(ReadResFile (RDPtr, 1, num_read, fp)) != (int)num_read) + break; + } + RDPtr += num_read; + } while (length -= num_read); + + if (length > 0) + { + FreeResourceData (result); + result = NULL; } } cclose (fh); - return (RData); + return result; } - - diff --git a/sc2/src/sc2code/libs/resource/resinit.c b/sc2/src/sc2code/libs/resource/resinit.c index 3db4ca8fd..9907b09f7 100644 --- a/sc2/src/sc2code/libs/resource/resinit.c +++ b/sc2/src/sc2code/libs/resource/resinit.c @@ -30,8 +30,8 @@ static bool copyResTypeHandlers (ResourceIndex *dest, const ResourceIndex *src); static bool setResTypeHandlers (ResourceIndex *idx, RES_TYPE resType, const ResourceHandlers *handlers); -static MEM_HANDLE allocResourceIndex(void); -static void freeResourceIndex (MEM_HANDLE h); +static RESOURCE_INDEX allocResourceIndex(void); +static void freeResourceIndex (RESOURCE_INDEX h); static List_List *indexList; @@ -95,19 +95,18 @@ newResourceDesc (RESOURCE res, char *res_id) result->res = res; result->res_id = res_id; - result->handle = NULL_HANDLE; + result->resdata = NULL; //result->ref = 0; return result; } -static MEM_HANDLE +static RESOURCE_INDEX loadResourceIndex (uio_Stream *stream, const char *fileName) { size_t lineNum; ResourceDesc **descs = NULL; COUNT numRes; int numDescsAlloced = 0; - MEM_HANDLE indexHandle = NULL_HANDLE; - ResourceIndex *ndx = NULL; + RESOURCE_INDEX ndx = NULL; #ifdef DEBUG RESOURCE lastResource = 0x00000000; #endif @@ -238,35 +237,31 @@ loadResourceIndex (uio_Stream *stream, const char *fileName) { log_add (log_Debug, "Warning: Resource index '%s' contains no valid " "entries.", fileName); - indexHandle = allocResourceIndex (); - if (indexHandle == NULL_HANDLE) + ndx = allocResourceIndex (); + if (ndx == NULL) goto err; - ndx = lockResourceIndex (indexHandle); ndx->res = descs; ndx->numRes = numRes; ndx->typeInfo.numTypes = 0; ndx->typeInfo.handlers = NULL; List_add (indexList, (void *) ndx); - unlockResourceIndex (indexHandle); - return indexHandle; + return ndx; err: - if (indexHandle != NULL_HANDLE) - freeResourceIndex (indexHandle); + if (ndx != NULL) + freeResourceIndex (ndx); HFree (descs); - return NULL_HANDLE; + return NULL; } // Get the data associated with a resource of type RES_INDEX // (In other words, a ResourceIndex) -MEM_HANDLE +void * _GetResFileData (uio_Stream *res_fp, DWORD fileLength) { - MEM_HANDLE handle; - ResourceIndex *ndx; - ResourceIndex *parentNdx; + RESOURCE_INDEX ndx, parentNdx; #if 0 ResourceDesc *desc; @@ -278,39 +273,28 @@ _GetResFileData (uio_Stream *res_fp, DWORD fileLength) return desc->handle; #endif - handle = loadResourceIndex (res_fp, _cur_resfile_name); - if (handle == NULL_HANDLE) - return NULL_HANDLE; - - ndx = lockResourceIndex (handle); + ndx = loadResourceIndex (res_fp, _cur_resfile_name); parentNdx = _get_current_index_header (); if (parentNdx != NULL) copyResTypeHandlers (ndx, parentNdx); - unlockResourceIndex (handle); - (void) fileLength; - return handle; + return ndx; } BOOLEAN -_ReleaseResFileData (MEM_HANDLE handle) +_ReleaseResFileData (RESOURCE_INDEX ndx) { - ResourceIndex *ndx; - - ndx = lockResourceIndex (handle); if (ndx->typeInfo.handlers != NULL) HFree (ndx->typeInfo.handlers); - unlockResourceIndex (handle); - mem_release (handle); + HFree (ndx); return TRUE; } -MEM_HANDLE +RESOURCE_INDEX InitResourceSystem (const char *mapfile, const char *resfile, RES_TYPE resType, BOOLEAN (*FileErrorFun) (const char *filename)) { - MEM_HANDLE handle; ResourceIndex *ndx; ResourceHandlers handlers; @@ -321,20 +305,18 @@ InitResourceSystem (const char *mapfile, const char *resfile, RES_TYPE resType, res_LoadFilename (contentDir, mapfile); - SetResourceIndex (NULL_HANDLE); - handle = loadResource (resfile, handlers.loadFun); - if (handle == NULL_HANDLE) - return NULL_HANDLE; + SetResourceIndex (NULL); + ndx = loadResource (resfile, handlers.loadFun); + if (ndx == NULL) + return NULL; - ndx = lockResourceIndex (handle); setResTypeHandlers (ndx, resType, &handlers); - unlockResourceIndex (handle); - SetResourceIndex (handle); + SetResourceIndex (ndx); (void) FileErrorFun; (void) mapfile; - return handle; + return ndx; } void @@ -351,15 +333,15 @@ UninitResourceSystem (void) #endif uninitIndexList (); - SetResourceIndex (NULL_HANDLE); + SetResourceIndex (NULL); } -MEM_HANDLE +RESOURCE_INDEX OpenResourceIndexInstance (RESOURCE res) { - MEM_HANDLE hRH; + RESOURCE_INDEX hRH; - hRH = res_GetResource (res); + hRH = (RESOURCE_INDEX)res_GetResource (res); if (hRH) res_DetachResource (res); @@ -368,46 +350,36 @@ OpenResourceIndexInstance (RESOURCE res) // Sets the current global resource index. // This is the index res_GetResource() calls will use. -MEM_HANDLE -SetResourceIndex (MEM_HANDLE newIndexHandle) +RESOURCE_INDEX +SetResourceIndex (RESOURCE_INDEX newIndex) { - static MEM_HANDLE currentIndexHandle; + static RESOURCE_INDEX currentIndex; // NB: currentIndexHandle is locked. - MEM_HANDLE oldIndexHandle; + RESOURCE_INDEX oldIndex; - if (currentIndexHandle != NULL_HANDLE) - unlockResourceIndex (currentIndexHandle); + oldIndex = currentIndex; + currentIndex = newIndex; - oldIndexHandle = currentIndexHandle; - currentIndexHandle = newIndexHandle; + if (currentIndex != NULL) { + RESOURCE_INDEX ndx; - if (currentIndexHandle != NULL_HANDLE) { - ResourceIndex *ndx; - - ndx = lockResourceIndex (currentIndexHandle); + ndx = currentIndex; _set_current_index_header (ndx); } else _set_current_index_header (NULL); - return oldIndexHandle; + return oldIndex; } BOOLEAN -CloseResourceIndex (MEM_HANDLE handle) +CloseResourceIndex (RESOURCE_INDEX ndx) { - ResourceIndex *ndx; - - unlockResourceIndex (handle); - - ndx = lockResourceIndex (handle); if (ndx == _get_current_index_header ()) - SetResourceIndex (NULL_HANDLE); + SetResourceIndex (NULL); List_remove ((void *) indexList, ndx); - unlockResourceIndex (handle); - - _ReleaseResFileData (handle); + _ReleaseResFileData (ndx); return TRUE; } @@ -470,14 +442,14 @@ copyResTypeHandlers (ResourceIndex *dest, const ResourceIndex *src) } -static MEM_HANDLE +static RESOURCE_INDEX allocResourceIndex (void) { - return mem_allocate (sizeof (ResourceIndex), MEM_PRIMARY); + return HMalloc (sizeof (struct resource_index)); } static void -freeResourceIndex (MEM_HANDLE h) { - mem_release (h); +freeResourceIndex (RESOURCE_INDEX h) { + HFree (h); } diff --git a/sc2/src/sc2code/libs/resource/resintrn.h b/sc2/src/sc2code/libs/resource/resintrn.h index 455e47bdd..822d6f717 100644 --- a/sc2/src/sc2code/libs/resource/resintrn.h +++ b/sc2/src/sc2code/libs/resource/resintrn.h @@ -20,11 +20,11 @@ #define _RESINTRN_H #include -#include "libs/reslib.h" +#include "reslib.h" #include "index.h" -MEM_HANDLE loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc); -MEM_HANDLE loadResource(const char *path, ResourceLoadFun *loadFun); +void *loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc); +void *loadResource(const char *path, ResourceLoadFun *loadFun); void _set_current_index_header (ResourceIndex *newResourceIndex); ResourceIndex *_get_current_index_header (void); diff --git a/sc2/src/sc2code/libs/sndlib.h b/sc2/src/sc2code/libs/sndlib.h index 0a6aecaf7..7a2e3e935 100644 --- a/sc2/src/sc2code/libs/sndlib.h +++ b/sc2/src/sc2code/libs/sndlib.h @@ -20,7 +20,6 @@ #define _SNDLIB_H #include "strlib.h" -#include "memlib.h" typedef STRING_TABLE SOUND_REF; typedef STRING SOUND; @@ -43,7 +42,8 @@ typedef struct soundposition #define GetSoundAddress GetStringAddress #define GetSoundContents GetStringContents -typedef MEM_HANDLE MUSIC_REF; +typedef struct tfb_soundsample TFB_SoundSample; +typedef TFB_SoundSample **MUSIC_REF; extern BOOLEAN InitSound (int argc, char *argv[]); extern void UninitSound (void); diff --git a/sc2/src/sc2code/libs/sound/fileinst.c b/sc2/src/sc2code/libs/sound/fileinst.c index fc1f7fdd9..e9de214f4 100644 --- a/sc2/src/sc2code/libs/sound/fileinst.c +++ b/sc2/src/sc2code/libs/sound/fileinst.c @@ -35,18 +35,18 @@ LoadSoundFile (const char *pStr) fp = res_OpenResFile (contentDir, pStr, "rb"); if (fp) { - MEM_HANDLE hData; + SOUND_REF hData; _cur_resfile_name = pStr; - hData = _GetSoundBankData (fp, LengthResFile (fp)); + hData = (SOUND_REF)_GetSoundBankData (fp, LengthResFile (fp)); _cur_resfile_name = 0; res_CloseResFile (fp); - return ((SOUND_REF)hData); + return hData; } - return (0); + return NULL; } MUSIC_REF @@ -70,15 +70,15 @@ LoadMusicFile (const char *pStr) fp = res_OpenResFile (contentDir, filename, "rb"); if (fp) { - MEM_HANDLE hData; + MUSIC_REF hData; _cur_resfile_name = filename; - hData = _GetMusicData (fp, LengthResFile (fp)); + hData = (MUSIC_REF)_GetMusicData (fp, LengthResFile (fp)); _cur_resfile_name = 0; res_CloseResFile (fp); - return ((MUSIC_REF)hData); + return hData; } return (0); diff --git a/sc2/src/sc2code/libs/sound/music.c b/sc2/src/sc2code/libs/sound/music.c index f9baf8568..dc7c3c860 100644 --- a/sc2/src/sc2code/libs/sound/music.c +++ b/sc2/src/sc2code/libs/sound/music.c @@ -28,9 +28,8 @@ static MUSIC_REF curSpeechRef; void PLRPlaySong (MUSIC_REF MusicRef, BOOLEAN Continuous, BYTE Priority) { - TFB_SoundSample **pmus; + TFB_SoundSample **pmus = MusicRef; - LockMusicData (MusicRef, &pmus); if (pmus) { LockMutex (soundSource[MUSIC_SOURCE].stream_mutex); @@ -52,7 +51,6 @@ PLRStop (MUSIC_REF MusicRef) LockMutex (soundSource[MUSIC_SOURCE].stream_mutex); StopStream (MUSIC_SOURCE); UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex); - UnlockMusicData (curMusicRef); curMusicRef = 0; } @@ -100,9 +98,8 @@ PLRResume (MUSIC_REF MusicRef) void snd_PlaySpeech (MUSIC_REF SpeechRef) { - TFB_SoundSample **pmus; + TFB_SoundSample **pmus = SpeechRef; - LockMusicData (SpeechRef, &pmus); if (pmus) { LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); @@ -122,7 +119,6 @@ snd_StopSpeech (void) LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); StopStream (SPEECH_SOURCE); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); - UnlockMusicData (curSpeechRef); curSpeechRef = 0; } @@ -130,7 +126,8 @@ snd_StopSpeech (void) BOOLEAN DestroyMusic (MUSIC_REF MusicRef) { - return (FreeMusicData (MusicRef)); + FreeMusicData (MusicRef); + return (TRUE); } void @@ -149,22 +146,18 @@ CheckMusicResName (char* fileName) return fileName; } -MEM_HANDLE +void * _GetMusicData (uio_Stream *fp, DWORD length) { - MEM_HANDLE h; + MUSIC_REF h; - h = 0; if (_cur_resfile_name && (h = AllocMusicData (sizeof (void *)))) { - TFB_SoundSample **pmus; + TFB_SoundSample **pmus = h; - LockMusicData (h, &pmus); if (!pmus) { - UnlockMusicData (h); - mem_release (h); - h = 0; + return NULL; } else { @@ -181,9 +174,8 @@ _GetMusicData (uio_Stream *fp, DWORD length) { log_add (log_Warning, "_GetMusicData(): couldn't load %s", filename); - UnlockMusicData (h); - mem_release (h); - h = 0; + HFree (h); + return NULL; } else { @@ -196,8 +188,6 @@ _GetMusicData (uio_Stream *fp, DWORD length) audio_GenBuffers ((*pmus)->num_buffers, (*pmus)->buffer); } } - - UnlockMusicData (h); } (void) fp; /* satisfy compiler (unused parameter) */ @@ -206,12 +196,11 @@ _GetMusicData (uio_Stream *fp, DWORD length) } BOOLEAN -_ReleaseMusicData (MEM_HANDLE handle) +_ReleaseMusicData (void *data) { - TFB_SoundSample **pmus; + TFB_SoundSample **pmus = data; - LockMusicData (handle, &pmus); - if (pmus == 0) + if (pmus == NULL) return (FALSE); if ((*pmus)->decoder) @@ -232,9 +221,7 @@ _ReleaseMusicData (MEM_HANDLE handle) HFree ((*pmus)->buffer_tag); } HFree (*pmus); - - UnlockMusicData (handle); - mem_release (handle); + HFree (pmus); return (TRUE); } diff --git a/sc2/src/sc2code/libs/sound/resinst.c b/sc2/src/sc2code/libs/sound/resinst.c index 647349e27..06da2664e 100644 --- a/sc2/src/sc2code/libs/sound/resinst.c +++ b/sc2/src/sc2code/libs/sound/resinst.c @@ -27,9 +27,9 @@ InstallAudioResTypes (COUNT sound_type, COUNT music_type) } SOUND_REF -LoadSoundInstance (DWORD res) +LoadSoundInstance (RESOURCE res) { - MEM_HANDLE hData; + void *hData; hData = res_GetResource (res); if (hData) @@ -39,9 +39,9 @@ LoadSoundInstance (DWORD res) } MUSIC_REF -LoadMusicInstance (DWORD res) +LoadMusicInstance (RESOURCE res) { - MEM_HANDLE hData; + void *hData; hData = res_GetResource (res); if (hData) diff --git a/sc2/src/sc2code/libs/sound/sfx.c b/sc2/src/sc2code/libs/sound/sfx.c index 9eb94581d..3309a9909 100644 --- a/sc2/src/sc2code/libs/sound/sfx.c +++ b/sc2/src/sc2code/libs/sound/sfx.c @@ -177,7 +177,7 @@ GetSampleRate (SOUND sound) return 0; } -MEM_HANDLE +void * _GetSoundBankData (uio_Stream *fp, DWORD length) { int snd_ct, n; @@ -254,12 +254,11 @@ _GetSoundBankData (uio_Stream *fp, DWORD length) break;*/ } - Snd = 0; + Snd = NULL; if (snd_ct && (Snd = AllocStringTable (snd_ct, 0))) { - STRING_TABLE_DESC *fxTab; + STRING_TABLE fxTab = Snd; - LockStringTable (Snd, &fxTab); if (fxTab == 0) { while (snd_ct--) @@ -286,19 +285,17 @@ _GetSoundBankData (uio_Stream *fp, DWORD length) str->length = sizeof (sndfx[0]); str++; } - UnlockStringTable (Snd); } } - return ((MEM_HANDLE)Snd); + return Snd; } BOOLEAN -_ReleaseSoundBankData (MEM_HANDLE Snd) +_ReleaseSoundBankData (void *Snd) { - STRING_TABLE_DESC *fxTab; + STRING_TABLE fxTab = Snd; - LockStringTable (Snd, &fxTab); if (fxTab) { int snd_ct, index; @@ -331,7 +328,6 @@ _ReleaseSoundBankData (MEM_HANDLE Snd) *sptr = 0; index++; } - UnlockStringTable (Snd); FreeStringTable (Snd); return (TRUE); @@ -343,5 +339,5 @@ _ReleaseSoundBankData (MEM_HANDLE Snd) BOOLEAN DestroySound(SOUND_REF target) { - return _ReleaseSoundBankData ((MEM_HANDLE) target); + return _ReleaseSoundBankData (target); } diff --git a/sc2/src/sc2code/libs/sound/sndintrn.h b/sc2/src/sc2code/libs/sound/sndintrn.h index 6aced96c2..56d5b86be 100644 --- a/sc2/src/sc2code/libs/sound/sndintrn.h +++ b/sc2/src/sc2code/libs/sound/sndintrn.h @@ -23,16 +23,14 @@ #include "sndlib.h" #include "reslib.h" -extern MEM_HANDLE _GetMusicData (uio_Stream *fp, DWORD length); -extern BOOLEAN _ReleaseMusicData (MEM_HANDLE handle); +extern void *_GetMusicData (uio_Stream *fp, DWORD length); +extern BOOLEAN _ReleaseMusicData (void *handle); -extern MEM_HANDLE _GetSoundBankData (uio_Stream *fp, DWORD length); -extern BOOLEAN _ReleaseSoundBankData (MEM_HANDLE handle); +extern void *_GetSoundBankData (uio_Stream *fp, DWORD length); +extern BOOLEAN _ReleaseSoundBankData (void *handle); -#define AllocMusicData(s) AllocResourceData((s),MEM_ZEROINIT) -#define LockMusicData LockResourceData -#define UnlockMusicData UnlockResourceData -#define FreeMusicData _ReleaseMusicData +#define AllocMusicData HMalloc +#define FreeMusicData HFree extern char* CheckMusicResName (char* filename); diff --git a/sc2/src/sc2code/libs/sound/sound.h b/sc2/src/sc2code/libs/sound/sound.h index d90fd5906..b03440a3d 100644 --- a/sc2/src/sc2code/libs/sound/sound.h +++ b/sc2/src/sc2code/libs/sound/sound.h @@ -38,9 +38,6 @@ typedef struct void *data; // user-defined data } TFB_SoundTag; -// forward-declare -typedef struct tfb_soundsample TFB_SoundSample; - typedef struct tfb_soundcallbacks { // return TRUE to continue, FALSE to abort diff --git a/sc2/src/sc2code/libs/strings/getstr.c b/sc2/src/sc2code/libs/strings/getstr.c index 7c35cade9..5fe7a848a 100644 --- a/sc2/src/sc2code/libs/strings/getstr.c +++ b/sc2/src/sc2code/libs/strings/getstr.c @@ -57,10 +57,10 @@ set_strtab_entry (STRING_TABLE_DESC *strtab, int index, const char *value, int l } } -MEM_HANDLE +void * _GetStringData (uio_Stream *fp, DWORD length) { - MEM_HANDLE hData; + void *result; { char *s; @@ -255,7 +255,7 @@ _GetStringData (uio_Stream *fp, DWORD length) if (timestamp_fp) uio_fclose (timestamp_fp); - hData = 0; + result = NULL; num_data_sets = (ClipOffs ? 1 : 0) + (TSOffs ? 1 : 0) + 1; if (++n) { @@ -264,13 +264,13 @@ _GetStringData (uio_Stream *fp, DWORD length) flags |= HAS_SOUND_CLIPS; if (TSOffs) flags |= HAS_TIMESTAMP; - hData = AllocStringTable (n, flags); - if (hData) + result = AllocStringTable (n, flags); + if (result) { int StringIndex, ClipIndex, TSIndex; STRING_TABLE_DESC *lpST; - LockStringTable (hData, &lpST); + lpST = (STRING_TABLE) result; StringIndex = 0; ClipIndex = n; @@ -294,8 +294,6 @@ _GetStringData (uio_Stream *fp, DWORD length) TSOffs += tslen[n]; } } - - UnlockStringTable (hData); } } HFree (strdata); @@ -303,46 +301,42 @@ _GetStringData (uio_Stream *fp, DWORD length) if (ts_data) HFree (ts_data); - return (hData); + return (result); } } /* We don't end in .txt, so, we're a color table of some kind. */ - hData = GetResourceData (fp, length, MEM_SOUND); - if (hData) + result = GetResourceData (fp, length); + if (result) { DWORD *fileData; - MEM_HANDLE hStrTab; + STRING_TABLE lpST; - fileData = mem_lock (hData); + fileData = (DWORD *)result; dword_convert (fileData, 1); /* Length */ - hStrTab = AllocStringTable (fileData[0], 0); - if (hStrTab) + lpST = AllocStringTable (fileData[0], 0); + if (lpST) { - STRING_TABLE_DESC *lpST; int i, size; BYTE *stringptr; - LockStringTable (hStrTab, &lpST); size = lpST->size; - dword_convert (fileData+2, size); - stringptr = (BYTE *)(fileData + 2 + size); + dword_convert (fileData+1, size + 1); + stringptr = (BYTE *)(fileData + 2 + size + fileData[1]); for (i = 0; i < size; i++) { set_strtab_entry (lpST, i, stringptr, fileData[2+i]); stringptr += fileData[2+i]; } - UnlockStringTable (hStrTab); } - mem_unlock (hData); - mem_release (hData); - hData = hStrTab; + HFree (result); + result = lpST; } - return (hData); + return (result); } diff --git a/sc2/src/sc2code/libs/strings/sfileins.c b/sc2/src/sc2code/libs/strings/sfileins.c index a95d0bed3..38733c9a9 100644 --- a/sc2/src/sc2code/libs/strings/sfileins.c +++ b/sc2/src/sc2code/libs/strings/sfileins.c @@ -35,14 +35,14 @@ LoadStringTableFile (uio_DirHandle *dir, const char *fileName) fp = res_OpenResFile (dir, fileName, "rb"); if (fp) { - MEM_HANDLE hData; + STRING_TABLE data; _cur_resfile_name = fileName; - hData = _GetStringData (fp, LengthResFile (fp)); + data = (STRING_TABLE) _GetStringData (fp, LengthResFile (fp)); _cur_resfile_name = 0; res_CloseResFile (fp); - return hData; + return data; } return (0); diff --git a/sc2/src/sc2code/libs/strings/sresins.c b/sc2/src/sc2code/libs/strings/sresins.c index 71d413163..6c1fe8d7b 100644 --- a/sc2/src/sc2code/libs/strings/sresins.c +++ b/sc2/src/sc2code/libs/strings/sresins.c @@ -28,14 +28,14 @@ InstallStringTableResType (COUNT string_type) STRING_TABLE LoadStringTableInstance (DWORD res) { - MEM_HANDLE hData; + void *data; - hData = res_GetResource (res); - if (hData) + data = res_GetResource (res); + if (data) { res_DetachResource (res); } - return hData; + return (STRING_TABLE)data; } diff --git a/sc2/src/sc2code/libs/strings/strings.c b/sc2/src/sc2code/libs/strings/strings.c index db9160fe5..ccae1cf5f 100644 --- a/sc2/src/sc2code/libs/strings/strings.c +++ b/sc2/src/sc2code/libs/strings/strings.c @@ -22,8 +22,7 @@ STRING_TABLE AllocStringTable (int num_entries, int flags) { - MEM_HANDLE hData = mem_allocate (sizeof (STRING_TABLE_DESC), MEM_SOUND); - STRING_TABLE_DESC *strtab = mem_lock (hData); + STRING_TABLE strtab = HMalloc (sizeof (STRING_TABLE_DESC)); int i, multiplier = 1; if (flags & HAS_SOUND_CLIPS) @@ -34,7 +33,6 @@ AllocStringTable (int num_entries, int flags) { multiplier++; } - strtab->handle = hData; strtab->flags = flags; strtab->size = num_entries; num_entries *= multiplier; @@ -46,17 +44,14 @@ AllocStringTable (int num_entries, int flags) strtab->strings[i].parent = strtab; strtab->strings[i].index = i; } - return hData; + return strtab; } void -FreeStringTable (STRING_TABLE StringTable) +FreeStringTable (STRING_TABLE strtab) { - STRING_TABLE_DESC *strtab; int i, multiplier = 1; - strtab = mem_lock (StringTable); - if (strtab == NULL) { return; @@ -80,8 +75,7 @@ FreeStringTable (STRING_TABLE StringTable) } HFree (strtab->strings); - mem_unlock (StringTable); - mem_release (StringTable); + HFree (strtab); } BOOLEAN @@ -94,20 +88,9 @@ DestroyStringTable (STRING_TABLE StringTable) STRING CaptureStringTable (STRING_TABLE StringTable) { - if (StringTable != 0) + if ((StringTable != 0) && (StringTable->size > 0)) { - STRING_TABLE_DESC *StringTablePtr; - - LockStringTable (StringTable, &StringTablePtr); - if (StringTablePtr->size > 0) - { - return StringTablePtr->strings; - } - else - { - UnlockStringTable (StringTable); - return NULL; - } + return StringTable->strings; } return NULL; @@ -119,8 +102,6 @@ ReleaseStringTable (STRING String) STRING_TABLE StringTable; StringTable = GetStringTable (String); - if (StringTable != 0) - UnlockStringTable (StringTable); return (StringTable); } @@ -130,9 +111,9 @@ GetStringTable (STRING String) { if (String && String->parent) { - return String->parent->handle; + return String->parent; } - return NULL_HANDLE; + return NULL; } COUNT @@ -158,7 +139,7 @@ GetStringTableIndex (STRING String) STRING SetAbsStringTableIndex (STRING String, COUNT StringTableIndex) { - STRING_TABLE_DESC *StringTablePtr; + STRING_TABLE StringTablePtr; if (!String) return NULL; @@ -181,7 +162,7 @@ SetAbsStringTableIndex (STRING String, COUNT StringTableIndex) STRING SetRelStringTableIndex (STRING String, SIZE StringTableOffs) { - STRING_TABLE_DESC *StringTablePtr; + STRING_TABLE StringTablePtr; if (!String) return NULL; @@ -230,7 +211,7 @@ GetStringLengthBin (STRING String) STRINGPTR GetStringSoundClip (STRING String) { - STRING_TABLE_DESC *StringTablePtr; + STRING_TABLE StringTablePtr; COUNT StringIndex; if (String == NULL) @@ -263,7 +244,7 @@ GetStringSoundClip (STRING String) STRINGPTR GetStringTimeStamp (STRING String) { - STRING_TABLE_DESC *StringTablePtr; + STRING_TABLE StringTablePtr; COUNT StringIndex; int offset; diff --git a/sc2/src/sc2code/libs/strings/strintrn.h b/sc2/src/sc2code/libs/strings/strintrn.h index 0f8722dc5..c02d5f868 100644 --- a/sc2/src/sc2code/libs/strings/strintrn.h +++ b/sc2/src/sc2code/libs/strings/strintrn.h @@ -22,7 +22,6 @@ #include #include #include "strlib.h" -#include "memlib.h" #include "reslib.h" struct string_table_entry @@ -33,25 +32,20 @@ struct string_table_entry struct string_table *parent; }; -typedef struct string_table +struct string_table { - MEM_HANDLE handle; unsigned short flags; int size; STRING_TABLE_ENTRY_DESC *strings; -} STRING_TABLE_DESC; -typedef STRING_TABLE_DESC *PSTRING_TABLE_DESC; +}; #define HAS_SOUND_CLIPS (1 << 0) #define HAS_TIMESTAMP (1 << 1) -#define LockStringTable LockResourceData -#define UnlockStringTable UnlockResourceData - STRING_TABLE AllocStringTable (int num_entries, int flags); void FreeStringTable (STRING_TABLE strtab); -MEM_HANDLE _GetStringData (uio_Stream *fp, DWORD length); +void *_GetStringData (uio_Stream *fp, DWORD length); #endif /* _STRINTRN_H */ diff --git a/sc2/src/sc2code/libs/strlib.h b/sc2/src/sc2code/libs/strlib.h index 77d7df0bb..95fcdc09d 100644 --- a/sc2/src/sc2code/libs/strlib.h +++ b/sc2/src/sc2code/libs/strlib.h @@ -21,14 +21,14 @@ #include "compiler.h" #include "port.h" -#include "libs/memlib.h" #include "libs/uio.h" #include typedef struct string_table_entry STRING_TABLE_ENTRY_DESC; +typedef struct string_table STRING_TABLE_DESC; -typedef MEM_HANDLE STRING_TABLE; +typedef STRING_TABLE_DESC *STRING_TABLE; typedef STRING_TABLE_ENTRY_DESC *STRING; typedef BYTE *STRINGPTR; diff --git a/sc2/src/sc2code/libs/video/vidplayer.c b/sc2/src/sc2code/libs/video/vidplayer.c index 4fe23703f..c9b02d5c6 100644 --- a/sc2/src/sc2code/libs/video/vidplayer.c +++ b/sc2/src/sc2code/libs/video/vidplayer.c @@ -346,12 +346,11 @@ TFB_PlayVideo (VIDEO_REF VidRef, uint32 x, uint32 y) } // nasty hack for now - LockMusicData (vid->hAudio, &pmus); + pmus = vid->hAudio; (*pmus)->buffer_tag = HCalloc ( sizeof (TFB_SoundTag) * (*pmus)->num_buffers); (*pmus)->callbacks = vp_AudioCBs; (*pmus)->data = vid; // hijack data ;) - UnlockMusicData (vid->hAudio); } SetSemaphore (vp_interthread_lock); diff --git a/sc2/src/sc2code/loadship.c b/sc2/src/sc2code/loadship.c index 0fcc8815d..f13b7aed0 100644 --- a/sc2/src/sc2code/loadship.c +++ b/sc2/src/sc2code/loadship.c @@ -26,11 +26,10 @@ RACE_DESC * load_ship (DWORD RaceResIndex, BOOLEAN LoadBattleData) { - MEM_HANDLE h; + RESOURCE_INDEX h, hOldIndex; RACE_DESC *RDPtr = 0; #define INITIAL_CODE_RES MAKE_RESOURCE (1, CODE, 0) void *CodeRef; - MEM_HANDLE hOldIndex; h = OpenResourceIndexInstance (RaceResIndex); if (!h) diff --git a/sc2/src/sc2code/nameref.h b/sc2/src/sc2code/nameref.h index 158551c71..ed5458912 100644 --- a/sc2/src/sc2code/nameref.h +++ b/sc2/src/sc2code/nameref.h @@ -22,8 +22,8 @@ #include "restypes.h" #define LoadCodeRes LoadCodeResInstance -#define LoadGraphic LoadGraphicInstance -#define LoadFont LoadGraphicInstance +#define LoadGraphic (DRAWABLE)LoadGraphicInstance +#define LoadFont (FONT)LoadGraphicInstance #define LoadColorMap LoadColorMapInstance #define LoadStringTable LoadStringTableInstance #define LoadSound LoadSoundInstance diff --git a/sc2/src/sc2code/pickship.c b/sc2/src/sc2code/pickship.c index 1075f35dc..ab829807b 100644 --- a/sc2/src/sc2code/pickship.c +++ b/sc2/src/sc2code/pickship.c @@ -451,7 +451,7 @@ DrawArmadaPickShip (BOOLEAN draw_salvage_frame, RECT *pPickRect) STAMP s; TEXT t; CONTEXT OldContext; - MEM_HANDLE hLastIndex; + RESOURCE_INDEX hLastIndex; FRAME PickFrame; hLastIndex = SetResourceIndex (hResIndex); diff --git a/sc2/src/sc2code/planets/lander.c b/sc2/src/sc2code/planets/lander.c index ee5bca43c..6eb5ec0e1 100644 --- a/sc2/src/sc2code/planets/lander.c +++ b/sc2/src/sc2code/planets/lander.c @@ -533,7 +533,7 @@ static void CheckObjectCollision (COUNT index) { INTERSECT_CONTROL LanderControl; - MEM_HANDLE LanderHandle; + DRAWABLE LanderHandle; PRIMITIVE *pPrim; PRIMITIVE *pLanderPrim; PLANETSIDE_DESC *pPSD; @@ -555,7 +555,7 @@ CheckObjectCollision (COUNT index) pPSD = (PLANETSIDE_DESC*)pMenuState->ModuleFrame; LanderControl.EndPoint = LanderControl.IntersectStamp.origin; - LanderHandle = GetFrameHandle (LanderControl.IntersectStamp.frame); + LanderHandle = GetFrameParentDrawable (LanderControl.IntersectStamp.frame); for (; index != END_OF_LIST; index = GetPredLink (GetPrimLinks (pPrim))) { @@ -566,7 +566,7 @@ CheckObjectCollision (COUNT index) ElementControl.IntersectStamp = pPrim->Object.Stamp; ElementControl.EndPoint = ElementControl.IntersectStamp.origin; - if (GetFrameHandle (ElementControl.IntersectStamp.frame) + if (GetFrameParentDrawable (ElementControl.IntersectStamp.frame) == LanderHandle) { CheckObjectCollision (index); diff --git a/sc2/src/sc2code/planets/planets.c b/sc2/src/sc2code/planets/planets.c index eeff8d76f..6dc9f0799 100644 --- a/sc2/src/sc2code/planets/planets.c +++ b/sc2/src/sc2code/planets/planets.c @@ -279,7 +279,7 @@ FreePlanet (void) void LoadStdLanderFont (PLANET_INFO *info) { - info->LanderFont = CaptureFont (LoadFont (LANDER_FONT)); + info->LanderFont = LoadFont (LANDER_FONT); info->LanderFontEff = CaptureDrawable ( LoadGraphic (LANDER_FONTEFF_PMAP_ANIM)); } @@ -287,8 +287,8 @@ LoadStdLanderFont (PLANET_INFO *info) void FreeLanderFont (PLANET_INFO *info) { - DestroyFont (ReleaseFont (info->LanderFont)); - info->LanderFont = 0; + DestroyFont (info->LanderFont); + info->LanderFont = NULL; DestroyDrawable (ReleaseDrawable (info->LanderFontEff)); - info->LanderFontEff = 0; + info->LanderFontEff = NULL; } diff --git a/sc2/src/sc2code/setup.c b/sc2/src/sc2code/setup.c index 41c165704..f77bf613f 100644 --- a/sc2/src/sc2code/setup.c +++ b/sc2/src/sc2code/setup.c @@ -46,7 +46,7 @@ ACTIVITY LastActivity; BYTE PlayerControl[NUM_PLAYERS]; // XXX: These declarations should really go to the file they belong to. -MEM_HANDLE hResIndex; +RESOURCE_INDEX hResIndex; CONTEXT ScreenContext; CONTEXT SpaceContext; CONTEXT StatusContext; @@ -184,11 +184,11 @@ InitKernel (void) for (counter = 0; counter < NUM_PLAYERS; ++counter) InitQueue (&race_q[counter], MAX_SHIPS_PER_SIDE, sizeof (STARSHIP)); - StarConFont = CaptureFont (LoadFont (STARCON_FONT)); + StarConFont = LoadFont (STARCON_FONT); if (StarConFont == NULL) return FALSE; - TinyFont = CaptureFont (LoadFont (TINY_FONT)); + TinyFont = LoadFont (TINY_FONT); if (TinyFont == NULL) return FALSE; @@ -204,7 +204,7 @@ InitKernel (void) if (GameStrings == 0) return FALSE; - MicroFont = CaptureFont (LoadFont (MICRO_FONT)); + MicroFont = LoadFont (MICRO_FONT); if (MicroFont == NULL) return FALSE; diff --git a/sc2/src/sc2code/setup.h b/sc2/src/sc2code/setup.h index 8f40eb608..d273889e2 100644 --- a/sc2/src/sc2code/setup.h +++ b/sc2/src/sc2code/setup.h @@ -19,12 +19,12 @@ #include "displist.h" #include "globdata.h" +#include "libs/reslib.h" #include "libs/sndlib.h" #include "libs/gfxlib.h" #include "libs/threadlib.h" - -extern MEM_HANDLE hResIndex; +extern RESOURCE_INDEX hResIndex; extern FRAME Screen; extern FRAME ActivityFrame; diff --git a/sc2/src/sc2code/ships/androsyn/androsyn.c b/sc2/src/sc2code/ships/androsyn/androsyn.c index 7511cf855..33aff3b60 100644 --- a/sc2/src/sc2code/ships/androsyn/androsyn.c +++ b/sc2/src/sc2code/ships/androsyn/androsyn.c @@ -94,7 +94,7 @@ static RACE_DESC androsynth_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/arilou/arilou.c b/sc2/src/sc2code/ships/arilou/arilou.c index 00ab6945b..186d08802 100644 --- a/sc2/src/sc2code/ships/arilou/arilou.c +++ b/sc2/src/sc2code/ships/arilou/arilou.c @@ -95,7 +95,7 @@ static RACE_DESC arilou_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/blackurq/blackurq.c b/sc2/src/sc2code/ships/blackurq/blackurq.c index c9bf8cbf7..b3330caa2 100644 --- a/sc2/src/sc2code/ships/blackurq/blackurq.c +++ b/sc2/src/sc2code/ships/blackurq/blackurq.c @@ -97,7 +97,7 @@ static RACE_DESC black_urquan_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/chenjesu/chenjesu.c b/sc2/src/sc2code/ships/chenjesu/chenjesu.c index b8da7a53d..85c2d424f 100644 --- a/sc2/src/sc2code/ships/chenjesu/chenjesu.c +++ b/sc2/src/sc2code/ships/chenjesu/chenjesu.c @@ -100,7 +100,7 @@ static RACE_DESC chenjesu_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/chmmr/chmmr.c b/sc2/src/sc2code/ships/chmmr/chmmr.c index b11b12c43..03ad4d1eb 100644 --- a/sc2/src/sc2code/ships/chmmr/chmmr.c +++ b/sc2/src/sc2code/ships/chmmr/chmmr.c @@ -97,7 +97,7 @@ static RACE_DESC chmmr_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/druuge/druuge.c b/sc2/src/sc2code/ships/druuge/druuge.c index 0ebd6e19a..aa6cc3c10 100644 --- a/sc2/src/sc2code/ships/druuge/druuge.c +++ b/sc2/src/sc2code/ships/druuge/druuge.c @@ -93,7 +93,7 @@ static RACE_DESC druuge_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/human/human.c b/sc2/src/sc2code/ships/human/human.c index 3e87a28f8..263b882b6 100644 --- a/sc2/src/sc2code/ships/human/human.c +++ b/sc2/src/sc2code/ships/human/human.c @@ -97,7 +97,7 @@ static RACE_DESC human_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/ilwrath/ilwrath.c b/sc2/src/sc2code/ships/ilwrath/ilwrath.c index 30154d82c..788c28d9c 100644 --- a/sc2/src/sc2code/ships/ilwrath/ilwrath.c +++ b/sc2/src/sc2code/ships/ilwrath/ilwrath.c @@ -95,7 +95,7 @@ static RACE_DESC ilwrath_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/lastbat/lastbat.c b/sc2/src/sc2code/ships/lastbat/lastbat.c index eb3035fdb..008168624 100644 --- a/sc2/src/sc2code/ships/lastbat/lastbat.c +++ b/sc2/src/sc2code/ships/lastbat/lastbat.c @@ -100,7 +100,7 @@ static RACE_DESC samatra_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/melnorme/melnorme.c b/sc2/src/sc2code/ships/melnorme/melnorme.c index 076bc9c68..3ae46ab12 100644 --- a/sc2/src/sc2code/ships/melnorme/melnorme.c +++ b/sc2/src/sc2code/ships/melnorme/melnorme.c @@ -96,7 +96,7 @@ static RACE_DESC melnorme_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/mmrnmhrm/mmrnmhrm.c b/sc2/src/sc2code/ships/mmrnmhrm/mmrnmhrm.c index 352addea8..ab02d1625 100644 --- a/sc2/src/sc2code/ships/mmrnmhrm/mmrnmhrm.c +++ b/sc2/src/sc2code/ships/mmrnmhrm/mmrnmhrm.c @@ -108,7 +108,7 @@ static RACE_DESC mmrnmhrm_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/mycon/mycon.c b/sc2/src/sc2code/ships/mycon/mycon.c index 8956a5db0..0e5febb57 100644 --- a/sc2/src/sc2code/ships/mycon/mycon.c +++ b/sc2/src/sc2code/ships/mycon/mycon.c @@ -96,7 +96,7 @@ static RACE_DESC mycon_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/orz/orz.c b/sc2/src/sc2code/ships/orz/orz.c index c0ca4d9d3..0a0a9cb91 100644 --- a/sc2/src/sc2code/ships/orz/orz.c +++ b/sc2/src/sc2code/ships/orz/orz.c @@ -98,7 +98,7 @@ static RACE_DESC orz_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/pkunk/pkunk.c b/sc2/src/sc2code/ships/pkunk/pkunk.c index 48d22c65f..febf166a6 100644 --- a/sc2/src/sc2code/ships/pkunk/pkunk.c +++ b/sc2/src/sc2code/ships/pkunk/pkunk.c @@ -96,7 +96,7 @@ static RACE_DESC pkunk_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/probe/probe.c b/sc2/src/sc2code/ships/probe/probe.c index 190945e97..4c676495e 100644 --- a/sc2/src/sc2code/ships/probe/probe.c +++ b/sc2/src/sc2code/ships/probe/probe.c @@ -90,7 +90,7 @@ static RACE_DESC probe_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/shofixti/shofixti.c b/sc2/src/sc2code/ships/shofixti/shofixti.c index cc2783fba..ff1d7c3e2 100644 --- a/sc2/src/sc2code/ships/shofixti/shofixti.c +++ b/sc2/src/sc2code/ships/shofixti/shofixti.c @@ -96,7 +96,7 @@ static RACE_DESC shofixti_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/sis_ship/sis_ship.c b/sc2/src/sc2code/ships/sis_ship/sis_ship.c index 2e828f0e6..e029fba49 100644 --- a/sc2/src/sc2code/ships/sis_ship/sis_ship.c +++ b/sc2/src/sc2code/ships/sis_ship/sis_ship.c @@ -102,7 +102,7 @@ static RACE_DESC sis_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/slylandr/slylandr.c b/sc2/src/sc2code/ships/slylandr/slylandr.c index 608b685e9..a48421357 100644 --- a/sc2/src/sc2code/ships/slylandr/slylandr.c +++ b/sc2/src/sc2code/ships/slylandr/slylandr.c @@ -95,7 +95,7 @@ static RACE_DESC slylandro_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/spathi/spathi.c b/sc2/src/sc2code/ships/spathi/spathi.c index 6cec6715d..945bd56d7 100644 --- a/sc2/src/sc2code/ships/spathi/spathi.c +++ b/sc2/src/sc2code/ships/spathi/spathi.c @@ -93,7 +93,7 @@ static RACE_DESC spathi_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/supox/supox.c b/sc2/src/sc2code/ships/supox/supox.c index 1fabd5117..2809c4e1a 100644 --- a/sc2/src/sc2code/ships/supox/supox.c +++ b/sc2/src/sc2code/ships/supox/supox.c @@ -95,7 +95,7 @@ static RACE_DESC supox_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/syreen/syreen.c b/sc2/src/sc2code/ships/syreen/syreen.c index 15192fd5b..81db2dc2c 100644 --- a/sc2/src/sc2code/ships/syreen/syreen.c +++ b/sc2/src/sc2code/ships/syreen/syreen.c @@ -96,7 +96,7 @@ static RACE_DESC syreen_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/thradd/thradd.c b/sc2/src/sc2code/ships/thradd/thradd.c index d48005a00..e8c1af143 100644 --- a/sc2/src/sc2code/ships/thradd/thradd.c +++ b/sc2/src/sc2code/ships/thradd/thradd.c @@ -96,7 +96,7 @@ static RACE_DESC thraddash_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/umgah/umgah.c b/sc2/src/sc2code/ships/umgah/umgah.c index 3d88d92fc..49cacbf9a 100644 --- a/sc2/src/sc2code/ships/umgah/umgah.c +++ b/sc2/src/sc2code/ships/umgah/umgah.c @@ -95,7 +95,7 @@ static RACE_DESC umgah_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/urquan/urquan.c b/sc2/src/sc2code/ships/urquan/urquan.c index 7762aa27a..57a44d716 100644 --- a/sc2/src/sc2code/ships/urquan/urquan.c +++ b/sc2/src/sc2code/ships/urquan/urquan.c @@ -97,7 +97,7 @@ static RACE_DESC urquan_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/utwig/utwig.c b/sc2/src/sc2code/ships/utwig/utwig.c index 5897347b6..707459e94 100644 --- a/sc2/src/sc2code/ships/utwig/utwig.c +++ b/sc2/src/sc2code/ships/utwig/utwig.c @@ -97,7 +97,7 @@ static RACE_DESC utwig_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/vux/vux.c b/sc2/src/sc2code/ships/vux/vux.c index 50ed8361a..b45b54314 100644 --- a/sc2/src/sc2code/ships/vux/vux.c +++ b/sc2/src/sc2code/ships/vux/vux.c @@ -98,7 +98,7 @@ static RACE_DESC vux_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/yehat/yehat.c b/sc2/src/sc2code/ships/yehat/yehat.c index 8bfaa4e05..6bcc71b75 100644 --- a/sc2/src/sc2code/ships/yehat/yehat.c +++ b/sc2/src/sc2code/ships/yehat/yehat.c @@ -95,7 +95,7 @@ static RACE_DESC yehat_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/sc2code/ships/zoqfot/zoqfot.c b/sc2/src/sc2code/ships/zoqfot/zoqfot.c index 662f7a593..771cc9a45 100644 --- a/sc2/src/sc2code/ships/zoqfot/zoqfot.c +++ b/sc2/src/sc2code/ships/zoqfot/zoqfot.c @@ -96,7 +96,7 @@ static RACE_DESC zoqfotpik_desc = { NULL, NULL, NULL }, { NULL, NULL, NULL }, { NULL, NULL, NULL }, - NULL_HANDLE, NULL + NULL, NULL }, { 0, diff --git a/sc2/src/starcon2.c b/sc2/src/starcon2.c index 35ef17e3f..62304aba2 100644 --- a/sc2/src/starcon2.c +++ b/sc2/src/starcon2.c @@ -33,6 +33,7 @@ #include "controls.h" #include "file.h" #include "port.h" +#include "libs/memlib.h" #include "libs/platform.h" #include "libs/log.h" #include "options.h"