Misc fixes for ticket:2435 (cleanup, cosmetic) to reduce diffcount

master
Per Inge Mathisen 2011-01-09 14:46:18 +01:00
parent b4c9ca5f10
commit 9e9fc1ba5b
8 changed files with 19 additions and 77 deletions

View File

@ -316,7 +316,7 @@ void frameShutDown(void)
PHYSFS_file* openLoadFile(const char* fileName, bool hard_fail) PHYSFS_file* openLoadFile(const char* fileName, bool hard_fail)
{ {
PHYSFS_file* fileHandle = PHYSFS_openRead(fileName); PHYSFS_file* fileHandle = PHYSFS_openRead(fileName);
debug(LOG_WZ, "Reading...[directory: %s] %s", PHYSFS_getRealDir(fileName), fileName); debug(LOG_NEVER, "Reading...[directory: %s] %s", PHYSFS_getRealDir(fileName), fileName);
if (!fileHandle) if (!fileHandle)
{ {
if (hard_fail) if (hard_fail)

View File

@ -88,6 +88,12 @@ void resShutDown(void)
} }
} }
// force set the base resource directory
void resForceBaseDir(const char* pResDir)
{
sstrcpy(aResDir, pResDir);
sstrcpy(aCurrResDir, pResDir);
}
// set the base resource directory // set the base resource directory
void resSetBaseDir(const char* pResDir) void resSetBaseDir(const char* pResDir)
@ -465,7 +471,7 @@ bool resLoadFile(const char *pType, const char *pFile)
// Now process the buffer data // Now process the buffer data
if (!psT->buffLoad(Resource->pBuffer, Resource->size, &pData)) if (!psT->buffLoad(Resource->pBuffer, Resource->size, &pData))
{ {
debug(LOG_ERROR, "resLoadFile: The load function for resource type \"%s\" failed for file \"%s\"", pType, pFile); ASSERT(false, "The load function for resource type \"%s\" failed for file \"%s\"", pType, pFile);
FreeResourceFile(Resource); FreeResourceFile(Resource);
if (psT->release != NULL) if (psT->release != NULL)
{ {
@ -481,7 +487,7 @@ bool resLoadFile(const char *pType, const char *pFile)
// Process data directly from file // Process data directly from file
if (!psT->fileLoad(aFileName, &pData)) if (!psT->fileLoad(aFileName, &pData))
{ {
debug(LOG_ERROR, "resLoadFile: The load function for resource type \"%s\" failed for file \"%s\"", pType, pFile); ASSERT(false, "The load function for resource type \"%s\" failed for file \"%s\"", pType, pFile);
if (psT->release != NULL) if (psT->release != NULL)
{ {
psT->release(pData); psT->release(pData);
@ -491,7 +497,7 @@ bool resLoadFile(const char *pType, const char *pFile)
} }
else else
{ {
debug(LOG_ERROR, "resLoadFile: No load functions for this type (%s)", pType); ASSERT(false, "No load functions for this type (%s)", pType);
return false; return false;
} }
@ -778,10 +784,6 @@ void resReleaseBlockData(SDWORD blockID)
{ {
psT->release( psRes->pData ); psT->release( psRes->pData );
} }
else
{
ASSERT( false,"resReleaseAllData: NULL release function" );
}
psNRes = psRes->psNext; psNRes = psRes->psNext;
free(psRes); free(psRes);

View File

@ -88,6 +88,7 @@ extern void resShutDown(void);
/** Set the base resource directory. */ /** Set the base resource directory. */
extern void resSetBaseDir(const char* pResDir); extern void resSetBaseDir(const char* pResDir);
extern void resForceBaseDir(const char* pResDir);
/** Parse the res file. */ /** Parse the res file. */
bool resLoad(const char *pResFile, SDWORD blockID); bool resLoad(const char *pResFile, SDWORD blockID);
@ -112,9 +113,6 @@ extern bool resAddFileLoad(const char *pType, RES_FILELOAD fileLoad,
/** Call the load function for a file. */ /** Call the load function for a file. */
extern bool resLoadFile(const char *pType, const char *pFile); extern bool resLoadFile(const char *pType, const char *pFile);
/** Add data to the resource system. */
extern bool resAddData(char *pType, char *pID, void *pData);
/** Return the resource for a type and ID */ /** Return the resource for a type and ID */
extern void *resGetDataFromHash(const char *pType, UDWORD HashedID); extern void *resGetDataFromHash(const char *pType, UDWORD HashedID);
extern void *resGetData(const char *pType, const char *pID); extern void *resGetData(const char *pType, const char *pID);

View File

@ -33,7 +33,6 @@
#include "eventsave.h" #include "eventsave.h"
// the event save file header // the event save file header
typedef struct _event_save_header typedef struct _event_save_header
{ {
@ -52,11 +51,9 @@ static BOOL eventSaveContext(char *pBuffer, UDWORD *pSize)
INTERP_VAL *psVal; INTERP_VAL *psVal;
SCR_VAL_SAVE saveFunc; SCR_VAL_SAVE saveFunc;
char *pPos; char *pPos;
//not hashed char *pScriptID;
UDWORD hashedName; UDWORD hashedName;
UWORD *pValSize = NULL; UWORD *pValSize = NULL;
size = 0; size = 0;
numContext = 0; numContext = 0;
pPos = pBuffer; pPos = pBuffer;
@ -74,7 +71,6 @@ static BOOL eventSaveContext(char *pBuffer, UDWORD *pSize)
numContext += 1; numContext += 1;
// save the context info // save the context info
//nothashed if (!resGetIDfromData("SCRIPT", psCCont->psCode, &hashedName))
if (!resGetHashfromData("SCRIPT", psCCont->psCode, &hashedName)) if (!resGetHashfromData("SCRIPT", psCCont->psCode, &hashedName))
{ {
debug( LOG_FATAL, "eventSaveContext: couldn't find script resource id" ); debug( LOG_FATAL, "eventSaveContext: couldn't find script resource id" );
@ -85,8 +81,6 @@ static BOOL eventSaveContext(char *pBuffer, UDWORD *pSize)
if (pBuffer != NULL) if (pBuffer != NULL)
{ {
//not hashed strcpy(pPos, pScriptID);
//not hashed pPos += strlen(pScriptID) + 1;
*((UDWORD*)pPos) = (UDWORD)hashedName; *((UDWORD*)pPos) = (UDWORD)hashedName;
endian_udword((UDWORD*)pPos); endian_udword((UDWORD*)pPos);
pPos += sizeof(UDWORD); pPos += sizeof(UDWORD);
@ -99,7 +93,6 @@ static BOOL eventSaveContext(char *pBuffer, UDWORD *pSize)
pPos += sizeof(UBYTE); pPos += sizeof(UBYTE);
} }
//not hashed size += strlen(pScriptID) + 1 + sizeof(SWORD) + sizeof(UBYTE);
size += sizeof(UDWORD) + sizeof(SWORD) + sizeof(UBYTE); size += sizeof(UDWORD) + sizeof(SWORD) + sizeof(UBYTE);
// save the context variables // save the context variables
@ -220,7 +213,7 @@ static BOOL eventSaveContext(char *pBuffer, UDWORD *pSize)
} }
// load the context information for the script system // load the context information for the script system
static BOOL eventLoadContext(const SDWORD version, char *pBuffer, UDWORD *pSize, BOOL bHashed) static BOOL eventLoadContext(const SDWORD version, char *pBuffer, UDWORD *pSize)
{ {
UDWORD size, valSize,stringLen; UDWORD size, valSize,stringLen;
SDWORD numVars, i, numContext, context; SDWORD numVars, i, numContext, context;
@ -228,7 +221,6 @@ static BOOL eventLoadContext(const SDWORD version, char *pBuffer, UDWORD *pSize,
INTERP_TYPE type; INTERP_TYPE type;
SCR_VAL_LOAD loadFunc; SCR_VAL_LOAD loadFunc;
char *pPos; char *pPos;
char *pScriptID = NULL;
UDWORD hashedName; UDWORD hashedName;
SCRIPT_CODE *psCode; SCRIPT_CODE *psCode;
CONTEXT_RELEASE release; CONTEXT_RELEASE release;
@ -246,17 +238,11 @@ static BOOL eventLoadContext(const SDWORD version, char *pBuffer, UDWORD *pSize,
// go through the contexts // go through the contexts
for(context=0; context < numContext; context += 1) for(context=0; context < numContext; context += 1)
{ {
if(bHashed) {
endian_udword((UDWORD*)pPos); endian_udword((UDWORD*)pPos);
hashedName = *((UDWORD*)pPos); hashedName = *((UDWORD*)pPos);
psCode = (SCRIPT_CODE*)resGetDataFromHash("SCRIPT", hashedName); psCode = (SCRIPT_CODE*)resGetDataFromHash("SCRIPT", hashedName);
pPos += sizeof(UDWORD); pPos += sizeof(UDWORD);
} else {
// get the script code
pScriptID = (char *)pPos;
psCode = (SCRIPT_CODE*)resGetData("SCRIPT", pScriptID);
pPos += strlen(pScriptID) + 1;
}
// check the number of variables // check the number of variables
endian_sword((SWORD*)pPos); endian_sword((SWORD*)pPos);
numVars = psCode->numGlobals + psCode->arraySize; numVars = psCode->numGlobals + psCode->arraySize;
@ -281,11 +267,7 @@ static BOOL eventLoadContext(const SDWORD version, char *pBuffer, UDWORD *pSize,
// bit of a hack this - note the id of the context to link it to the triggers // bit of a hack this - note the id of the context to link it to the triggers
psContList->id = (SWORD)context; psContList->id = (SWORD)context;
if(bHashed) { size += sizeof(UDWORD) + sizeof(SWORD) + sizeof(UBYTE);
size += sizeof(UDWORD) + sizeof(SWORD) + sizeof(UBYTE);
} else {
size += strlen(pScriptID) + 1 + sizeof(SWORD) + sizeof(UBYTE);
}
// set the context variables // set the context variables
for(i=0; i < numVars; i+= 1) for(i=0; i < numVars; i+= 1)
@ -601,8 +583,6 @@ BOOL eventSaveState(SDWORD version, char **ppBuffer, UDWORD *pFileSize)
} }
totalSize += size; totalSize += size;
// Allocate the buffer to save to // Allocate the buffer to save to
pBuffer = (char*)malloc(totalSize); pBuffer = (char*)malloc(totalSize);
if (pBuffer == NULL) if (pBuffer == NULL)
@ -613,7 +593,6 @@ BOOL eventSaveState(SDWORD version, char **ppBuffer, UDWORD *pFileSize)
} }
pPos = pBuffer; pPos = pBuffer;
// set the header // set the header
psHdr = (EVENT_SAVE_HDR *)pPos; psHdr = (EVENT_SAVE_HDR *)pPos;
psHdr->aFileType[0] = 'e'; psHdr->aFileType[0] = 'e';
@ -625,7 +604,6 @@ BOOL eventSaveState(SDWORD version, char **ppBuffer, UDWORD *pFileSize)
pPos += sizeof(EVENT_SAVE_HDR); pPos += sizeof(EVENT_SAVE_HDR);
// save the contexts // save the contexts
if (!eventSaveContext(pPos, &size)) if (!eventSaveContext(pPos, &size))
{ {
@ -655,38 +633,25 @@ BOOL eventSaveState(SDWORD version, char **ppBuffer, UDWORD *pFileSize)
// Load the state of the event system // Load the state of the event system
BOOL eventLoadState(char *pBuffer, UDWORD fileSize, BOOL bHashed) BOOL eventLoadState(char *pBuffer, UDWORD fileSize)
{ {
UDWORD size, totalSize, version; UDWORD size, totalSize, version;
char *pPos; char *pPos;
EVENT_SAVE_HDR *psHdr; EVENT_SAVE_HDR *psHdr;
pPos = pBuffer; pPos = pBuffer;
totalSize = 0; totalSize = 0;
// Get the header // Get the header
psHdr = (EVENT_SAVE_HDR *)pPos; psHdr = (EVENT_SAVE_HDR *)pPos;
endian_udword(&psHdr->version); endian_udword(&psHdr->version);
if (strncmp(psHdr->aFileType, "evnt", 4) != 0) ASSERT_OR_RETURN(false, strncmp(psHdr->aFileType, "evnt", 4) == 0, "Invalid file header");
{
debug( LOG_FATAL, "eventLoadState: invalid file header" );
abort();
return false;
}
/* if ((psHdr->version != 1) &&
(psHdr->version != 2))
{
DBERROR(("eventLoadState: invalid file version"));
return false;
}*/
version = psHdr->version; version = psHdr->version;
pPos += sizeof(EVENT_SAVE_HDR); pPos += sizeof(EVENT_SAVE_HDR);
totalSize += sizeof(EVENT_SAVE_HDR); totalSize += sizeof(EVENT_SAVE_HDR);
// load the event contexts // load the event contexts
if (!eventLoadContext(version, pPos, &size, bHashed)) if (!eventLoadContext(version, pPos, &size))
{ {
return false; return false;
} }

View File

@ -31,6 +31,6 @@
extern BOOL eventSaveState(SDWORD version, char **ppBuffer, UDWORD *pFileSize); extern BOOL eventSaveState(SDWORD version, char **ppBuffer, UDWORD *pFileSize);
// Load the state of the event system // Load the state of the event system
extern BOOL eventLoadState(char *pBuffer, UDWORD fileSize, BOOL bHashed); extern BOOL eventLoadState(char *pBuffer, UDWORD fileSize);
#endif #endif

View File

@ -11347,7 +11347,6 @@ BOOL loadScriptState(char *pFileName)
{ {
char *pFileData; char *pFileData;
UDWORD fileSize; UDWORD fileSize;
BOOL bHashed = false;
// change the file extension // change the file extension
pFileName[strlen(pFileName)-4] = (char)0; pFileName[strlen(pFileName)-4] = (char)0;
@ -11361,12 +11360,7 @@ BOOL loadScriptState(char *pFileName)
return false; return false;
} }
if (saveGameVersion > VERSION_12) if (!eventLoadState(pFileData, fileSize))
{
bHashed = true;
}
if (!eventLoadState(pFileData, fileSize, bHashed))
{ {
return false; return false;
} }

View File

@ -198,7 +198,6 @@ BOOL scrGenExternSet(UDWORD index)
{ {
// Since tutorial is skirmish // Since tutorial is skirmish
NetPlay.players[0].allocated = true; NetPlay.players[0].allocated = true;
debug(LOG_ERROR, "tutorial turned %s", val ? "on" : "off");
} }
break; break;
case EXTID_EXTRAVICTORYFLAG: case EXTID_EXTRAVICTORYFLAG:

View File

@ -1677,9 +1677,6 @@ VAR_SYMBOL asObjTable[] =
*/ */
CONST_SYMBOL asConstantTable[] = CONST_SYMBOL asConstantTable[] =
{ {
/* { "TEST_BOOL_CONST", VAL_BOOL, true, 0, 0 },
{ "TEST_INT_CONST", VAL_INT, 0, 10, 0 },*/
//reticule button IDs - for scrFlashOn & Off //reticule button IDs - for scrFlashOn & Off
// original annette styley // original annette styley
{ "OPTIONS", VAL_INT, false, IDRET_OPTIONS, NULL, NULL, 0.0f }, { "OPTIONS", VAL_INT, false, IDRET_OPTIONS, NULL, NULL, 0.0f },
@ -1691,7 +1688,6 @@ CONST_SYMBOL asConstantTable[] =
{ "DESIGN", VAL_INT, false, IDRET_DESIGN, NULL, NULL, 0.0f }, { "DESIGN", VAL_INT, false, IDRET_DESIGN, NULL, NULL, 0.0f },
{ "COMMAND", VAL_INT, false, IDRET_COMMAND, NULL, NULL, 0.0f }, { "COMMAND", VAL_INT, false, IDRET_COMMAND, NULL, NULL, 0.0f },
// new styley that supports many other buttons // new styley that supports many other buttons
{ "IDRET_OPTIONS", VAL_INT, false, IDRET_OPTIONS, NULL, NULL, 0.0f }, { "IDRET_OPTIONS", VAL_INT, false, IDRET_OPTIONS, NULL, NULL, 0.0f },
{ "IDRET_CANCEL", VAL_INT, false, IDRET_CANCEL, NULL, NULL, 0.0f }, { "IDRET_CANCEL", VAL_INT, false, IDRET_CANCEL, NULL, NULL, 0.0f },
@ -1719,13 +1715,11 @@ CONST_SYMBOL asConstantTable[] =
// the first (top-left) button on the list window (up from the reticule) // the first (top-left) button on the list window (up from the reticule)
{ "IDSTAT_START", VAL_INT, false, IDSTAT_START, NULL, NULL, 0.0f }, { "IDSTAT_START", VAL_INT, false, IDSTAT_START, NULL, NULL, 0.0f },
//message Types //message Types
{ "RES_MSG", VAL_INT, false, MSG_RESEARCH, NULL, NULL, 0.0f }, { "RES_MSG", VAL_INT, false, MSG_RESEARCH, NULL, NULL, 0.0f },
{ "CAMP_MSG", VAL_INT, false, MSG_CAMPAIGN, NULL, NULL, 0.0f }, { "CAMP_MSG", VAL_INT, false, MSG_CAMPAIGN, NULL, NULL, 0.0f },
{ "MISS_MSG", VAL_INT, false, MSG_MISSION, NULL, NULL, 0.0f }, { "MISS_MSG", VAL_INT, false, MSG_MISSION, NULL, NULL, 0.0f },
{ "PROX_MSG", VAL_INT, false, MSG_PROXIMITY, NULL, NULL, 0.0f }, { "PROX_MSG", VAL_INT, false, MSG_PROXIMITY, NULL, NULL, 0.0f },
//{ "TUT_MSG", VAL_INT, false, MSG_TUTORIAL, NULL, NULL, 0.0f }, NOT NEEDED
//used for null pointers //used for null pointers
{ "NULLTEMPLATE", (INTERP_TYPE)ST_POINTER_T, false, 0, NULL, NULL, 0.0f }, { "NULLTEMPLATE", (INTERP_TYPE)ST_POINTER_T, false, 0, NULL, NULL, 0.0f },
@ -1941,7 +1935,6 @@ CONST_SYMBOL asConstantTable[] =
{ "STATUS_BattleMapViewEnabled",VAL_INT, false, STATUS_BattleMapViewEnabled, NULL, NULL, 0.0f }, // Are we currently in the battlemap view (tactical display) true=yes { "STATUS_BattleMapViewEnabled",VAL_INT, false, STATUS_BattleMapViewEnabled, NULL, NULL, 0.0f }, // Are we currently in the battlemap view (tactical display) true=yes
{ "STATUS_DeliveryReposInProgress",VAL_INT,false, STATUS_DeliveryReposInProgress, NULL, NULL, 0.0f }, // Are we currently in the delivery repos mode { "STATUS_DeliveryReposInProgress",VAL_INT,false, STATUS_DeliveryReposInProgress, NULL, NULL, 0.0f }, // Are we currently in the delivery repos mode
//possible values for externed targetedObjectType //possible values for externed targetedObjectType
{ "MT_TERRAIN", VAL_INT, false, MT_TERRAIN, NULL, NULL, 0.0f }, { "MT_TERRAIN", VAL_INT, false, MT_TERRAIN, NULL, NULL, 0.0f },
{ "MT_RESOURCE", VAL_INT, false, MT_RESOURCE, NULL, NULL, 0.0f }, { "MT_RESOURCE", VAL_INT, false, MT_RESOURCE, NULL, NULL, 0.0f },
@ -2291,16 +2284,12 @@ BOOL scrTabInitialise(void)
// Set the object variable table // Set the object variable table
scriptSetObjectTab(asObjTable); scriptSetObjectTab(asObjTable);
// Set the callback table // Set the callback table
scriptSetCallbackTab(asCallbackTable); scriptSetCallbackTab(asCallbackTable);
// Set the type equivalence table // Set the type equivalence table
scriptSetTypeEquiv(asEquivTable); scriptSetTypeEquiv(asEquivTable);
// Set the create and release functions // Set the create and release functions
if (!eventAddValueCreate((INTERP_TYPE)ST_BASEOBJECT, scrvAddBasePointer)) if (!eventAddValueCreate((INTERP_TYPE)ST_BASEOBJECT, scrvAddBasePointer))
{ {
@ -2362,14 +2351,9 @@ BOOL scrTabInitialise(void)
return true; return true;
} }
// Shut down the script system // Shut down the script system
void scrShutDown(void) void scrShutDown(void)
{ {
scrvShutDown(); scrvShutDown();
scriptShutDown(); scriptShutDown();
} }