Finished memory refactoring.

MEM_HANDLE and friends are no longer visible to the main code at all, which now treats everything as pointers.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2901 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2008-01-12 05:21:49 +00:00
parent 8199596810
commit 4acc058c4f
110 changed files with 456 additions and 648 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
Changes towards version 0.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 - Split out RESOURCEs from the loaded data in RACE_DESC and LOCDATA
structures - Michael structures - Michael
- Normalized all loaded resources to be flat MEM_HANDLEs - Michael
- Prevent overflow for planet weight when scanning a planet (bug #1025) - Prevent overflow for planet weight when scanning a planet (bug #1025)
- from Benjamin Alan Weaver - from Benjamin Alan Weaver
- Don't set _POSIX_THREAD_SAFE_FUNCTIONS - SvdB - Don't set _POSIX_THREAD_SAFE_FUNCTIONS - SvdB
+3 -3
View File
@@ -74,12 +74,12 @@ UninitKernel (BOOLEAN ships)
UninitSpace (); UninitSpace ();
DestroySound (ReleaseSound (MenuSounds)); DestroySound (ReleaseSound (MenuSounds));
DestroyFont (ReleaseFont (MicroFont)); DestroyFont (MicroFont);
DestroyStringTable (ReleaseStringTable (GameStrings)); DestroyStringTable (ReleaseStringTable (GameStrings));
DestroyDrawable (ReleaseDrawable (StatusFrame)); DestroyDrawable (ReleaseDrawable (StatusFrame));
DestroyDrawable (ReleaseDrawable (ActivityFrame)); DestroyDrawable (ReleaseDrawable (ActivityFrame));
DestroyFont (ReleaseFont (TinyFont)); DestroyFont (TinyFont);
DestroyFont (ReleaseFont (StarConFont)); DestroyFont (StarConFont);
UninitQueue (&race_q[0]); UninitQueue (&race_q[0]);
UninitQueue (&race_q[1]); UninitQueue (&race_q[1]);
+2 -2
View File
@@ -609,7 +609,7 @@ MeleeConnectDialog (int side)
{ {
CONNECT_DIALOG_STATE state; CONNECT_DIALOG_STATE state;
PlayerFont = CaptureFont ((FONT_REF)LoadFont (PLAYER_FONT)); PlayerFont = LoadFont (PLAYER_FONT);
state.Initialized = FALSE; state.Initialized = FALSE;
state.which_side = side; state.which_side = side;
@@ -622,7 +622,7 @@ MeleeConnectDialog (int side)
current_state = NULL; current_state = NULL;
DestroyFont (ReleaseFont (PlayerFont)); DestroyFont (PlayerFont);
return state.confirmed; return state.confirmed;
} }
+5 -6
View File
@@ -21,16 +21,15 @@
#include "reslib.h" #include "reslib.h"
extern MEM_HANDLE LoadCodeResFile (const char *pStr); extern void *LoadCodeResFile (const char *pStr);
extern BOOLEAN InstallCodeResType (COUNT code_type); extern BOOLEAN InstallCodeResType (COUNT code_type);
extern MEM_HANDLE LoadCodeResInstance (RESOURCE res); extern void *LoadCodeResInstance (RESOURCE res);
extern void* CaptureCodeRes (MEM_HANDLE hCode, void *pData, void **ppLocData); extern void *CaptureCodeRes (void *hCode, void *pData, void **ppLocData);
extern MEM_HANDLE ReleaseCodeRes (void *CodeRef); extern void *ReleaseCodeRes (void *CodeRef);
extern BOOLEAN DestroyCodeRes (MEM_HANDLE hCode); extern BOOLEAN DestroyCodeRes (void *hCode);
typedef struct typedef struct
{ {
MEM_HANDLE hCode;
UWORD size; UWORD size;
} CODE_REF; } CODE_REF;
+6 -7
View File
@@ -1298,7 +1298,7 @@ DoResponsePhrase (RESPONSE_REF R, RESPONSE_FUNC response_func,
static void static void
HailAlien (void) HailAlien (void)
{ {
MEM_HANDLE hOldIndex; RESOURCE_INDEX hOldIndex;
ENCOUNTER_STATE ES; ENCOUNTER_STATE ES;
FONT PlayerFont, OldFont; FONT PlayerFont, OldFont;
MUSIC_REF SongRef = 0; MUSIC_REF SongRef = 0;
@@ -1309,13 +1309,12 @@ HailAlien (void)
ES.InputFunc = DoCommunication; ES.InputFunc = DoCommunication;
hOldIndex = SetResourceIndex (hResIndex); hOldIndex = SetResourceIndex (hResIndex);
PlayerFont = CaptureFont ((FONT_REF)LoadFont (PLAYER_FONT)); PlayerFont = LoadFont (PLAYER_FONT);
SetResourceIndex (hOldIndex); SetResourceIndex (hOldIndex);
CommData.AlienFrame = CaptureDrawable ( CommData.AlienFrame = CaptureDrawable (
LoadGraphic (CommData.AlienFrameRes)); LoadGraphic (CommData.AlienFrameRes));
CommData.AlienFont = CaptureFont ((FONT_REF) CommData.AlienFont = LoadFont (CommData.AlienFontRes);
LoadFont (CommData.AlienFontRes));
CommData.AlienColorMap = CaptureColorMap ( CommData.AlienColorMap = CaptureColorMap (
LoadColorMap (CommData.AlienColorMapRes)); LoadColorMap (CommData.AlienColorMapRes));
if ((CommData.AlienSongFlags & LDASF_USE_ALTERNATE) if ((CommData.AlienSongFlags & LDASF_USE_ALTERNATE)
@@ -1417,7 +1416,7 @@ HailAlien (void)
DestroyStringTable (ReleaseStringTable (CommData.ConversationPhrases)); DestroyStringTable (ReleaseStringTable (CommData.ConversationPhrases));
DestroyMusic (CommData.AlienSong); DestroyMusic (CommData.AlienSong);
DestroyColorMap (ReleaseColorMap (CommData.AlienColorMap)); DestroyColorMap (ReleaseColorMap (CommData.AlienColorMap));
DestroyFont (ReleaseFont (CommData.AlienFont)); DestroyFont (CommData.AlienFont);
DestroyDrawable (ReleaseDrawable (CommData.AlienFrame)); DestroyDrawable (ReleaseDrawable (CommData.AlienFrame));
DestroyContext (TextCacheContext); DestroyContext (TextCacheContext);
@@ -1425,7 +1424,7 @@ HailAlien (void)
SetContext (SpaceContext); SetContext (SpaceContext);
SetContextFont (OldFont); SetContextFont (OldFont);
DestroyFont (ReleaseFont (PlayerFont)); DestroyFont (PlayerFont);
CommData.ConversationPhrases = 0; CommData.ConversationPhrases = 0;
pCurInputState = 0; pCurInputState = 0;
@@ -1435,7 +1434,7 @@ COUNT
InitCommunication (RESOURCE which_comm) InitCommunication (RESOURCE which_comm)
{ {
COUNT status; COUNT status;
MEM_HANDLE hOldIndex, hIndex; RESOURCE_INDEX hOldIndex, hIndex;
LOCDATA *LocDataPtr; LOCDATA *LocDataPtr;
#ifdef DEBUG #ifdef DEBUG
+1 -1
View File
@@ -223,7 +223,7 @@ static LOCDATA arilou_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -125,7 +125,7 @@ static LOCDATA blackurq_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -111,7 +111,7 @@ static LOCDATA chmmr_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -86,7 +86,7 @@ static LOCDATA commander_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -152,7 +152,7 @@ static LOCDATA druuge_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -95,7 +95,7 @@ static LOCDATA ilwrath_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -106,7 +106,7 @@ static LOCDATA melnorme_desc =
&melnorme_numbers_english, /* AlienNumberSpeech - default */ &melnorme_numbers_english, /* AlienNumberSpeech - default */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -104,7 +104,7 @@ static LOCDATA mycon_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -166,7 +166,7 @@ static LOCDATA orz_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -91,7 +91,7 @@ static LOCDATA pkunk_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -188,7 +188,7 @@ static LOCDATA yehat_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -152,7 +152,7 @@ static LOCDATA shofixti_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -166,7 +166,7 @@ static LOCDATA slylandro_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -113,7 +113,7 @@ static LOCDATA slylandro_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -179,7 +179,7 @@ static LOCDATA spahome_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -140,7 +140,7 @@ static LOCDATA spathi_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -154,7 +154,7 @@ static LOCDATA commander_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -96,7 +96,7 @@ static LOCDATA supox_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -186,7 +186,7 @@ static LOCDATA syreen_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -193,7 +193,7 @@ static LOCDATA talkpet_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -129,7 +129,7 @@ static LOCDATA thradd_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -191,7 +191,7 @@ static LOCDATA umgah_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -116,7 +116,7 @@ static LOCDATA urquan_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -193,7 +193,7 @@ static LOCDATA utwig_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -196,7 +196,7 @@ static LOCDATA vux_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -187,7 +187,7 @@ static LOCDATA yehat_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+1 -1
View File
@@ -105,7 +105,7 @@ static LOCDATA zoqfot_desc =
NULL, /* AlienNumberSpeech - none */ NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */ /* Filler for loaded resources */
NULL, NULL, NULL, NULL, NULL, NULL,
NULL_HANDLE, NULL,
NULL, NULL,
}; };
+2 -2
View File
@@ -554,7 +554,7 @@ StartCredits (void)
CreditsBack = CaptureDrawable (LoadGraphic (CREDITS_BACK_ANIM)); CreditsBack = CaptureDrawable (LoadGraphic (CREDITS_BACK_ANIM));
// load fonts // load fonts
for (fdef = CreditsFont; fdef->size; ++fdef) for (fdef = CreditsFont; fdef->size; ++fdef)
fdef->font = CaptureFont (LoadFont (fdef->res)); fdef->font = LoadFont (fdef->res);
CreditsRate = CREDITS_BASE_RATE; CreditsRate = CREDITS_BASE_RATE;
CreditsRunning = FALSE; CreditsRunning = FALSE;
@@ -578,7 +578,7 @@ FreeCredits (void)
// free fonts // free fonts
for (fdef = CreditsFont; fdef->size; ++fdef) for (fdef = CreditsFont; fdef->size; ++fdef)
{ {
DestroyFont (ReleaseFont (fdef->font)); DestroyFont (fdef->font);
fdef->font = 0; fdef->font = 0;
} }
} }
+28 -33
View File
@@ -33,18 +33,17 @@
typedef struct typedef struct
{ {
MEM_HANDLE handle;
RACE_DESC data _ALIGNED_ANY; RACE_DESC data _ALIGNED_ANY;
} CODERES_STRUCT; } CODERES_STRUCT;
MEM_HANDLE void *
LoadCodeResFile (const char *pStr) LoadCodeResFile (const char *pStr)
{ {
(void) pStr; /* Satisfying compiler (unused parameter) */ (void) pStr; /* Satisfying compiler (unused parameter) */
return (0); return NULL;
} }
static MEM_HANDLE static void *
GetCodeResData (uio_Stream *fp, DWORD length) GetCodeResData (uio_Stream *fp, DWORD length)
{ {
enum enum
@@ -81,15 +80,15 @@ enum
}; };
BYTE which_res; BYTE which_res;
MEM_HANDLE hData; void *hData;
which_res = GetResFileChar (fp); which_res = GetResFileChar (fp);
hData = mem_allocate (sizeof (CODERES_STRUCT), DEFAULT_MEM_FLAGS); hData = HMalloc (sizeof (CODERES_STRUCT));
if (hData) if (hData)
{ {
RACE_DESC *RDPtr; RACE_DESC *RDPtr;
RDPtr = 0; RDPtr = NULL;
switch (which_res) switch (which_res)
{ {
case ANDROSYN_CODE_RES: case ANDROSYN_CODE_RES:
@@ -295,36 +294,40 @@ enum
if (RDPtr == 0) if (RDPtr == 0)
{ {
mem_release (hData); HFree (hData);
hData = 0; hData = 0;
} }
else else
{ {
CODERES_STRUCT *cs; CODERES_STRUCT *cs;
cs = (CODERES_STRUCT *) mem_lock (hData); cs = (CODERES_STRUCT *) hData;
cs->data = *RDPtr; cs->data = *RDPtr; // Structure assignment.
// Structure assignment.
mem_unlock (hData);
} }
} }
(void) length; /* Satisfying compiler (unused parameter) */ (void) length; /* Satisfying compiler (unused parameter) */
return (hData); return (hData);
} }
BOOLEAN
_ReleaseCodeResData (void *data)
{
HFree (data);
return TRUE;
}
BOOLEAN BOOLEAN
InstallCodeResType (COUNT code_type) InstallCodeResType (COUNT code_type)
{ {
return (InstallResTypeVectors (code_type, return (InstallResTypeVectors (code_type,
GetCodeResData, mem_release)); GetCodeResData, _ReleaseCodeResData));
} }
MEM_HANDLE void *
LoadCodeResInstance (DWORD res) LoadCodeResInstance (DWORD res)
{ {
MEM_HANDLE hData; void *hData;
hData = res_GetResource (res); hData = res_GetResource (res);
if (hData) if (hData)
@@ -335,25 +338,25 @@ LoadCodeResInstance (DWORD res)
BOOLEAN BOOLEAN
DestroyCodeRes (MEM_HANDLE hCode) DestroyCodeRes (void *hCode)
{ {
return (mem_release (hCode)); HFree (hCode);
return (TRUE);
} }
void* void*
CaptureCodeRes (MEM_HANDLE hCode, void *pData, void **ppLocData) CaptureCodeRes (void *hCode, void *pData, void **ppLocData)
{ {
CODERES_STRUCT *cs; CODERES_STRUCT *cs;
if (hCode == 0) if (hCode == NULL)
{ {
log_add (log_Fatal, "dummy.c::CaptureCodeRes() hCode==0! FATAL!"); log_add (log_Fatal, "dummy.c::CaptureCodeRes() hCode==NULL! FATAL!");
return(0); return(NULL);
} }
cs = (CODERES_STRUCT *) mem_lock (hCode); cs = (CODERES_STRUCT *) hCode;
cs->handle = hCode;
*ppLocData = &cs->data; *ppLocData = &cs->data;
(void) pData; /* Satisfying compiler (unused parameter) */ (void) pData; /* Satisfying compiler (unused parameter) */
@@ -361,16 +364,8 @@ CaptureCodeRes (MEM_HANDLE hCode, void *pData, void **ppLocData)
} }
MEM_HANDLE void *
ReleaseCodeRes (void *CodeRef) ReleaseCodeRes (void *CodeRef)
{ {
if (CodeRef) return CodeRef;
{
MEM_HANDLE hCode;
mem_unlock (hCode = *(MEM_HANDLE *)CodeRef);
return (hCode);
}
return (0);
} }
+2 -2
View File
@@ -184,7 +184,7 @@ COUNT
InitEncounter (void) InitEncounter (void)
{ {
COUNT i; COUNT i;
MEM_HANDLE hOldIndex; RESOURCE_INDEX hOldIndex;
FRAME SegueFrame; FRAME SegueFrame;
STAMP s; STAMP s;
TEXT t; TEXT t;
@@ -713,7 +713,7 @@ ExitUninitEncounter:
void void
EncounterBattle (void) EncounterBattle (void)
{ {
MEM_HANDLE hLastIndex; RESOURCE_INDEX hLastIndex;
ACTIVITY OldActivity; ACTIVITY OldActivity;
extern UWORD nth_frame; extern UWORD nth_frame;
+1 -1
View File
@@ -142,7 +142,7 @@ LoadSC2Data (void)
{ {
if (FlagStatFrame == 0) if (FlagStatFrame == 0)
{ {
MEM_HANDLE hOldIndex; RESOURCE_INDEX hOldIndex;
hOldIndex = SetResourceIndex (hResIndex); hOldIndex = SetResourceIndex (hResIndex);
+1 -1
View File
@@ -31,7 +31,7 @@ load_gravity_well (BYTE selector)
RES_TYPE rt; RES_TYPE rt;
RES_INSTANCE ri; RES_INSTANCE ri;
RES_PACKAGE rp; RES_PACKAGE rp;
MEM_HANDLE hLastIndex; RESOURCE_INDEX hLastIndex;
hLastIndex = SetResourceIndex (hResIndex); hLastIndex = SetResourceIndex (hResIndex);
+19 -3
View File
@@ -65,19 +65,35 @@ load_animation (FRAME *pixarray, RESOURCE big_res, RESOURCE med_res, RESOURCE
return TRUE; 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 BOOLEAN
free_image (FRAME *pixarray) free_image (FRAME *pixarray)
{ {
BOOLEAN retval; BOOLEAN retval;
COUNT i; COUNT i, j;
void *already_freed[NUM_VIEWS];
retval = TRUE; retval = TRUE;
for (i = 0; i < NUM_VIEWS; ++i) for (i = 0; i < NUM_VIEWS; ++i)
{ {
if (pixarray[i] != NULL) if (pixarray[i] != NULL)
{ {
if (!DestroyDrawable (ReleaseDrawable (pixarray[i]))) BOOLEAN ok = TRUE;
retval = FALSE; 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; pixarray[i] = NULL;
} }
} }
+3 -3
View File
@@ -430,8 +430,8 @@ DoPresentation (void *pIS)
if (pPIS->Buffer[0]) if (pPIS->Buffer[0])
{ /* asked to load a font */ { /* asked to load a font */
if (*pFont) if (*pFont)
DestroyFont (ReleaseFont (*pFont)); DestroyFont (*pFont);
*pFont = CaptureFont ((FONT_REF) LoadFontFile (pPIS->Buffer)); *pFont = LoadFontFile (pPIS->Buffer);
} }
if (!pPIS->Batched) if (!pPIS->Batched)
@@ -847,7 +847,7 @@ ShowPresentation (STRING PresStr)
DestroyDrawable (ReleaseDrawable (pis.RotatedFrame)); DestroyDrawable (ReleaseDrawable (pis.RotatedFrame));
DestroyDrawable (ReleaseDrawable (pis.Frame)); DestroyDrawable (ReleaseDrawable (pis.Frame));
for (i = 0; i < MAX_FONTS; ++i) for (i = 0; i < MAX_FONTS; ++i)
DestroyFont (ReleaseFont (pis.Fonts[i])); DestroyFont (pis.Fonts[i]);
DestroyStringTable (ReleaseStringTable (pis.SlideShow)); DestroyStringTable (ReleaseStringTable (pis.SlideShow));
LockMutex (GraphicsLock); LockMutex (GraphicsLock);
+1 -1
View File
@@ -36,7 +36,7 @@ static SWORD *encode_arrays;
#define AllocEncodeArrays() \ #define AllocEncodeArrays() \
HCalloc ( \ HCalloc ( \
(MEM_SIZE)(((N + 1) + (N + 257) + (N + 1)) \ (((N + 1) + (N + 257) + (N + 1)) \
* sizeof (lson[0]))) * sizeof (lson[0])))
#define FreeCodeArrays HFree #define FreeCodeArrays HFree
+1 -1
View File
@@ -75,7 +75,7 @@ typedef LZHCODE_DESC *PLZHCODE_DESC;
(*_Stream++ = (BYTE)(c))) (*_Stream++ = (BYTE)(c)))
#define AllocCodeDesc() HCalloc ((MEM_SIZE)sizeof (LZHCODE_DESC)) #define AllocCodeDesc() HCalloc (sizeof (LZHCODE_DESC))
#define FreeCodeDesc HFree #define FreeCodeDesc HFree
extern void _update (COUNT c); extern void _update (COUNT c);
+8 -12
View File
@@ -19,15 +19,17 @@
#ifndef _GFXLIB_H #ifndef _GFXLIB_H
#define _GFXLIB_H #define _GFXLIB_H
#include "memlib.h" #include "compiler.h"
typedef struct context_desc CONTEXT_DESC; typedef struct context_desc CONTEXT_DESC;
typedef struct frame_desc FRAME_DESC; typedef struct frame_desc FRAME_DESC;
typedef struct font_desc FONT_DESC; typedef struct font_desc FONT_DESC;
typedef struct drawable_desc DRAWABLE_DESC;
typedef CONTEXT_DESC *CONTEXT; typedef CONTEXT_DESC *CONTEXT;
typedef FRAME_DESC *FRAME; typedef FRAME_DESC *FRAME;
typedef FONT_DESC *FONT; typedef FONT_DESC *FONT;
typedef DRAWABLE_DESC *DRAWABLE;
typedef UWORD TIME_VALUE; typedef UWORD TIME_VALUE;
@@ -131,10 +133,6 @@ typedef struct
STAMP IntersectStamp; STAMP IntersectStamp;
} INTERSECT_CONTROL; } INTERSECT_CONTROL;
typedef MEM_HANDLE DRAWABLE;
typedef MEM_HANDLE FONT_REF;
typedef BYTE INTERSECT_CODE; typedef BYTE INTERSECT_CODE;
#define INTERSECT_LEFT (INTERSECT_CODE)(1 << 0) #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 SetFrameHot (FRAME Frame, HOT_SPOT HotSpot);
extern HOT_SPOT GetFrameHot (FRAME Frame); extern HOT_SPOT GetFrameHot (FRAME Frame);
extern BOOLEAN InstallGraphicResTypes (COUNT cel_type, COUNT font_type); extern BOOLEAN InstallGraphicResTypes (COUNT cel_type, COUNT font_type);
extern DWORD LoadGraphicFile (const char *pStr); extern DRAWABLE LoadGraphicFile (const char *pStr);
extern DWORD LoadFontFile (const char *pStr); extern FONT LoadFontFile (const char *pStr);
extern DWORD LoadGraphicInstance (DWORD res); extern void *LoadGraphicInstance (DWORD res);
extern DRAWABLE LoadDisplayPixmap (RECT *area, FRAME frame); extern DRAWABLE LoadDisplayPixmap (RECT *area, FRAME frame);
extern FRAME SetContextFontEffect (FRAME EffectFrame); extern FRAME SetContextFontEffect (FRAME EffectFrame);
extern FONT SetContextFont (FONT Font); extern FONT SetContextFont (FONT Font);
extern BOOLEAN DestroyFont (FONT_REF FontRef); extern BOOLEAN DestroyFont (FONT FontRef);
extern FONT CaptureFont (FONT_REF FontRef);
extern FONT_REF ReleaseFont (FONT Font);
extern BOOLEAN TextRect (TEXT *pText, RECT *pRect, BYTE *pdelta); extern BOOLEAN TextRect (TEXT *pText, RECT *pRect, BYTE *pdelta);
extern BOOLEAN GetContextFontLeading (SIZE *pheight); extern BOOLEAN GetContextFontLeading (SIZE *pheight);
extern BOOLEAN GetContextFontLeadingWidth (SIZE *pwidth); extern BOOLEAN GetContextFontLeadingWidth (SIZE *pwidth);
@@ -228,7 +224,7 @@ extern void SetFrameTransparentColor (FRAME Frame, COLOR c32k);
extern FRAME CaptureDrawable (DRAWABLE Drawable); extern FRAME CaptureDrawable (DRAWABLE Drawable);
extern DRAWABLE ReleaseDrawable (FRAME Frame); extern DRAWABLE ReleaseDrawable (FRAME Frame);
extern MEM_HANDLE GetFrameHandle (FRAME Frame); extern DRAWABLE GetFrameParentDrawable (FRAME Frame);
extern BOOLEAN SetColorMap (COLORMAPPTR ColorMapPtr); extern BOOLEAN SetColorMap (COLORMAPPTR ColorMapPtr);
extern DWORD XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval); extern DWORD XFormColorMap (COLORMAPPTR ColorMapPtr, SIZE TimeInterval);
+1 -1
View File
@@ -41,7 +41,7 @@ struct context_desc
}; };
#define AllocContext() HCalloc ((MEM_SIZE)sizeof (CONTEXT_DESC)) #define AllocContext() HCalloc (sizeof (CONTEXT_DESC))
#define FreeContext HFree #define FreeContext HFree
extern CONTEXT _pCurContext; extern CONTEXT _pCurContext;
+7 -16
View File
@@ -83,20 +83,17 @@ DRAWABLE
AllocDrawable (COUNT n) AllocDrawable (COUNT n)
{ {
DRAWABLE Drawable; DRAWABLE Drawable;
Drawable = (DRAWABLE)mem_allocate ((MEM_SIZE)(sizeof (DRAWABLE_DESC)), Drawable = (DRAWABLE) HCalloc(sizeof (DRAWABLE_DESC));
MEM_ZEROINIT | MEM_GRAPHICS);
if (Drawable) if (Drawable)
{ {
DRAWABLE_DESC *DrawablePtr;
int i; int i;
DrawablePtr = LockDrawable (Drawable); Drawable->Frame = (FRAME)HMalloc (sizeof (FRAME_DESC) * n);
DrawablePtr->Frame = (FRAME)HMalloc ((MEM_SIZE)(sizeof (FRAME_DESC) * n));
/* Zero out the newly allocated frames, since HMalloc doesn't have MEM_ZEROINIT. */ /* Zero out the newly allocated frames, since HMalloc doesn't have MEM_ZEROINIT. */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
FRAME F; FRAME F;
F = &DrawablePtr->Frame[i]; F = &Drawable->Frame[i];
F->parent = DrawablePtr; F->parent = Drawable;
F->Type = 0; F->Type = 0;
F->Index = 0; F->Index = 0;
F->image = 0; F->image = 0;
@@ -105,8 +102,6 @@ AllocDrawable (COUNT n)
F->HotSpot.x = 0; F->HotSpot.x = 0;
F->HotSpot.y = 0; F->HotSpot.y = 0;
} }
UnlockDrawable (Drawable);
} }
return Drawable; return Drawable;
} }
@@ -143,15 +138,11 @@ CreateDrawable (CREATE_FLAGS CreateFlags, SIZE width, SIZE height, COUNT
BOOLEAN BOOLEAN
DestroyDrawable (DRAWABLE Drawable) DestroyDrawable (DRAWABLE Drawable)
{ {
DRAWABLE_DESC *DrawablePtr; if (_CurFramePtr && (Drawable == _CurFramePtr->parent))
SetContextFGFrame ((FRAME)NULL);
if (LOWORD (Drawable) == GetFrameHandle (_CurFramePtr)) if (Drawable)
SetContextFGFrame ((FRAME)0);
DrawablePtr = LockDrawable (Drawable);
if (DrawablePtr)
{ {
UnlockDrawable (Drawable);
FreeDrawable (Drawable); FreeDrawable (Drawable);
return (TRUE); return (TRUE);
+2 -7
View File
@@ -50,8 +50,6 @@ struct frame_desc
typedef struct drawable_desc typedef struct drawable_desc
{ {
MEM_HANDLE hDrawable;
CREATE_FLAGS Flags; CREATE_FLAGS Flags;
UWORD MaxIndex; UWORD MaxIndex;
FRAME_DESC *Frame; FRAME_DESC *Frame;
@@ -66,10 +64,7 @@ typedef struct drawable_desc
#define DRAWABLE_PRIORITY DEFAULT_MEM_PRIORITY #define DRAWABLE_PRIORITY DEFAULT_MEM_PRIORITY
extern DRAWABLE AllocDrawable (COUNT num_frames); 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 FreeDrawable(D) _ReleaseCelData (D)
#define GetFrameParentDrawable(F) (F)->parent
#define TYPE_GET(f) ((f) & FTYPE_MASK) #define TYPE_GET(f) ((f) & FTYPE_MASK)
#define INDEX_GET(f) ((f) & FINDEX_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); DrawableType, CREATE_FLAGS flags, SIZE width, SIZE height);
extern INTERSECT_CODE _clip_line (RECT *pClipRect, BRESENHAM_LINE *pLine); extern INTERSECT_CODE _clip_line (RECT *pClipRect, BRESENHAM_LINE *pLine);
extern MEM_HANDLE _GetCelData (uio_Stream *fp, DWORD length); extern void *_GetCelData (uio_Stream *fp, DWORD length);
extern BOOLEAN _ReleaseCelData (MEM_HANDLE handle); extern BOOLEAN _ReleaseCelData (void *handle);
extern STAMP _save_stamp; extern STAMP _save_stamp;
extern FRAME _CurFramePtr; extern FRAME _CurFramePtr;
+9 -9
View File
@@ -21,7 +21,7 @@
#include "libs/reslib.h" #include "libs/reslib.h"
DWORD DRAWABLE
LoadGraphicFile (const char *pStr) LoadGraphicFile (const char *pStr)
{ {
uio_Stream *fp; uio_Stream *fp;
@@ -34,19 +34,19 @@ LoadGraphicFile (const char *pStr)
fp = res_OpenResFile (contentDir, pStr, "rb"); fp = res_OpenResFile (contentDir, pStr, "rb");
if (fp != NULL) if (fp != NULL)
{ {
MEM_HANDLE hData; DRAWABLE hData;
_cur_resfile_name = pStr; _cur_resfile_name = pStr;
hData = _GetCelData (fp, LengthResFile (fp)); hData = (DRAWABLE)_GetCelData (fp, LengthResFile (fp));
_cur_resfile_name = 0; _cur_resfile_name = 0;
res_CloseResFile (fp); res_CloseResFile (fp);
return ((DWORD)hData); return hData;
} }
return (0); return (NULL);
} }
DWORD FONT
LoadFontFile (const char *pStr) LoadFontFile (const char *pStr)
{ {
uio_Stream *fp; uio_Stream *fp;
@@ -59,13 +59,13 @@ LoadFontFile (const char *pStr)
fp = res_OpenResFile (contentDir, pStr, "rb"); fp = res_OpenResFile (contentDir, pStr, "rb");
if (fp == (uio_Stream *) ~0) if (fp == (uio_Stream *) ~0)
{ {
MEM_HANDLE hData; FONT hData;
_cur_resfile_name = pStr; _cur_resfile_name = pStr;
hData = _GetFontData (fp, LengthResFile (fp)); hData = (FONT)_GetFontData (fp, LengthResFile (fp));
_cur_resfile_name = 0; _cur_resfile_name = 0;
res_CloseResFile (fp); res_CloseResFile (fp);
return ((DWORD)hData); return hData;
} }
return (0); return (0);
+4 -35
View File
@@ -42,48 +42,17 @@ SetContextFont (FONT Font)
} }
BOOLEAN BOOLEAN
DestroyFont (FONT_REF FontRef) DestroyFont (FONT FontRef)
{ {
if (FontRef == 0) if (FontRef == NULL)
return (FALSE); return (FALSE);
if (_CurFontPtr && _CurFontPtr->FontRef == FontRef) if (_CurFontPtr && _CurFontPtr == FontRef)
SetContextFont ((FONT)0); SetContextFont ((FONT)NULL);
return (FreeFont (FontRef)); 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 void
font_DrawText (TEXT *lpText) font_DrawText (TEXT *lpText)
{ {
+3 -9
View File
@@ -48,8 +48,6 @@ FreeFontPage (FONT_PAGE *page)
struct font_desc struct font_desc
{ {
FONT_REF FontRef;
UWORD Leading; UWORD Leading;
UWORD LeadingWidth; UWORD LeadingWidth;
FONT_PAGE *fontPages; FONT_PAGE *fontPages;
@@ -59,17 +57,13 @@ struct font_desc
#define FONT_PRIORITY DEFAULT_MEM_PRIORITY #define FONT_PRIORITY DEFAULT_MEM_PRIORITY
#define AllocFont(size) \ #define AllocFont(size) (FONT)HCalloc (sizeof (FONT_DESC) + (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 FreeFont _ReleaseFontData #define FreeFont _ReleaseFontData
extern FONT _CurFontPtr; extern FONT _CurFontPtr;
extern MEM_HANDLE _GetFontData (uio_Stream *fp, DWORD length); extern void *_GetFontData (uio_Stream *fp, DWORD length);
extern BOOLEAN _ReleaseFontData (MEM_HANDLE handle); extern BOOLEAN _ReleaseFontData (void *handle);
#endif /* _FONT_H */ #endif /* _FONT_H */
+1 -1
View File
@@ -36,7 +36,7 @@
DRAWABLE DRAWABLE
LoadDisplayPixmap (RECT *area, FRAME frame) LoadDisplayPixmap (RECT *area, FRAME frame)
{ {
MEM_HANDLE buffer = GetFrameHandle (frame); DRAWABLE buffer = GetFrameParentDrawable (frame);
COUNT index = GetFrameIndex (frame); COUNT index = GetFrameIndex (frame);
if (buffer || (buffer = CreateDrawable ( if (buffer || (buffer = CreateDrawable (
+14 -22
View File
@@ -19,18 +19,25 @@
#include "gfxintrn.h" #include "gfxintrn.h"
#include "libs/log.h" #include "libs/log.h"
FRAME DRAWABLE
CaptureDrawable (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) if (DrawablePtr)
{ {
return &DrawablePtr->Frame[0]; return &DrawablePtr->Frame[0];
} }
return (0); return NULL;
} }
DRAWABLE DRAWABLE
@@ -39,28 +46,13 @@ ReleaseDrawable (FRAME FramePtr)
if (FramePtr != 0) if (FramePtr != 0)
{ {
DRAWABLE Drawable; DRAWABLE Drawable;
DRAWABLE_DESC *DrawablePtr;
DrawablePtr = GetFrameParentDrawable (FramePtr); Drawable = GetFrameParentDrawable (FramePtr);
Drawable = DrawablePtr->hDrawable;
UnlockDrawable (Drawable);
return (Drawable); return (Drawable);
} }
return NULL_HANDLE; return NULL;
}
MEM_HANDLE
GetFrameHandle (FRAME FramePtr)
{
DRAWABLE_DESC *DrawablePtr;
if (FramePtr == 0)
return (0);
DrawablePtr = GetFrameParentDrawable (FramePtr);
return (DrawablePtr->hDrawable);
} }
COUNT COUNT
+4 -3
View File
@@ -27,15 +27,16 @@ InstallGraphicResTypes (COUNT cel_type, COUNT font_type)
return (TRUE); return (TRUE);
} }
DWORD /* Needs to be void * because it could be either a DRAWABLE or a FONT. */
void *
LoadGraphicInstance (DWORD res) LoadGraphicInstance (DWORD res)
{ {
MEM_HANDLE hData; void *hData;
hData = res_GetResource (res); hData = res_GetResource (res);
if (hData) if (hData)
res_DetachResource (res); res_DetachResource (res);
return ((DWORD)hData); return (hData);
} }
+45 -70
View File
@@ -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)); return (SDL_MapRGBA (img->format, r, g, b, a));
} }
MEM_HANDLE void *
_GetCelData (uio_Stream *fp, DWORD length) _GetCelData (uio_Stream *fp, DWORD length)
{ {
int cel_total, cel_index, n; 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); 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); ani = HMalloc (sizeof (AniData) * cel_total);
@@ -418,7 +418,7 @@ _GetCelData (uio_Stream *fp, DWORD length)
HFree (img); HFree (img);
log_add (log_Warning, "Couldn't allocate space for '%s' anidata", _cur_resfile_name); log_add (log_Warning, "Couldn't allocate space for '%s' anidata", _cur_resfile_name);
return NULL_HANDLE; return NULL;
} }
cel_index = 0; cel_index = 0;
@@ -455,36 +455,31 @@ _GetCelData (uio_Stream *fp, DWORD length)
break; break;
} }
Drawable = NULL_HANDLE; Drawable = NULL;
if (cel_index && (Drawable = AllocDrawable (cel_index))) if (cel_index && (Drawable = AllocDrawable (cel_index)))
{ {
DRAWABLE_DESC *DrawablePtr; if (!Drawable)
if ((DrawablePtr = LockDrawable (Drawable)) == 0)
{ {
while (cel_index--) while (cel_index--)
SDL_FreeSurface (img[cel_index]); SDL_FreeSurface (img[cel_index]);
mem_release ((MEM_HANDLE)Drawable); HFree (Drawable);
Drawable = NULL_HANDLE; Drawable = NULL;
} }
else else
{ {
FRAME FramePtr; FRAME FramePtr;
DrawablePtr->hDrawable = Drawable; Drawable->Flags = WANT_PIXMAP;
DrawablePtr->Flags = WANT_PIXMAP; Drawable->MaxIndex = cel_index - 1;
DrawablePtr->MaxIndex = cel_index - 1;
FramePtr = &DrawablePtr->Frame[cel_index]; FramePtr = &Drawable->Frame[cel_index];
while (--FramePtr, cel_index--) while (--FramePtr, cel_index--)
process_image (FramePtr, img, ani, 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'", log_add (log_Warning, "Couldn't get cel data for '%s'",
_cur_resfile_name); _cur_resfile_name);
@@ -494,13 +489,13 @@ _GetCelData (uio_Stream *fp, DWORD length)
} }
BOOLEAN BOOLEAN
_ReleaseCelData (MEM_HANDLE handle) _ReleaseCelData (DRAWABLE handle)
{ {
DRAWABLE_DESC *DrawablePtr; DRAWABLE_DESC *DrawablePtr;
int cel_ct; int cel_ct;
FRAME FramePtr = NULL; FRAME FramePtr = NULL;
if ((DrawablePtr = LockDrawable (handle)) == 0) if ((DrawablePtr = handle) == 0)
return (FALSE); return (FALSE);
cel_ct = DrawablePtr->MaxIndex + 1; cel_ct = DrawablePtr->MaxIndex + 1;
@@ -514,8 +509,8 @@ _ReleaseCelData (MEM_HANDLE handle)
} }
} }
UnlockDrawable (handle); HFree (handle);
if (mem_release (handle) && FramePtr) if (FramePtr)
{ {
int i; int i;
for (i = 0; i < cel_ct; 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; return (int) bcd1->index - (int) bcd2->index;
} }
MEM_HANDLE void *
_GetFontData (uio_Stream *fp, DWORD length) _GetFontData (uio_Stream *fp, DWORD length)
{ {
COUNT numDirEntries; COUNT numDirEntries;
FONT_REF fontRef = 0; DIRENTRY fontDir = NULL;
DIRENTRY fontDir = 0;
BuildCharDesc *bcds = NULL; BuildCharDesc *bcds = NULL;
size_t numBCDs = 0; size_t numBCDs = 0;
int dirEntryI; int dirEntryI;
uio_DirHandle *fontDirHandle = NULL; uio_DirHandle *fontDirHandle = NULL;
FONT fontPtr; FONT fontPtr = NULL;
if (_cur_resfile_name == 0) if (_cur_resfile_name == 0)
goto err; goto err;
@@ -613,15 +607,10 @@ _GetFontData (uio_Stream *fp, DWORD length)
qsort (bcds, numBCDs, sizeof (BuildCharDesc), qsort (bcds, numBCDs, sizeof (BuildCharDesc),
(int (*)(const void *, const void *)) compareBCDIndex); (int (*)(const void *, const void *)) compareBCDIndex);
fontRef = AllocFont (0); fontPtr = AllocFont (0);
if (fontRef == 0)
goto err;
fontPtr = LockFont (fontRef);
if (fontPtr == NULL) if (fontPtr == NULL)
goto err; goto err;
fontPtr->FontRef = fontRef;
fontPtr->Leading = 0; fontPtr->Leading = 0;
fontPtr->LeadingWidth = 0; fontPtr->LeadingWidth = 0;
@@ -684,17 +673,16 @@ _GetFontData (uio_Stream *fp, DWORD length)
} }
fontPtr->Leading++; fontPtr->Leading++;
UnlockFont (fontRef);
HFree (bcds); HFree (bcds);
(void) fp; /* Satisfying compiler (unused parameter) */ (void) fp; /* Satisfying compiler (unused parameter) */
(void) length; /* Satisfying compiler (unused parameter) */ (void) length; /* Satisfying compiler (unused parameter) */
return fontRef; return fontPtr;
err: err:
if (fontRef != 0) if (fontPtr != 0)
mem_release (fontRef); HFree (fontPtr);
if (bcds != NULL) if (bcds != NULL)
{ {
@@ -713,9 +701,9 @@ err:
} }
BOOLEAN BOOLEAN
_ReleaseFontData (MEM_HANDLE handle) _ReleaseFontData (void *handle)
{ {
FONT font = LockFont (handle); FONT font = (FONT) handle;
if (font == NULL) if (font == NULL)
return FALSE; return FALSE;
@@ -743,8 +731,7 @@ _ReleaseFontData (MEM_HANDLE handle)
} }
} }
UnlockFont (handle); HFree (font);
mem_release (handle);
return TRUE; return TRUE;
} }
@@ -762,43 +749,31 @@ _request_drawable (COUNT NumFrames, DRAWABLE_TYPE DrawableType,
); );
if (Drawable) if (Drawable)
{ {
DRAWABLE_DESC *DrawablePtr; int imgw, imgh;
FRAME FramePtr;
if ((DrawablePtr = LockDrawable (Drawable)) == 0) Drawable->Flags = flags;
Drawable->MaxIndex = NumFrames - 1;
imgw = width;
imgh = height;
FramePtr = &Drawable->Frame[NumFrames - 1];
while (NumFrames--)
{ {
FreeDrawable (Drawable); TFB_Image *Image;
Drawable = NULL_HANDLE;
}
else
{
int imgw, imgh;
FRAME FramePtr;
DrawablePtr->hDrawable = Drawable; if (DrawableType == RAM_DRAWABLE && imgw > 0 && imgh > 0
DrawablePtr->Flags = flags; && (Image = TFB_DrawImage_New (TFB_DrawCanvas_New_TrueColor (
DrawablePtr->MaxIndex = NumFrames - 1; imgw, imgh, (flags & WANT_ALPHA) ? TRUE : FALSE))))
imgw = width;
imgh = height;
FramePtr = &DrawablePtr->Frame[NumFrames - 1];
while (NumFrames--)
{ {
TFB_Image *Image; FramePtr->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;
} }
UnlockDrawable (Drawable);
FramePtr->Type = DrawableType;
FramePtr->Index = NumFrames;
SetFrameBounds (FramePtr, width, height);
--FramePtr;
} }
} }
+1 -1
View File
@@ -19,8 +19,8 @@
#ifndef _INPLIB_H #ifndef _INPLIB_H
#define _INPLIB_H #define _INPLIB_H
#include "memlib.h"
#include <stddef.h> #include <stddef.h>
#include "compiler.h"
#include "libs/uio.h" #include "libs/uio.h"
typedef DWORD INPUT_STATE; typedef DWORD INPUT_STATE;
+15 -24
View File
@@ -20,11 +20,13 @@
#define _RESLIB_H #define _RESLIB_H
//#include <stdio.h> //#include <stdio.h>
#include "compiler.h"
#include "port.h" #include "port.h"
#include "memlib.h" #include "misc.h"
#include "libs/uio.h" #include "libs/uio.h"
typedef struct resource_index *RESOURCE_INDEX;
typedef DWORD RESOURCE; typedef DWORD RESOURCE;
typedef BYTE RES_TYPE; typedef BYTE RES_TYPE;
@@ -52,8 +54,8 @@ typedef COUNT RES_PACKAGE;
extern const char *_cur_resfile_name; extern const char *_cur_resfile_name;
typedef MEM_HANDLE (ResourceLoadFun) (uio_Stream *fp, DWORD len); typedef void *(ResourceLoadFun) (uio_Stream *fp, DWORD len);
typedef BOOLEAN (ResourceFreeFun) (MEM_HANDLE handle); typedef BOOLEAN (ResourceFreeFun) (void *handle);
extern uio_Stream *res_OpenResFile (uio_DirHandle *dir, const char *filename, extern uio_Stream *res_OpenResFile (uio_DirHandle *dir, const char *filename,
const char *mode); const char *mode);
@@ -69,35 +71,25 @@ extern long LengthResFile (uio_Stream *fp);
extern BOOLEAN res_CloseResFile (uio_Stream *fp); extern BOOLEAN res_CloseResFile (uio_Stream *fp);
extern BOOLEAN DeleteResFile (uio_DirHandle *dir, const char *filename); 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)); RES_TYPE resType, BOOLEAN (*FileErrorFun) (const char *filename));
extern void UninitResourceSystem (void); extern void UninitResourceSystem (void);
extern BOOLEAN InstallResTypeVectors (RES_TYPE res_type, extern BOOLEAN InstallResTypeVectors (RES_TYPE res_type,
ResourceLoadFun *loadFun, ResourceFreeFun *freeFun); ResourceLoadFun *loadFun, ResourceFreeFun *freeFun);
extern MEM_HANDLE res_GetResource (RESOURCE res); extern void *res_GetResource (RESOURCE res);
extern MEM_HANDLE res_DetachResource (RESOURCE res); extern void *res_DetachResource (RESOURCE res);
extern BOOLEAN FreeResource (RESOURCE res); extern BOOLEAN FreeResource (RESOURCE res);
extern COUNT CountResourceTypes (void); extern COUNT CountResourceTypes (void);
extern MEM_HANDLE OpenResourceIndexFile (const char *resfile); extern RESOURCE_INDEX OpenResourceIndexFile (const char *resfile);
extern MEM_HANDLE OpenResourceIndexInstance (RESOURCE res); extern RESOURCE_INDEX OpenResourceIndexInstance (RESOURCE res);
extern MEM_HANDLE SetResourceIndex (MEM_HANDLE newIndexHandle); extern RESOURCE_INDEX SetResourceIndex (RESOURCE_INDEX newIndexHandle);
extern BOOLEAN CloseResourceIndex (MEM_HANDLE newIndexHandle); extern BOOLEAN CloseResourceIndex (RESOURCE_INDEX newIndexHandle);
extern MEM_HANDLE GetResourceData (uio_Stream *fp, DWORD length, extern void *GetResourceData (uio_Stream *fp, DWORD length);
MEM_FLAGS mem_flags);
#define RESOURCE_PRIORITY DEFAULT_MEM_PRIORITY #define AllocResourceData HMalloc
#define FreeResourceData HFree
#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
#include "strlib.h" #include "strlib.h"
@@ -105,7 +97,6 @@ typedef STRING_TABLE DIRENTRY_REF;
typedef STRING DIRENTRY; typedef STRING DIRENTRY;
typedef STRINGPTR DIRENTRYPTR; typedef STRINGPTR DIRENTRYPTR;
extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle, extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle,
const char *path, const char *pattern, match_MatchType matchType); const char *path, const char *pattern, match_MatchType matchType);
#define CaptureDirEntryTable CaptureStringTable #define CaptureDirEntryTable CaptureStringTable
+2 -3
View File
@@ -70,7 +70,7 @@ LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path,
} }
StringTable = AllocStringTable (num_entries, 0); StringTable = AllocStringTable (num_entries, 0);
LockStringTable (StringTable, &lpST); lpST = StringTable;
if (lpST == 0) if (lpST == 0)
{ {
FreeStringTable (StringTable); FreeStringTable (StringTable);
@@ -95,8 +95,7 @@ LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path,
} }
uio_DirList_free(dirList); uio_DirList_free(dirList);
UnlockStringTable (StringTable); return StringTable;
return ((DIRENTRY_REF) StringTable);
} }
+28 -28
View File
@@ -61,14 +61,14 @@ loadPackage (ResourceIndex *idx, RES_PACKAGE pkg) {
if (GET_PACKAGE (idx->res[i]->res) != pkg) if (GET_PACKAGE (idx->res[i]->res) != pkg)
continue; continue;
if (idx->res[i]->handle != NULL_HANDLE) if (idx->res[i]->resdata != NULL)
continue; // Already loaded continue; // Already loaded
loadResourceDesc (idx, idx->res[i]); loadResourceDesc (idx, idx->res[i]);
} }
} }
MEM_HANDLE void *
loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc) loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc)
{ {
RES_TYPE resType = GET_TYPE (desc->res); 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 " log_add (log_Warning, "Warning: Unable to load '%s'; no handler "
"for type %d defined.", desc->res_id, resType); "for type %d defined.", desc->res_id, resType);
return NULL_HANDLE; return NULL;
} }
path = res_GetString (desc->res_id); path = res_GetString (desc->res_id);
if (path == NULL) if (path == NULL)
{ {
log_add (log_Warning, "Could not decode resource '%s'", desc->res_id); 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); idx->typeInfo.handlers[resType].loadFun);
return desc->handle; return desc->resdata;
} }
MEM_HANDLE void *
loadResource(const char *path, ResourceLoadFun *loadFun) loadResource(const char *path, ResourceLoadFun *loadFun)
{ {
uio_Stream *stream; uio_Stream *stream;
long dataLen; long dataLen;
MEM_HANDLE handle; void *resdata;
stream = res_OpenResFile (contentDir, path, "rb"); stream = res_OpenResFile (contentDir, path, "rb");
if (stream == NULL) if (stream == NULL)
{ {
log_add (log_Warning, "Warning: Can't open '%s'", path); log_add (log_Warning, "Warning: Can't open '%s'", path);
return NULL_HANDLE; return NULL;
} }
dataLen = LengthResFile (stream); dataLen = LengthResFile (stream);
@@ -118,15 +118,15 @@ loadResource(const char *path, ResourceLoadFun *loadFun)
} }
_cur_resfile_name = path; _cur_resfile_name = path;
handle = (*loadFun) (stream, dataLen); resdata = (*loadFun) (stream, dataLen);
_cur_resfile_name = NULL; _cur_resfile_name = NULL;
res_CloseResFile (stream); res_CloseResFile (stream);
return handle; return resdata;
err: err:
res_CloseResFile (stream); res_CloseResFile (stream);
return NULL_HANDLE; return NULL;
} }
// Get a resource by its resource ID. // 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 // 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 // indicate whether you really want this, or add a separate function
// for preloading the entire package. // for preloading the entire package.
MEM_HANDLE void *
res_GetResource (RESOURCE res) res_GetResource (RESOURCE res)
{ {
ResourceIndex *resourceIndex; ResourceIndex *resourceIndex;
@@ -148,17 +148,17 @@ res_GetResource (RESOURCE res)
{ {
log_add (log_Warning, "Trying to get undefined resource %08x", log_add (log_Warning, "Trying to get undefined resource %08x",
(DWORD) res); (DWORD) res);
return NULL_HANDLE; return NULL;
} }
if (desc->handle != NULL_HANDLE) if (desc->resdata != NULL)
return desc->handle; return desc->resdata;
// Load the entire package, for historical reasons. // Load the entire package, for historical reasons.
loadPackage (resourceIndex, GET_PACKAGE (res)); loadPackage (resourceIndex, GET_PACKAGE (res));
return desc->handle; return desc->resdata;
// May still be NULL_HANDLE, if the load failed. // May still be NULL, if the load failed.
} }
// NB: this function appears to be never called! // NB: this function appears to be never called!
@@ -177,7 +177,7 @@ res_FreeResource (RESOURCE res)
return; return;
} }
if (desc->handle == NULL_HANDLE) if (desc->resdata == NULL)
{ {
log_add (log_Debug, "Warning: trying to free not loaded " log_add (log_Debug, "Warning: trying to free not loaded "
"resource."); "resource.");
@@ -186,37 +186,37 @@ res_FreeResource (RESOURCE res)
idx = _get_current_index_header (); idx = _get_current_index_header ();
freeFun = idx->typeInfo.handlers[GET_TYPE (res)].freeFun; freeFun = idx->typeInfo.handlers[GET_TYPE (res)].freeFun;
(*freeFun) (desc->handle); (*freeFun) (desc->resdata);
desc->handle = NULL_HANDLE; desc->resdata = NULL;
} }
// By calling this function the caller will be responsible of unloading // By calling this function the caller will be responsible of unloading
// the resource. If res_GetResource() get called again for this // the resource. If res_GetResource() get called again for this
// resource, a NEW copy will be loaded, regardless of whether a detached // resource, a NEW copy will be loaded, regardless of whether a detached
// copy still exists. // copy still exists.
MEM_HANDLE void *
res_DetachResource (RESOURCE res) res_DetachResource (RESOURCE res)
{ {
ResourceDesc *desc; ResourceDesc *desc;
MEM_HANDLE result; void *result;
desc = lookupResourceDesc (_get_current_index_header(), res); desc = lookupResourceDesc (_get_current_index_header(), res);
if (desc == NULL) if (desc == NULL)
{ {
log_add (log_Debug, "Warning: trying to detach from an unrecognised " log_add (log_Debug, "Warning: trying to detach from an unrecognised "
"resource."); "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 " log_add (log_Debug, "Warning: trying to detach from a not loaded "
"resource."); "resource.");
return NULL_HANDLE; return NULL;
} }
result = desc->handle; result = desc->resdata;
desc->handle = NULL_HANDLE; desc->resdata = NULL;
return result; return result;
} }
+6 -16
View File
@@ -19,13 +19,14 @@
#ifndef _INDEX_H #ifndef _INDEX_H
#define _INDEX_H #define _INDEX_H
#include "reslib.h"
#include <stdio.h> #include <stdio.h>
typedef struct typedef struct
{ {
RESOURCE res; RESOURCE res;
char *res_id; char *res_id;
MEM_HANDLE handle; void *resdata;
//COUNT ref; //COUNT ref;
} ResourceDesc; } ResourceDesc;
@@ -44,30 +45,19 @@ typedef struct
ResourceHandlers *handlers; ResourceHandlers *handlers;
} ResourceTypeInfo; } ResourceTypeInfo;
typedef struct struct resource_index
{ {
ResourceDesc **res; ResourceDesc **res;
ResourceTypeInfo typeInfo; ResourceTypeInfo typeInfo;
size_t numRes; size_t numRes;
} ResourceIndex; };
/* XXX: This should almost certainly be folded into RESOURCE_INDEX wherever possible */
typedef struct resource_index ResourceIndex;
void void
forAllResourceIndices( forAllResourceIndices(
void (*callback) (ResourceIndex *idx, void *extra), void *extra); 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 */ #endif /* _INDEX_H */
+27 -39
View File
@@ -19,10 +19,11 @@
#include "resintrn.h" #include "resintrn.h"
#include "declib.h" #include "declib.h"
MEM_HANDLE void *
GetResourceData (uio_Stream *fp, DWORD length, MEM_FLAGS mem_flags) GetResourceData (uio_Stream *fp, DWORD length)
{ {
MEM_HANDLE RData; BYTE *RDPtr;
void *result;
DECODE_REF fh = 0; DECODE_REF fh = 0;
if (length == ~(DWORD)0) if (length == ~(DWORD)0)
@@ -32,51 +33,38 @@ GetResourceData (uio_Stream *fp, DWORD length, MEM_FLAGS mem_flags)
else else
length -= sizeof (DWORD); length -= sizeof (DWORD);
RData = AllocResourceData (length, mem_flags); result = AllocResourceData (length);
if (RData) RDPtr = result;
if (RDPtr)
{ {
BYTE *RDPtr; COUNT num_read;
LockResourceData (RData, &RDPtr); do
if (RDPtr == NULL)
{ {
FreeResourceData (RData);
RData = 0;
}
else
{
COUNT num_read;
do
{
#define READ_LENGTH 0x00007FFFL #define READ_LENGTH 0x00007FFFL
num_read = length >= READ_LENGTH ? num_read = length >= READ_LENGTH ?
(COUNT)READ_LENGTH : (COUNT)length; (COUNT)READ_LENGTH : (COUNT)length;
if (fh) 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)
{ {
FreeResourceData (RData); if (cread (RDPtr, 1, num_read, fh) != num_read)
RData = 0; 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); cclose (fh);
return (RData); return result;
} }
+45 -73
View File
@@ -30,8 +30,8 @@ static bool copyResTypeHandlers (ResourceIndex *dest,
const ResourceIndex *src); const ResourceIndex *src);
static bool setResTypeHandlers (ResourceIndex *idx, RES_TYPE resType, static bool setResTypeHandlers (ResourceIndex *idx, RES_TYPE resType,
const ResourceHandlers *handlers); const ResourceHandlers *handlers);
static MEM_HANDLE allocResourceIndex(void); static RESOURCE_INDEX allocResourceIndex(void);
static void freeResourceIndex (MEM_HANDLE h); static void freeResourceIndex (RESOURCE_INDEX h);
static List_List *indexList; static List_List *indexList;
@@ -95,19 +95,18 @@ newResourceDesc (RESOURCE res, char *res_id)
result->res = res; result->res = res;
result->res_id = res_id; result->res_id = res_id;
result->handle = NULL_HANDLE; result->resdata = NULL;
//result->ref = 0; //result->ref = 0;
return result; return result;
} }
static MEM_HANDLE static RESOURCE_INDEX
loadResourceIndex (uio_Stream *stream, const char *fileName) { loadResourceIndex (uio_Stream *stream, const char *fileName) {
size_t lineNum; size_t lineNum;
ResourceDesc **descs = NULL; ResourceDesc **descs = NULL;
COUNT numRes; COUNT numRes;
int numDescsAlloced = 0; int numDescsAlloced = 0;
MEM_HANDLE indexHandle = NULL_HANDLE; RESOURCE_INDEX ndx = NULL;
ResourceIndex *ndx = NULL;
#ifdef DEBUG #ifdef DEBUG
RESOURCE lastResource = 0x00000000; RESOURCE lastResource = 0x00000000;
#endif #endif
@@ -238,35 +237,31 @@ loadResourceIndex (uio_Stream *stream, const char *fileName) {
log_add (log_Debug, "Warning: Resource index '%s' contains no valid " log_add (log_Debug, "Warning: Resource index '%s' contains no valid "
"entries.", fileName); "entries.", fileName);
indexHandle = allocResourceIndex (); ndx = allocResourceIndex ();
if (indexHandle == NULL_HANDLE) if (ndx == NULL)
goto err; goto err;
ndx = lockResourceIndex (indexHandle);
ndx->res = descs; ndx->res = descs;
ndx->numRes = numRes; ndx->numRes = numRes;
ndx->typeInfo.numTypes = 0; ndx->typeInfo.numTypes = 0;
ndx->typeInfo.handlers = NULL; ndx->typeInfo.handlers = NULL;
List_add (indexList, (void *) ndx); List_add (indexList, (void *) ndx);
unlockResourceIndex (indexHandle);
return indexHandle; return ndx;
err: err:
if (indexHandle != NULL_HANDLE) if (ndx != NULL)
freeResourceIndex (indexHandle); freeResourceIndex (ndx);
HFree (descs); HFree (descs);
return NULL_HANDLE; return NULL;
} }
// Get the data associated with a resource of type RES_INDEX // Get the data associated with a resource of type RES_INDEX
// (In other words, a ResourceIndex) // (In other words, a ResourceIndex)
MEM_HANDLE void *
_GetResFileData (uio_Stream *res_fp, DWORD fileLength) _GetResFileData (uio_Stream *res_fp, DWORD fileLength)
{ {
MEM_HANDLE handle; RESOURCE_INDEX ndx, parentNdx;
ResourceIndex *ndx;
ResourceIndex *parentNdx;
#if 0 #if 0
ResourceDesc *desc; ResourceDesc *desc;
@@ -278,39 +273,28 @@ _GetResFileData (uio_Stream *res_fp, DWORD fileLength)
return desc->handle; return desc->handle;
#endif #endif
handle = loadResourceIndex (res_fp, _cur_resfile_name); ndx = loadResourceIndex (res_fp, _cur_resfile_name);
if (handle == NULL_HANDLE)
return NULL_HANDLE;
ndx = lockResourceIndex (handle);
parentNdx = _get_current_index_header (); parentNdx = _get_current_index_header ();
if (parentNdx != NULL) if (parentNdx != NULL)
copyResTypeHandlers (ndx, parentNdx); copyResTypeHandlers (ndx, parentNdx);
unlockResourceIndex (handle);
(void) fileLength; (void) fileLength;
return handle; return ndx;
} }
BOOLEAN BOOLEAN
_ReleaseResFileData (MEM_HANDLE handle) _ReleaseResFileData (RESOURCE_INDEX ndx)
{ {
ResourceIndex *ndx;
ndx = lockResourceIndex (handle);
if (ndx->typeInfo.handlers != NULL) if (ndx->typeInfo.handlers != NULL)
HFree (ndx->typeInfo.handlers); HFree (ndx->typeInfo.handlers);
unlockResourceIndex (handle); HFree (ndx);
mem_release (handle);
return TRUE; return TRUE;
} }
MEM_HANDLE RESOURCE_INDEX
InitResourceSystem (const char *mapfile, const char *resfile, RES_TYPE resType, InitResourceSystem (const char *mapfile, const char *resfile, RES_TYPE resType,
BOOLEAN (*FileErrorFun) (const char *filename)) BOOLEAN (*FileErrorFun) (const char *filename))
{ {
MEM_HANDLE handle;
ResourceIndex *ndx; ResourceIndex *ndx;
ResourceHandlers handlers; ResourceHandlers handlers;
@@ -321,20 +305,18 @@ InitResourceSystem (const char *mapfile, const char *resfile, RES_TYPE resType,
res_LoadFilename (contentDir, mapfile); res_LoadFilename (contentDir, mapfile);
SetResourceIndex (NULL_HANDLE); SetResourceIndex (NULL);
handle = loadResource (resfile, handlers.loadFun); ndx = loadResource (resfile, handlers.loadFun);
if (handle == NULL_HANDLE) if (ndx == NULL)
return NULL_HANDLE; return NULL;
ndx = lockResourceIndex (handle);
setResTypeHandlers (ndx, resType, &handlers); setResTypeHandlers (ndx, resType, &handlers);
unlockResourceIndex (handle);
SetResourceIndex (handle); SetResourceIndex (ndx);
(void) FileErrorFun; (void) FileErrorFun;
(void) mapfile; (void) mapfile;
return handle; return ndx;
} }
void void
@@ -351,15 +333,15 @@ UninitResourceSystem (void)
#endif #endif
uninitIndexList (); uninitIndexList ();
SetResourceIndex (NULL_HANDLE); SetResourceIndex (NULL);
} }
MEM_HANDLE RESOURCE_INDEX
OpenResourceIndexInstance (RESOURCE res) OpenResourceIndexInstance (RESOURCE res)
{ {
MEM_HANDLE hRH; RESOURCE_INDEX hRH;
hRH = res_GetResource (res); hRH = (RESOURCE_INDEX)res_GetResource (res);
if (hRH) if (hRH)
res_DetachResource (res); res_DetachResource (res);
@@ -368,46 +350,36 @@ OpenResourceIndexInstance (RESOURCE res)
// Sets the current global resource index. // Sets the current global resource index.
// This is the index res_GetResource() calls will use. // This is the index res_GetResource() calls will use.
MEM_HANDLE RESOURCE_INDEX
SetResourceIndex (MEM_HANDLE newIndexHandle) SetResourceIndex (RESOURCE_INDEX newIndex)
{ {
static MEM_HANDLE currentIndexHandle; static RESOURCE_INDEX currentIndex;
// NB: currentIndexHandle is locked. // NB: currentIndexHandle is locked.
MEM_HANDLE oldIndexHandle; RESOURCE_INDEX oldIndex;
if (currentIndexHandle != NULL_HANDLE) oldIndex = currentIndex;
unlockResourceIndex (currentIndexHandle); currentIndex = newIndex;
oldIndexHandle = currentIndexHandle; if (currentIndex != NULL) {
currentIndexHandle = newIndexHandle; RESOURCE_INDEX ndx;
if (currentIndexHandle != NULL_HANDLE) { ndx = currentIndex;
ResourceIndex *ndx;
ndx = lockResourceIndex (currentIndexHandle);
_set_current_index_header (ndx); _set_current_index_header (ndx);
} else } else
_set_current_index_header (NULL); _set_current_index_header (NULL);
return oldIndexHandle; return oldIndex;
} }
BOOLEAN BOOLEAN
CloseResourceIndex (MEM_HANDLE handle) CloseResourceIndex (RESOURCE_INDEX ndx)
{ {
ResourceIndex *ndx;
unlockResourceIndex (handle);
ndx = lockResourceIndex (handle);
if (ndx == _get_current_index_header ()) if (ndx == _get_current_index_header ())
SetResourceIndex (NULL_HANDLE); SetResourceIndex (NULL);
List_remove ((void *) indexList, ndx); List_remove ((void *) indexList, ndx);
unlockResourceIndex (handle); _ReleaseResFileData (ndx);
_ReleaseResFileData (handle);
return TRUE; return TRUE;
} }
@@ -470,14 +442,14 @@ copyResTypeHandlers (ResourceIndex *dest, const ResourceIndex *src)
} }
static MEM_HANDLE static RESOURCE_INDEX
allocResourceIndex (void) { allocResourceIndex (void) {
return mem_allocate (sizeof (ResourceIndex), MEM_PRIMARY); return HMalloc (sizeof (struct resource_index));
} }
static void static void
freeResourceIndex (MEM_HANDLE h) { freeResourceIndex (RESOURCE_INDEX h) {
mem_release (h); HFree (h);
} }
+3 -3
View File
@@ -20,11 +20,11 @@
#define _RESINTRN_H #define _RESINTRN_H
#include <string.h> #include <string.h>
#include "libs/reslib.h" #include "reslib.h"
#include "index.h" #include "index.h"
MEM_HANDLE loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc); void *loadResourceDesc (ResourceIndex *idx, ResourceDesc *desc);
MEM_HANDLE loadResource(const char *path, ResourceLoadFun *loadFun); void *loadResource(const char *path, ResourceLoadFun *loadFun);
void _set_current_index_header (ResourceIndex *newResourceIndex); void _set_current_index_header (ResourceIndex *newResourceIndex);
ResourceIndex *_get_current_index_header (void); ResourceIndex *_get_current_index_header (void);
+2 -2
View File
@@ -20,7 +20,6 @@
#define _SNDLIB_H #define _SNDLIB_H
#include "strlib.h" #include "strlib.h"
#include "memlib.h"
typedef STRING_TABLE SOUND_REF; typedef STRING_TABLE SOUND_REF;
typedef STRING SOUND; typedef STRING SOUND;
@@ -43,7 +42,8 @@ typedef struct soundposition
#define GetSoundAddress GetStringAddress #define GetSoundAddress GetStringAddress
#define GetSoundContents GetStringContents #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 BOOLEAN InitSound (int argc, char *argv[]);
extern void UninitSound (void); extern void UninitSound (void);
+7 -7
View File
@@ -35,18 +35,18 @@ LoadSoundFile (const char *pStr)
fp = res_OpenResFile (contentDir, pStr, "rb"); fp = res_OpenResFile (contentDir, pStr, "rb");
if (fp) if (fp)
{ {
MEM_HANDLE hData; SOUND_REF hData;
_cur_resfile_name = pStr; _cur_resfile_name = pStr;
hData = _GetSoundBankData (fp, LengthResFile (fp)); hData = (SOUND_REF)_GetSoundBankData (fp, LengthResFile (fp));
_cur_resfile_name = 0; _cur_resfile_name = 0;
res_CloseResFile (fp); res_CloseResFile (fp);
return ((SOUND_REF)hData); return hData;
} }
return (0); return NULL;
} }
MUSIC_REF MUSIC_REF
@@ -70,15 +70,15 @@ LoadMusicFile (const char *pStr)
fp = res_OpenResFile (contentDir, filename, "rb"); fp = res_OpenResFile (contentDir, filename, "rb");
if (fp) if (fp)
{ {
MEM_HANDLE hData; MUSIC_REF hData;
_cur_resfile_name = filename; _cur_resfile_name = filename;
hData = _GetMusicData (fp, LengthResFile (fp)); hData = (MUSIC_REF)_GetMusicData (fp, LengthResFile (fp));
_cur_resfile_name = 0; _cur_resfile_name = 0;
res_CloseResFile (fp); res_CloseResFile (fp);
return ((MUSIC_REF)hData); return hData;
} }
return (0); return (0);
+14 -27
View File
@@ -28,9 +28,8 @@ static MUSIC_REF curSpeechRef;
void void
PLRPlaySong (MUSIC_REF MusicRef, BOOLEAN Continuous, BYTE Priority) PLRPlaySong (MUSIC_REF MusicRef, BOOLEAN Continuous, BYTE Priority)
{ {
TFB_SoundSample **pmus; TFB_SoundSample **pmus = MusicRef;
LockMusicData (MusicRef, &pmus);
if (pmus) if (pmus)
{ {
LockMutex (soundSource[MUSIC_SOURCE].stream_mutex); LockMutex (soundSource[MUSIC_SOURCE].stream_mutex);
@@ -52,7 +51,6 @@ PLRStop (MUSIC_REF MusicRef)
LockMutex (soundSource[MUSIC_SOURCE].stream_mutex); LockMutex (soundSource[MUSIC_SOURCE].stream_mutex);
StopStream (MUSIC_SOURCE); StopStream (MUSIC_SOURCE);
UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex); UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex);
UnlockMusicData (curMusicRef);
curMusicRef = 0; curMusicRef = 0;
} }
@@ -100,9 +98,8 @@ PLRResume (MUSIC_REF MusicRef)
void void
snd_PlaySpeech (MUSIC_REF SpeechRef) snd_PlaySpeech (MUSIC_REF SpeechRef)
{ {
TFB_SoundSample **pmus; TFB_SoundSample **pmus = SpeechRef;
LockMusicData (SpeechRef, &pmus);
if (pmus) if (pmus)
{ {
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
@@ -122,7 +119,6 @@ snd_StopSpeech (void)
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
StopStream (SPEECH_SOURCE); StopStream (SPEECH_SOURCE);
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
UnlockMusicData (curSpeechRef);
curSpeechRef = 0; curSpeechRef = 0;
} }
@@ -130,7 +126,8 @@ snd_StopSpeech (void)
BOOLEAN BOOLEAN
DestroyMusic (MUSIC_REF MusicRef) DestroyMusic (MUSIC_REF MusicRef)
{ {
return (FreeMusicData (MusicRef)); FreeMusicData (MusicRef);
return (TRUE);
} }
void void
@@ -149,22 +146,18 @@ CheckMusicResName (char* fileName)
return fileName; return fileName;
} }
MEM_HANDLE void *
_GetMusicData (uio_Stream *fp, DWORD length) _GetMusicData (uio_Stream *fp, DWORD length)
{ {
MEM_HANDLE h; MUSIC_REF h;
h = 0;
if (_cur_resfile_name && (h = AllocMusicData (sizeof (void *)))) if (_cur_resfile_name && (h = AllocMusicData (sizeof (void *))))
{ {
TFB_SoundSample **pmus; TFB_SoundSample **pmus = h;
LockMusicData (h, &pmus);
if (!pmus) if (!pmus)
{ {
UnlockMusicData (h); return NULL;
mem_release (h);
h = 0;
} }
else else
{ {
@@ -181,9 +174,8 @@ _GetMusicData (uio_Stream *fp, DWORD length)
{ {
log_add (log_Warning, "_GetMusicData(): couldn't load %s", filename); log_add (log_Warning, "_GetMusicData(): couldn't load %s", filename);
UnlockMusicData (h); HFree (h);
mem_release (h); return NULL;
h = 0;
} }
else else
{ {
@@ -196,8 +188,6 @@ _GetMusicData (uio_Stream *fp, DWORD length)
audio_GenBuffers ((*pmus)->num_buffers, (*pmus)->buffer); audio_GenBuffers ((*pmus)->num_buffers, (*pmus)->buffer);
} }
} }
UnlockMusicData (h);
} }
(void) fp; /* satisfy compiler (unused parameter) */ (void) fp; /* satisfy compiler (unused parameter) */
@@ -206,12 +196,11 @@ _GetMusicData (uio_Stream *fp, DWORD length)
} }
BOOLEAN BOOLEAN
_ReleaseMusicData (MEM_HANDLE handle) _ReleaseMusicData (void *data)
{ {
TFB_SoundSample **pmus; TFB_SoundSample **pmus = data;
LockMusicData (handle, &pmus); if (pmus == NULL)
if (pmus == 0)
return (FALSE); return (FALSE);
if ((*pmus)->decoder) if ((*pmus)->decoder)
@@ -232,9 +221,7 @@ _ReleaseMusicData (MEM_HANDLE handle)
HFree ((*pmus)->buffer_tag); HFree ((*pmus)->buffer_tag);
} }
HFree (*pmus); HFree (*pmus);
HFree (pmus);
UnlockMusicData (handle);
mem_release (handle);
return (TRUE); return (TRUE);
} }
+4 -4
View File
@@ -27,9 +27,9 @@ InstallAudioResTypes (COUNT sound_type, COUNT music_type)
} }
SOUND_REF SOUND_REF
LoadSoundInstance (DWORD res) LoadSoundInstance (RESOURCE res)
{ {
MEM_HANDLE hData; void *hData;
hData = res_GetResource (res); hData = res_GetResource (res);
if (hData) if (hData)
@@ -39,9 +39,9 @@ LoadSoundInstance (DWORD res)
} }
MUSIC_REF MUSIC_REF
LoadMusicInstance (DWORD res) LoadMusicInstance (RESOURCE res)
{ {
MEM_HANDLE hData; void *hData;
hData = res_GetResource (res); hData = res_GetResource (res);
if (hData) if (hData)
+7 -11
View File
@@ -177,7 +177,7 @@ GetSampleRate (SOUND sound)
return 0; return 0;
} }
MEM_HANDLE void *
_GetSoundBankData (uio_Stream *fp, DWORD length) _GetSoundBankData (uio_Stream *fp, DWORD length)
{ {
int snd_ct, n; int snd_ct, n;
@@ -254,12 +254,11 @@ _GetSoundBankData (uio_Stream *fp, DWORD length)
break;*/ break;*/
} }
Snd = 0; Snd = NULL;
if (snd_ct && (Snd = AllocStringTable (snd_ct, 0))) if (snd_ct && (Snd = AllocStringTable (snd_ct, 0)))
{ {
STRING_TABLE_DESC *fxTab; STRING_TABLE fxTab = Snd;
LockStringTable (Snd, &fxTab);
if (fxTab == 0) if (fxTab == 0)
{ {
while (snd_ct--) while (snd_ct--)
@@ -286,19 +285,17 @@ _GetSoundBankData (uio_Stream *fp, DWORD length)
str->length = sizeof (sndfx[0]); str->length = sizeof (sndfx[0]);
str++; str++;
} }
UnlockStringTable (Snd);
} }
} }
return ((MEM_HANDLE)Snd); return Snd;
} }
BOOLEAN BOOLEAN
_ReleaseSoundBankData (MEM_HANDLE Snd) _ReleaseSoundBankData (void *Snd)
{ {
STRING_TABLE_DESC *fxTab; STRING_TABLE fxTab = Snd;
LockStringTable (Snd, &fxTab);
if (fxTab) if (fxTab)
{ {
int snd_ct, index; int snd_ct, index;
@@ -331,7 +328,6 @@ _ReleaseSoundBankData (MEM_HANDLE Snd)
*sptr = 0; *sptr = 0;
index++; index++;
} }
UnlockStringTable (Snd);
FreeStringTable (Snd); FreeStringTable (Snd);
return (TRUE); return (TRUE);
@@ -343,5 +339,5 @@ _ReleaseSoundBankData (MEM_HANDLE Snd)
BOOLEAN BOOLEAN
DestroySound(SOUND_REF target) DestroySound(SOUND_REF target)
{ {
return _ReleaseSoundBankData ((MEM_HANDLE) target); return _ReleaseSoundBankData (target);
} }
+6 -8
View File
@@ -23,16 +23,14 @@
#include "sndlib.h" #include "sndlib.h"
#include "reslib.h" #include "reslib.h"
extern MEM_HANDLE _GetMusicData (uio_Stream *fp, DWORD length); extern void *_GetMusicData (uio_Stream *fp, DWORD length);
extern BOOLEAN _ReleaseMusicData (MEM_HANDLE handle); extern BOOLEAN _ReleaseMusicData (void *handle);
extern MEM_HANDLE _GetSoundBankData (uio_Stream *fp, DWORD length); extern void *_GetSoundBankData (uio_Stream *fp, DWORD length);
extern BOOLEAN _ReleaseSoundBankData (MEM_HANDLE handle); extern BOOLEAN _ReleaseSoundBankData (void *handle);
#define AllocMusicData(s) AllocResourceData((s),MEM_ZEROINIT) #define AllocMusicData HMalloc
#define LockMusicData LockResourceData #define FreeMusicData HFree
#define UnlockMusicData UnlockResourceData
#define FreeMusicData _ReleaseMusicData
extern char* CheckMusicResName (char* filename); extern char* CheckMusicResName (char* filename);
-3
View File
@@ -38,9 +38,6 @@ typedef struct
void *data; // user-defined data void *data; // user-defined data
} TFB_SoundTag; } TFB_SoundTag;
// forward-declare
typedef struct tfb_soundsample TFB_SoundSample;
typedef struct tfb_soundcallbacks typedef struct tfb_soundcallbacks
{ {
// return TRUE to continue, FALSE to abort // return TRUE to continue, FALSE to abort
+18 -24
View File
@@ -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) _GetStringData (uio_Stream *fp, DWORD length)
{ {
MEM_HANDLE hData; void *result;
{ {
char *s; char *s;
@@ -255,7 +255,7 @@ _GetStringData (uio_Stream *fp, DWORD length)
if (timestamp_fp) if (timestamp_fp)
uio_fclose (timestamp_fp); uio_fclose (timestamp_fp);
hData = 0; result = NULL;
num_data_sets = (ClipOffs ? 1 : 0) + (TSOffs ? 1 : 0) + 1; num_data_sets = (ClipOffs ? 1 : 0) + (TSOffs ? 1 : 0) + 1;
if (++n) if (++n)
{ {
@@ -264,13 +264,13 @@ _GetStringData (uio_Stream *fp, DWORD length)
flags |= HAS_SOUND_CLIPS; flags |= HAS_SOUND_CLIPS;
if (TSOffs) if (TSOffs)
flags |= HAS_TIMESTAMP; flags |= HAS_TIMESTAMP;
hData = AllocStringTable (n, flags); result = AllocStringTable (n, flags);
if (hData) if (result)
{ {
int StringIndex, ClipIndex, TSIndex; int StringIndex, ClipIndex, TSIndex;
STRING_TABLE_DESC *lpST; STRING_TABLE_DESC *lpST;
LockStringTable (hData, &lpST); lpST = (STRING_TABLE) result;
StringIndex = 0; StringIndex = 0;
ClipIndex = n; ClipIndex = n;
@@ -294,8 +294,6 @@ _GetStringData (uio_Stream *fp, DWORD length)
TSOffs += tslen[n]; TSOffs += tslen[n];
} }
} }
UnlockStringTable (hData);
} }
} }
HFree (strdata); HFree (strdata);
@@ -303,46 +301,42 @@ _GetStringData (uio_Stream *fp, DWORD length)
if (ts_data) if (ts_data)
HFree (ts_data); HFree (ts_data);
return (hData); return (result);
} }
} }
/* We don't end in .txt, so, we're a color table of some kind. */ /* We don't end in .txt, so, we're a color table of some kind. */
hData = GetResourceData (fp, length, MEM_SOUND); result = GetResourceData (fp, length);
if (hData) if (result)
{ {
DWORD *fileData; DWORD *fileData;
MEM_HANDLE hStrTab; STRING_TABLE lpST;
fileData = mem_lock (hData); fileData = (DWORD *)result;
dword_convert (fileData, 1); /* Length */ dword_convert (fileData, 1); /* Length */
hStrTab = AllocStringTable (fileData[0], 0); lpST = AllocStringTable (fileData[0], 0);
if (hStrTab) if (lpST)
{ {
STRING_TABLE_DESC *lpST;
int i, size; int i, size;
BYTE *stringptr; BYTE *stringptr;
LockStringTable (hStrTab, &lpST);
size = lpST->size; size = lpST->size;
dword_convert (fileData+2, size); dword_convert (fileData+1, size + 1);
stringptr = (BYTE *)(fileData + 2 + size); stringptr = (BYTE *)(fileData + 2 + size + fileData[1]);
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
set_strtab_entry (lpST, i, stringptr, fileData[2+i]); set_strtab_entry (lpST, i, stringptr, fileData[2+i]);
stringptr += fileData[2+i]; stringptr += fileData[2+i];
} }
UnlockStringTable (hStrTab);
} }
mem_unlock (hData); HFree (result);
mem_release (hData); result = lpST;
hData = hStrTab;
} }
return (hData); return (result);
} }
+3 -3
View File
@@ -35,14 +35,14 @@ LoadStringTableFile (uio_DirHandle *dir, const char *fileName)
fp = res_OpenResFile (dir, fileName, "rb"); fp = res_OpenResFile (dir, fileName, "rb");
if (fp) if (fp)
{ {
MEM_HANDLE hData; STRING_TABLE data;
_cur_resfile_name = fileName; _cur_resfile_name = fileName;
hData = _GetStringData (fp, LengthResFile (fp)); data = (STRING_TABLE) _GetStringData (fp, LengthResFile (fp));
_cur_resfile_name = 0; _cur_resfile_name = 0;
res_CloseResFile (fp); res_CloseResFile (fp);
return hData; return data;
} }
return (0); return (0);
+4 -4
View File
@@ -28,14 +28,14 @@ InstallStringTableResType (COUNT string_type)
STRING_TABLE STRING_TABLE
LoadStringTableInstance (DWORD res) LoadStringTableInstance (DWORD res)
{ {
MEM_HANDLE hData; void *data;
hData = res_GetResource (res); data = res_GetResource (res);
if (hData) if (data)
{ {
res_DetachResource (res); res_DetachResource (res);
} }
return hData; return (STRING_TABLE)data;
} }
+12 -31
View File
@@ -22,8 +22,7 @@
STRING_TABLE STRING_TABLE
AllocStringTable (int num_entries, int flags) AllocStringTable (int num_entries, int flags)
{ {
MEM_HANDLE hData = mem_allocate (sizeof (STRING_TABLE_DESC), MEM_SOUND); STRING_TABLE strtab = HMalloc (sizeof (STRING_TABLE_DESC));
STRING_TABLE_DESC *strtab = mem_lock (hData);
int i, multiplier = 1; int i, multiplier = 1;
if (flags & HAS_SOUND_CLIPS) if (flags & HAS_SOUND_CLIPS)
@@ -34,7 +33,6 @@ AllocStringTable (int num_entries, int flags)
{ {
multiplier++; multiplier++;
} }
strtab->handle = hData;
strtab->flags = flags; strtab->flags = flags;
strtab->size = num_entries; strtab->size = num_entries;
num_entries *= multiplier; num_entries *= multiplier;
@@ -46,17 +44,14 @@ AllocStringTable (int num_entries, int flags)
strtab->strings[i].parent = strtab; strtab->strings[i].parent = strtab;
strtab->strings[i].index = i; strtab->strings[i].index = i;
} }
return hData; return strtab;
} }
void void
FreeStringTable (STRING_TABLE StringTable) FreeStringTable (STRING_TABLE strtab)
{ {
STRING_TABLE_DESC *strtab;
int i, multiplier = 1; int i, multiplier = 1;
strtab = mem_lock (StringTable);
if (strtab == NULL) if (strtab == NULL)
{ {
return; return;
@@ -80,8 +75,7 @@ FreeStringTable (STRING_TABLE StringTable)
} }
HFree (strtab->strings); HFree (strtab->strings);
mem_unlock (StringTable); HFree (strtab);
mem_release (StringTable);
} }
BOOLEAN BOOLEAN
@@ -94,20 +88,9 @@ DestroyStringTable (STRING_TABLE StringTable)
STRING STRING
CaptureStringTable (STRING_TABLE StringTable) CaptureStringTable (STRING_TABLE StringTable)
{ {
if (StringTable != 0) if ((StringTable != 0) && (StringTable->size > 0))
{ {
STRING_TABLE_DESC *StringTablePtr; return StringTable->strings;
LockStringTable (StringTable, &StringTablePtr);
if (StringTablePtr->size > 0)
{
return StringTablePtr->strings;
}
else
{
UnlockStringTable (StringTable);
return NULL;
}
} }
return NULL; return NULL;
@@ -119,8 +102,6 @@ ReleaseStringTable (STRING String)
STRING_TABLE StringTable; STRING_TABLE StringTable;
StringTable = GetStringTable (String); StringTable = GetStringTable (String);
if (StringTable != 0)
UnlockStringTable (StringTable);
return (StringTable); return (StringTable);
} }
@@ -130,9 +111,9 @@ GetStringTable (STRING String)
{ {
if (String && String->parent) if (String && String->parent)
{ {
return String->parent->handle; return String->parent;
} }
return NULL_HANDLE; return NULL;
} }
COUNT COUNT
@@ -158,7 +139,7 @@ GetStringTableIndex (STRING String)
STRING STRING
SetAbsStringTableIndex (STRING String, COUNT StringTableIndex) SetAbsStringTableIndex (STRING String, COUNT StringTableIndex)
{ {
STRING_TABLE_DESC *StringTablePtr; STRING_TABLE StringTablePtr;
if (!String) if (!String)
return NULL; return NULL;
@@ -181,7 +162,7 @@ SetAbsStringTableIndex (STRING String, COUNT StringTableIndex)
STRING STRING
SetRelStringTableIndex (STRING String, SIZE StringTableOffs) SetRelStringTableIndex (STRING String, SIZE StringTableOffs)
{ {
STRING_TABLE_DESC *StringTablePtr; STRING_TABLE StringTablePtr;
if (!String) if (!String)
return NULL; return NULL;
@@ -230,7 +211,7 @@ GetStringLengthBin (STRING String)
STRINGPTR STRINGPTR
GetStringSoundClip (STRING String) GetStringSoundClip (STRING String)
{ {
STRING_TABLE_DESC *StringTablePtr; STRING_TABLE StringTablePtr;
COUNT StringIndex; COUNT StringIndex;
if (String == NULL) if (String == NULL)
@@ -263,7 +244,7 @@ GetStringSoundClip (STRING String)
STRINGPTR STRINGPTR
GetStringTimeStamp (STRING String) GetStringTimeStamp (STRING String)
{ {
STRING_TABLE_DESC *StringTablePtr; STRING_TABLE StringTablePtr;
COUNT StringIndex; COUNT StringIndex;
int offset; int offset;
+3 -9
View File
@@ -22,7 +22,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "strlib.h" #include "strlib.h"
#include "memlib.h"
#include "reslib.h" #include "reslib.h"
struct string_table_entry struct string_table_entry
@@ -33,25 +32,20 @@ struct string_table_entry
struct string_table *parent; struct string_table *parent;
}; };
typedef struct string_table struct string_table
{ {
MEM_HANDLE handle;
unsigned short flags; unsigned short flags;
int size; int size;
STRING_TABLE_ENTRY_DESC *strings; STRING_TABLE_ENTRY_DESC *strings;
} STRING_TABLE_DESC; };
typedef STRING_TABLE_DESC *PSTRING_TABLE_DESC;
#define HAS_SOUND_CLIPS (1 << 0) #define HAS_SOUND_CLIPS (1 << 0)
#define HAS_TIMESTAMP (1 << 1) #define HAS_TIMESTAMP (1 << 1)
#define LockStringTable LockResourceData
#define UnlockStringTable UnlockResourceData
STRING_TABLE AllocStringTable (int num_entries, int flags); STRING_TABLE AllocStringTable (int num_entries, int flags);
void FreeStringTable (STRING_TABLE strtab); void FreeStringTable (STRING_TABLE strtab);
MEM_HANDLE _GetStringData (uio_Stream *fp, DWORD length); void *_GetStringData (uio_Stream *fp, DWORD length);
#endif /* _STRINTRN_H */ #endif /* _STRINTRN_H */
+2 -2
View File
@@ -21,14 +21,14 @@
#include "compiler.h" #include "compiler.h"
#include "port.h" #include "port.h"
#include "libs/memlib.h"
#include "libs/uio.h" #include "libs/uio.h"
#include <stddef.h> #include <stddef.h>
typedef struct string_table_entry STRING_TABLE_ENTRY_DESC; 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 STRING_TABLE_ENTRY_DESC *STRING;
typedef BYTE *STRINGPTR; typedef BYTE *STRINGPTR;
+1 -2
View File
@@ -346,12 +346,11 @@ TFB_PlayVideo (VIDEO_REF VidRef, uint32 x, uint32 y)
} }
// nasty hack for now // nasty hack for now
LockMusicData (vid->hAudio, &pmus); pmus = vid->hAudio;
(*pmus)->buffer_tag = HCalloc ( (*pmus)->buffer_tag = HCalloc (
sizeof (TFB_SoundTag) * (*pmus)->num_buffers); sizeof (TFB_SoundTag) * (*pmus)->num_buffers);
(*pmus)->callbacks = vp_AudioCBs; (*pmus)->callbacks = vp_AudioCBs;
(*pmus)->data = vid; // hijack data ;) (*pmus)->data = vid; // hijack data ;)
UnlockMusicData (vid->hAudio);
} }
SetSemaphore (vp_interthread_lock); SetSemaphore (vp_interthread_lock);
+1 -2
View File
@@ -26,11 +26,10 @@
RACE_DESC * RACE_DESC *
load_ship (DWORD RaceResIndex, BOOLEAN LoadBattleData) load_ship (DWORD RaceResIndex, BOOLEAN LoadBattleData)
{ {
MEM_HANDLE h; RESOURCE_INDEX h, hOldIndex;
RACE_DESC *RDPtr = 0; RACE_DESC *RDPtr = 0;
#define INITIAL_CODE_RES MAKE_RESOURCE (1, CODE, 0) #define INITIAL_CODE_RES MAKE_RESOURCE (1, CODE, 0)
void *CodeRef; void *CodeRef;
MEM_HANDLE hOldIndex;
h = OpenResourceIndexInstance (RaceResIndex); h = OpenResourceIndexInstance (RaceResIndex);
if (!h) if (!h)
+2 -2
View File
@@ -22,8 +22,8 @@
#include "restypes.h" #include "restypes.h"
#define LoadCodeRes LoadCodeResInstance #define LoadCodeRes LoadCodeResInstance
#define LoadGraphic LoadGraphicInstance #define LoadGraphic (DRAWABLE)LoadGraphicInstance
#define LoadFont LoadGraphicInstance #define LoadFont (FONT)LoadGraphicInstance
#define LoadColorMap LoadColorMapInstance #define LoadColorMap LoadColorMapInstance
#define LoadStringTable LoadStringTableInstance #define LoadStringTable LoadStringTableInstance
#define LoadSound LoadSoundInstance #define LoadSound LoadSoundInstance
+1 -1
View File
@@ -451,7 +451,7 @@ DrawArmadaPickShip (BOOLEAN draw_salvage_frame, RECT *pPickRect)
STAMP s; STAMP s;
TEXT t; TEXT t;
CONTEXT OldContext; CONTEXT OldContext;
MEM_HANDLE hLastIndex; RESOURCE_INDEX hLastIndex;
FRAME PickFrame; FRAME PickFrame;
hLastIndex = SetResourceIndex (hResIndex); hLastIndex = SetResourceIndex (hResIndex);
+3 -3
View File
@@ -533,7 +533,7 @@ static void
CheckObjectCollision (COUNT index) CheckObjectCollision (COUNT index)
{ {
INTERSECT_CONTROL LanderControl; INTERSECT_CONTROL LanderControl;
MEM_HANDLE LanderHandle; DRAWABLE LanderHandle;
PRIMITIVE *pPrim; PRIMITIVE *pPrim;
PRIMITIVE *pLanderPrim; PRIMITIVE *pLanderPrim;
PLANETSIDE_DESC *pPSD; PLANETSIDE_DESC *pPSD;
@@ -555,7 +555,7 @@ CheckObjectCollision (COUNT index)
pPSD = (PLANETSIDE_DESC*)pMenuState->ModuleFrame; pPSD = (PLANETSIDE_DESC*)pMenuState->ModuleFrame;
LanderControl.EndPoint = LanderControl.IntersectStamp.origin; LanderControl.EndPoint = LanderControl.IntersectStamp.origin;
LanderHandle = GetFrameHandle (LanderControl.IntersectStamp.frame); LanderHandle = GetFrameParentDrawable (LanderControl.IntersectStamp.frame);
for (; index != END_OF_LIST; index = GetPredLink (GetPrimLinks (pPrim))) for (; index != END_OF_LIST; index = GetPredLink (GetPrimLinks (pPrim)))
{ {
@@ -566,7 +566,7 @@ CheckObjectCollision (COUNT index)
ElementControl.IntersectStamp = pPrim->Object.Stamp; ElementControl.IntersectStamp = pPrim->Object.Stamp;
ElementControl.EndPoint = ElementControl.IntersectStamp.origin; ElementControl.EndPoint = ElementControl.IntersectStamp.origin;
if (GetFrameHandle (ElementControl.IntersectStamp.frame) if (GetFrameParentDrawable (ElementControl.IntersectStamp.frame)
== LanderHandle) == LanderHandle)
{ {
CheckObjectCollision (index); CheckObjectCollision (index);
+4 -4
View File
@@ -279,7 +279,7 @@ FreePlanet (void)
void void
LoadStdLanderFont (PLANET_INFO *info) LoadStdLanderFont (PLANET_INFO *info)
{ {
info->LanderFont = CaptureFont (LoadFont (LANDER_FONT)); info->LanderFont = LoadFont (LANDER_FONT);
info->LanderFontEff = CaptureDrawable ( info->LanderFontEff = CaptureDrawable (
LoadGraphic (LANDER_FONTEFF_PMAP_ANIM)); LoadGraphic (LANDER_FONTEFF_PMAP_ANIM));
} }
@@ -287,8 +287,8 @@ LoadStdLanderFont (PLANET_INFO *info)
void void
FreeLanderFont (PLANET_INFO *info) FreeLanderFont (PLANET_INFO *info)
{ {
DestroyFont (ReleaseFont (info->LanderFont)); DestroyFont (info->LanderFont);
info->LanderFont = 0; info->LanderFont = NULL;
DestroyDrawable (ReleaseDrawable (info->LanderFontEff)); DestroyDrawable (ReleaseDrawable (info->LanderFontEff));
info->LanderFontEff = 0; info->LanderFontEff = NULL;
} }
+4 -4
View File
@@ -46,7 +46,7 @@ ACTIVITY LastActivity;
BYTE PlayerControl[NUM_PLAYERS]; BYTE PlayerControl[NUM_PLAYERS];
// XXX: These declarations should really go to the file they belong to. // XXX: These declarations should really go to the file they belong to.
MEM_HANDLE hResIndex; RESOURCE_INDEX hResIndex;
CONTEXT ScreenContext; CONTEXT ScreenContext;
CONTEXT SpaceContext; CONTEXT SpaceContext;
CONTEXT StatusContext; CONTEXT StatusContext;
@@ -184,11 +184,11 @@ InitKernel (void)
for (counter = 0; counter < NUM_PLAYERS; ++counter) for (counter = 0; counter < NUM_PLAYERS; ++counter)
InitQueue (&race_q[counter], MAX_SHIPS_PER_SIDE, sizeof (STARSHIP)); InitQueue (&race_q[counter], MAX_SHIPS_PER_SIDE, sizeof (STARSHIP));
StarConFont = CaptureFont (LoadFont (STARCON_FONT)); StarConFont = LoadFont (STARCON_FONT);
if (StarConFont == NULL) if (StarConFont == NULL)
return FALSE; return FALSE;
TinyFont = CaptureFont (LoadFont (TINY_FONT)); TinyFont = LoadFont (TINY_FONT);
if (TinyFont == NULL) if (TinyFont == NULL)
return FALSE; return FALSE;
@@ -204,7 +204,7 @@ InitKernel (void)
if (GameStrings == 0) if (GameStrings == 0)
return FALSE; return FALSE;
MicroFont = CaptureFont (LoadFont (MICRO_FONT)); MicroFont = LoadFont (MICRO_FONT);
if (MicroFont == NULL) if (MicroFont == NULL)
return FALSE; return FALSE;
+2 -2
View File
@@ -19,12 +19,12 @@
#include "displist.h" #include "displist.h"
#include "globdata.h" #include "globdata.h"
#include "libs/reslib.h"
#include "libs/sndlib.h" #include "libs/sndlib.h"
#include "libs/gfxlib.h" #include "libs/gfxlib.h"
#include "libs/threadlib.h" #include "libs/threadlib.h"
extern RESOURCE_INDEX hResIndex;
extern MEM_HANDLE hResIndex;
extern FRAME Screen; extern FRAME Screen;
extern FRAME ActivityFrame; extern FRAME ActivityFrame;
+1 -1
View File
@@ -94,7 +94,7 @@ static RACE_DESC androsynth_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -95,7 +95,7 @@ static RACE_DESC arilou_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -97,7 +97,7 @@ static RACE_DESC black_urquan_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -100,7 +100,7 @@ static RACE_DESC chenjesu_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -97,7 +97,7 @@ static RACE_DESC chmmr_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -93,7 +93,7 @@ static RACE_DESC druuge_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -97,7 +97,7 @@ static RACE_DESC human_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -95,7 +95,7 @@ static RACE_DESC ilwrath_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -100,7 +100,7 @@ static RACE_DESC samatra_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -96,7 +96,7 @@ static RACE_DESC melnorme_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -108,7 +108,7 @@ static RACE_DESC mmrnmhrm_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -96,7 +96,7 @@ static RACE_DESC mycon_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -98,7 +98,7 @@ static RACE_DESC orz_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -96,7 +96,7 @@ static RACE_DESC pkunk_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -90,7 +90,7 @@ static RACE_DESC probe_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -96,7 +96,7 @@ static RACE_DESC shofixti_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -102,7 +102,7 @@ static RACE_DESC sis_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -95,7 +95,7 @@ static RACE_DESC slylandro_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,
+1 -1
View File
@@ -93,7 +93,7 @@ static RACE_DESC spathi_desc =
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
{ NULL, NULL, NULL }, { NULL, NULL, NULL },
NULL_HANDLE, NULL NULL, NULL
}, },
{ {
0, 0,

Some files were not shown because too many files have changed in this diff Show More