* remove unused function pointer fileLoad from struct RES_TYPE in lib/framework/frameresource.h (there is code that sets this member, but none that uses it)

* remove function resAddFileLoad from lib/framework/frameresource.[ch] which was used to set RES_TYPE.fileLoad
 * remove only call to resAddFileLoad from src/data.c, function dataInitLoadFuncs
 * remove now completely unused function dataSaveGameLoad from src/data.c
 * modify function dataInitLoadFuncs in src/data.c:
  * modify the struct definition for the list of resource types
  * modify the list accordingly
  * remove the NULL-item from the end of the list
  * modify list iteration code to use a start and end iterator (end being a pointer just past the last valid list-item, begin being the first valid one)

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1394 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2007-04-08 17:15:56 +00:00
parent 0af269415c
commit 10964ceca2
3 changed files with 62 additions and 141 deletions

View File

@ -144,7 +144,7 @@ BOOL resLoad(const char *pResFile, SDWORD blockID,
/* Allocate a RES_TYPE structure */
static BOOL resAlloc(const char *pType, RES_TYPE **ppsFunc)
static RES_TYPE* resAlloc(const char *pType)
{
RES_TYPE *psT;
@ -163,7 +163,7 @@ static BOOL resAlloc(const char *pType, RES_TYPE **ppsFunc)
{
debug( LOG_ERROR, "resAlloc: Out of memory" );
abort();
return FALSE;
return NULL;
}
// setup the structure
@ -174,9 +174,7 @@ static BOOL resAlloc(const char *pType, RES_TYPE **ppsFunc)
psT->psRes = NULL;
*ppsFunc = psT;
return TRUE;
return psT;
}
@ -185,15 +183,14 @@ static BOOL resAlloc(const char *pType, RES_TYPE **ppsFunc)
BOOL resAddBufferLoad(const char *pType, RES_BUFFERLOAD buffLoad,
RES_FREE release)
{
RES_TYPE *psT;
RES_TYPE *psT = resAlloc(pType);
if (!resAlloc(pType, &psT))
if (!psT)
{
return FALSE;
}
psT->buffLoad = buffLoad;
psT->fileLoad = NULL;
psT->release = release;
psT->psNext = psResTypes;
@ -202,30 +199,6 @@ BOOL resAddBufferLoad(const char *pType, RES_BUFFERLOAD buffLoad,
return TRUE;
}
/* Add a file name load function for a file type */
BOOL resAddFileLoad(const char *pType, RES_FILELOAD fileLoad,
RES_FREE release)
{
RES_TYPE *psT;
if (!resAlloc(pType, &psT))
{
return FALSE;
}
psT->buffLoad = NULL;
psT->fileLoad = fileLoad;
psT->release = release;
psT->psNext = psResTypes;
psResTypes = psT;
return TRUE;
}
// Make a string lower case
void resToLower(char *pStr)
{
@ -519,7 +492,7 @@ void *resGetDataFromHash(const char *pType, UDWORD HashedID)
if (psRes == NULL)
{
ASSERT( FALSE, "resGetDataFromHash: Unknown ID:" );
ASSERT( psRes != NULL, "resGetDataFromHash: Unknown ID:" );
return NULL;
}

View File

@ -32,8 +32,6 @@
/* Function pointer for a function that loads from a memory buffer */
typedef BOOL (*RES_BUFFERLOAD)(char *pBuffer, UDWORD size, void **pData);
/* Function pointer for a function that loads from a filename */
typedef BOOL (*RES_FILELOAD)(char *pFile, void **pData);
/* Function pointer for releasing a resource loaded by the above functions */
typedef void (*RES_FREE)(void *pData);
@ -68,7 +66,6 @@ typedef struct _res_type
RES_DATA *psRes; // Linked list of data items of this type
UDWORD HashedType; // hashed version of the name of the id - // a null hashedtype indicates end of list
RES_FILELOAD fileLoad; // This isn't really used any more ?
struct _res_type *psNext;
} RES_TYPE;
@ -111,10 +108,6 @@ extern void resReleaseAllData(void);
extern BOOL resAddBufferLoad(const char *pType, RES_BUFFERLOAD buffLoad,
RES_FREE release);
/* Add a file name load and release function for a file type */
extern BOOL resAddFileLoad(const char *pType, RES_FILELOAD fileLoad,
RES_FREE release);
/* Call the load function for a file */
extern BOOL resLoadFile(char *pType, char *pFile);

View File

@ -1132,130 +1132,85 @@ static BOOL dataScriptLoadVals(char *pBuffer, UDWORD size, void **ppData)
return TRUE;
}
static BOOL dataSaveGameLoad(char *pFile, void **ppData)
{
if (!stageTwoInitialise())
{
return FALSE;
}
if (!loadGameInit(pFile))
{
return FALSE;
}
if (!loadGame(pFile, !KEEPOBJECTS, FREEMEM,TRUE))
{
return FALSE;
}
if (!newMapInitialise())
{
return FALSE;
}
//not interested in this value
*ppData = NULL;
return TRUE;
}
// New reduced resource type ... specially for PSX
// These are statically defined in data.c
// this is also defined in frameresource.c - needs moving to a .h file
// This basically matches the argument list of resAddBufferLoad in frameresource.c
typedef struct
{
const char *aType; // points to the string defining the type (e.g. SCRIPT) - NULL indicates end of list
RES_BUFFERLOAD buffLoad; // routine to process the data for this type
RES_FREE release; // routine to release the data (NULL indicates none)
void *ResourceData; // Linked list of data - set to null initially
UDWORD HashedType; // hashed version of aType
const char *aType; // points to the string defining the type (e.g. SCRIPT) - NULL indicates end of list
RES_BUFFERLOAD buffLoad; // routine to process the data for this type
RES_FREE release; // routine to release the data (NULL indicates none)
} RES_TYPE_MIN;
static RES_TYPE_MIN ResourceTypes[]=
static const RES_TYPE_MIN ResourceTypes[] =
{
{"SWEAPON", bufferSWEAPONLoad, NULL, NULL, 0},
{"SBODY", bufferSBODYLoad, dataReleaseStats, NULL, 0},
{"SBRAIN", bufferSBRAINLoad, NULL, NULL, 0},
{"SPROP", bufferSPROPLoad, NULL, NULL, 0},
{"SSENSOR", bufferSSENSORLoad, NULL, NULL, 0},
{"SECM", bufferSECMLoad, NULL, NULL, 0},
{"SREPAIR", bufferSREPAIRLoad, NULL, NULL, 0},
{"SCONSTR", bufferSCONSTRLoad, NULL, NULL, 0},
{"SPROPTYPES", bufferSPROPTYPESLoad, NULL, NULL, 0},
{"SPROPSND", bufferSPROPSNDLoad, NULL, NULL, 0},
{"STERRTABLE", bufferSTERRTABLELoad, NULL, NULL, 0},
{"SSPECABIL", bufferSSPECABILLoad, NULL, NULL, 0},
{"SBPIMD", bufferSBPIMDLoad, NULL, NULL, 0},
{"SWEAPSND", bufferSWEAPSNDLoad, NULL, NULL, 0},
{"SWEAPMOD", bufferSWEAPMODLoad, NULL, NULL, 0},
{"STEMPL", bufferSTEMPLLoad, dataSTEMPLRelease, NULL, 0}, //template and associated files
{"STEMPWEAP", bufferSTEMPWEAPLoad, NULL, NULL, 0},
{"SSTRUCT", bufferSSTRUCTLoad, dataSSTRUCTRelease, NULL, 0}, //structure stats and associated files
{"SSTRFUNC", bufferSSTRFUNCLoad, NULL, NULL, 0},
{"SSTRWEAP", bufferSSTRWEAPLoad, NULL, NULL, 0},
{"SSTRMOD", bufferSSTRMODLoad, NULL, NULL, 0},
{"SFEAT", bufferSFEATLoad, dataSFEATRelease, NULL, 0}, //feature stats file
{"SFUNC", bufferSFUNCLoad, dataSFUNCRelease, NULL, 0}, //function stats file
{"RESCH", bufferRESCHLoad, dataRESCHRelease, NULL, 0}, //research stats files
{"RPREREQ", bufferRPREREQLoad, NULL, NULL, 0},
{"RCOMPRED", bufferRCOMPREDLoad, NULL, NULL, 0},
{"RCOMPRES", bufferRCOMPRESLoad, NULL, NULL, 0},
{"RSTRREQ", bufferRSTRREQLoad, NULL, NULL, 0},
{"RSTRRED", bufferRSTRREDLoad, NULL, NULL, 0},
{"RSTRRES", bufferRSTRRESLoad, NULL, NULL, 0},
{"RFUNC", bufferRFUNCLoad, NULL, NULL, 0},
{"SMSG", bufferSMSGLoad, dataSMSGRelease, NULL, 0},
{"SCRIPT", dataScriptLoad, (RES_FREE)scriptFreeCode, NULL, 0},
{"SCRIPTVAL", dataScriptLoadVals, NULL, NULL, 0},
{"STR_RES", dataStrResLoad, dataStrResRelease, NULL, 0},
{"IMGPAGE", dataIMGPAGELoad, dataIMGPAGERelease, NULL, 0},
{"TERTILES", NULL, NULL, NULL, 0}, // This version was used when running with the software renderer.
{"HWTERTILES", dataHWTERTILESLoad, dataHWTERTILESRelease, NULL, 0}, // freed by 3d shutdow},// Tertiles Files. This version used when running with hardware renderer.
{"AUDIOCFG", dataAudioCfgLoad, NULL, NULL, 0},
{"WAV", dataAudioLoad, dataAudioRelease, NULL, 0},
{"ANI", dataAnimLoad, dataAnimRelease, NULL, 0},
{"ANIMCFG", dataAnimCfgLoad, NULL, NULL, 0},
{"IMG", dataIMGLoad, dataIMGRelease, NULL, 0},
{"TEXPAGE", bufferTexPageLoad, dataTexPageRelease, NULL, 0},
{"IMD", dataIMDBufferLoad, (RES_FREE)iV_IMDRelease, NULL, 0},
{NULL,NULL,NULL, NULL, 0} // indicates end of list
{"SWEAPON", bufferSWEAPONLoad, NULL},
{"SBODY", bufferSBODYLoad, dataReleaseStats},
{"SBRAIN", bufferSBRAINLoad, NULL},
{"SPROP", bufferSPROPLoad, NULL},
{"SSENSOR", bufferSSENSORLoad, NULL},
{"SECM", bufferSECMLoad, NULL},
{"SREPAIR", bufferSREPAIRLoad, NULL},
{"SCONSTR", bufferSCONSTRLoad, NULL},
{"SPROPTYPES", bufferSPROPTYPESLoad, NULL},
{"SPROPSND", bufferSPROPSNDLoad, NULL},
{"STERRTABLE", bufferSTERRTABLELoad, NULL},
{"SSPECABIL", bufferSSPECABILLoad, NULL},
{"SBPIMD", bufferSBPIMDLoad, NULL},
{"SWEAPSND", bufferSWEAPSNDLoad, NULL},
{"SWEAPMOD", bufferSWEAPMODLoad, NULL},
{"STEMPL", bufferSTEMPLLoad, dataSTEMPLRelease}, //template and associated files
{"STEMPWEAP", bufferSTEMPWEAPLoad, NULL},
{"SSTRUCT", bufferSSTRUCTLoad, dataSSTRUCTRelease}, //structure stats and associated files
{"SSTRFUNC", bufferSSTRFUNCLoad, NULL},
{"SSTRWEAP", bufferSSTRWEAPLoad, NULL},
{"SSTRMOD", bufferSSTRMODLoad, NULL},
{"SFEAT", bufferSFEATLoad, dataSFEATRelease}, //feature stats file
{"SFUNC", bufferSFUNCLoad, dataSFUNCRelease}, //function stats file
{"RESCH", bufferRESCHLoad, dataRESCHRelease}, //research stats files
{"RPREREQ", bufferRPREREQLoad, NULL},
{"RCOMPRED", bufferRCOMPREDLoad, NULL},
{"RCOMPRES", bufferRCOMPRESLoad, NULL},
{"RSTRREQ", bufferRSTRREQLoad, NULL},
{"RSTRRED", bufferRSTRREDLoad, NULL},
{"RSTRRES", bufferRSTRRESLoad, NULL},
{"RFUNC", bufferRFUNCLoad, NULL},
{"SMSG", bufferSMSGLoad, dataSMSGRelease},
{"SCRIPT", dataScriptLoad, (RES_FREE)scriptFreeCode},
{"SCRIPTVAL", dataScriptLoadVals, NULL},
{"STR_RES", dataStrResLoad, dataStrResRelease},
{"IMGPAGE", dataIMGPAGELoad, dataIMGPAGERelease},
{"TERTILES", NULL, NULL}, // This version was used when running with the software renderer.
{"HWTERTILES", dataHWTERTILESLoad, dataHWTERTILESRelease}, // freed by 3d shutdow},// Tertiles Files. This version used when running with hardware renderer.
{"AUDIOCFG", dataAudioCfgLoad, NULL},
{"WAV", dataAudioLoad, dataAudioRelease},
{"ANI", dataAnimLoad, dataAnimRelease},
{"ANIMCFG", dataAnimCfgLoad, NULL},
{"IMG", dataIMGLoad, dataIMGRelease},
{"TEXPAGE", bufferTexPageLoad, dataTexPageRelease},
{"IMD", dataIMDBufferLoad, (RES_FREE)iV_IMDRelease},
};
/* Pass all the data loading functions to the framework library */
BOOL dataInitLoadFuncs(void)
{
RES_TYPE_MIN *CurrentType;
// UDWORD i;
const RES_TYPE_MIN *CurrentType;
// Points just past the last item in the list
const RES_TYPE_MIN *EndType = &ResourceTypes[sizeof(ResourceTypes) / sizeof(RES_TYPE_MIN)];
// init the cheat system;
resetCheatHash();
CurrentType=ResourceTypes; // point to the first entry
// While there are still some entries in the list
while( CurrentType->aType != NULL )
// Using iterator style: begin iterator (ResourceTypes),
// end iterator (EndType), and current iterator (CurrentType)
for (CurrentType = ResourceTypes; CurrentType != EndType; ++CurrentType)
{
// printf(" ==>%s\n",CurrentType->aType); //TESTING -Q
if(!resAddBufferLoad(CurrentType->aType,CurrentType->buffLoad,CurrentType->release))
{
return FALSE; // error whilst adding a buffer load
}
CurrentType++;
}
// Now add the only file load left!
if (!resAddFileLoad("SAVEGAME", dataSaveGameLoad, NULL))
{
return FALSE;
}
return TRUE;