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:
- 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
+3 -3
View File
@@ -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]);
+2 -2
View File
@@ -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;
}
+5 -6
View File
@@ -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;
+6 -7
View File
@@ -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
+1 -1
View File
@@ -223,7 +223,7 @@ static LOCDATA arilou_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -125,7 +125,7 @@ static LOCDATA blackurq_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -111,7 +111,7 @@ static LOCDATA chmmr_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -86,7 +86,7 @@ static LOCDATA commander_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -152,7 +152,7 @@ static LOCDATA druuge_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -95,7 +95,7 @@ static LOCDATA ilwrath_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -106,7 +106,7 @@ static LOCDATA melnorme_desc =
&melnorme_numbers_english, /* AlienNumberSpeech - default */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -104,7 +104,7 @@ static LOCDATA mycon_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -166,7 +166,7 @@ static LOCDATA orz_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -91,7 +91,7 @@ static LOCDATA pkunk_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -188,7 +188,7 @@ static LOCDATA yehat_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -152,7 +152,7 @@ static LOCDATA shofixti_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -166,7 +166,7 @@ static LOCDATA slylandro_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -113,7 +113,7 @@ static LOCDATA slylandro_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -179,7 +179,7 @@ static LOCDATA spahome_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -140,7 +140,7 @@ static LOCDATA spathi_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -154,7 +154,7 @@ static LOCDATA commander_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -96,7 +96,7 @@ static LOCDATA supox_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -186,7 +186,7 @@ static LOCDATA syreen_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -193,7 +193,7 @@ static LOCDATA talkpet_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -129,7 +129,7 @@ static LOCDATA thradd_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -191,7 +191,7 @@ static LOCDATA umgah_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -116,7 +116,7 @@ static LOCDATA urquan_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -193,7 +193,7 @@ static LOCDATA utwig_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -196,7 +196,7 @@ static LOCDATA vux_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -187,7 +187,7 @@ static LOCDATA yehat_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+1 -1
View File
@@ -105,7 +105,7 @@ static LOCDATA zoqfot_desc =
NULL, /* AlienNumberSpeech - none */
/* Filler for loaded resources */
NULL, NULL, NULL,
NULL_HANDLE,
NULL,
NULL,
};
+2 -2
View File
@@ -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;
}
}
+28 -33
View File
@@ -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;
}
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -142,7 +142,7 @@ LoadSC2Data (void)
{
if (FlagStatFrame == 0)
{
MEM_HANDLE hOldIndex;
RESOURCE_INDEX hOldIndex;
hOldIndex = SetResourceIndex (hResIndex);
+1 -1
View File
@@ -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);
+19 -3
View File
@@ -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;
}
}
+3 -3
View File
@@ -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);
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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);
+8 -12
View File
@@ -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);
+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
extern CONTEXT _pCurContext;
+7 -16
View File
@@ -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);
+2 -7
View File
@@ -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;
+9 -9
View File
@@ -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);
+4 -35
View File
@@ -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)
{
+3 -9
View File
@@ -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 */
+1 -1
View File
@@ -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 (
+14 -22
View File
@@ -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
+4 -3
View File
@@ -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);
}
+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));
}
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)
Drawable->Flags = flags;
Drawable->MaxIndex = NumFrames - 1;
imgw = width;
imgh = height;
FramePtr = &Drawable->Frame[NumFrames - 1];
while (NumFrames--)
{
FreeDrawable (Drawable);
Drawable = NULL_HANDLE;
}
else
{
int imgw, imgh;
FRAME FramePtr;
TFB_Image *Image;
DrawablePtr->hDrawable = Drawable;
DrawablePtr->Flags = flags;
DrawablePtr->MaxIndex = NumFrames - 1;
imgw = width;
imgh = height;
FramePtr = &DrawablePtr->Frame[NumFrames - 1];
while (NumFrames--)
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;
}
}
+1 -1
View File
@@ -19,8 +19,8 @@
#ifndef _INPLIB_H
#define _INPLIB_H
#include "memlib.h"
#include <stddef.h>
#include "compiler.h"
#include "libs/uio.h"
typedef DWORD INPUT_STATE;
+15 -24
View File
@@ -20,11 +20,13 @@
#define _RESLIB_H
//#include <stdio.h>
#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
+2 -3
View File
@@ -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;
}
+28 -28
View File
@@ -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;
}
+6 -16
View File
@@ -19,13 +19,14 @@
#ifndef _INDEX_H
#define _INDEX_H
#include "reslib.h"
#include <stdio.h>
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 */
+27 -39
View File
@@ -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;
}
+45 -73
View File
@@ -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);
}
+3 -3
View File
@@ -20,11 +20,11 @@
#define _RESINTRN_H
#include <string.h>
#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);
+2 -2
View File
@@ -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);
+7 -7
View File
@@ -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);
+14 -27
View File
@@ -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);
}
+4 -4
View File
@@ -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)
+7 -11
View File
@@ -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);
}
+6 -8
View File
@@ -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);
-3
View File
@@ -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
+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)
{
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);
}
+3 -3
View File
@@ -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);
+4 -4
View File
@@ -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;
}
+12 -31
View File
@@ -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;
+3 -9
View File
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <string.h>
#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 */
+2 -2
View File
@@ -21,14 +21,14 @@
#include "compiler.h"
#include "port.h"
#include "libs/memlib.h"
#include "libs/uio.h"
#include <stddef.h>
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;
+1 -2
View File
@@ -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);
+1 -2
View File
@@ -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)
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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);
+3 -3
View File
@@ -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);
+4 -4
View File
@@ -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;
}
+4 -4
View File
@@ -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;
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -94,7 +94,7 @@ static RACE_DESC androsynth_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -95,7 +95,7 @@ static RACE_DESC arilou_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
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_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -100,7 +100,7 @@ static RACE_DESC chenjesu_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -97,7 +97,7 @@ static RACE_DESC chmmr_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -93,7 +93,7 @@ static RACE_DESC druuge_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -97,7 +97,7 @@ static RACE_DESC human_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -95,7 +95,7 @@ static RACE_DESC ilwrath_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -100,7 +100,7 @@ static RACE_DESC samatra_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -96,7 +96,7 @@ static RACE_DESC melnorme_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -108,7 +108,7 @@ static RACE_DESC mmrnmhrm_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -96,7 +96,7 @@ static RACE_DESC mycon_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -98,7 +98,7 @@ static RACE_DESC orz_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -96,7 +96,7 @@ static RACE_DESC pkunk_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -90,7 +90,7 @@ static RACE_DESC probe_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -96,7 +96,7 @@ static RACE_DESC shofixti_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -102,7 +102,7 @@ static RACE_DESC sis_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -95,7 +95,7 @@ static RACE_DESC slylandro_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,
+1 -1
View File
@@ -93,7 +93,7 @@ static RACE_DESC spathi_desc =
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
NULL_HANDLE, NULL
NULL, NULL
},
{
0,

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