Only clean up the VIEWDATA relevant for the resource being destroyed.

Apparently the resource destruction system is also fine grained.
master
Per Inge Mathisen 2012-01-07 23:45:36 +01:00
parent 3462f7b5cd
commit 58d0295cf0
5 changed files with 36 additions and 20 deletions

View File

@ -666,37 +666,37 @@ static bool bufferRFUNCLoad(const char *pBuffer, UDWORD size, void **ppData)
/* Load the message viewdata */
static bool bufferSMSGLoad(const char *pBuffer, UDWORD size, void **ppData)
{
VIEWDATA *pViewData;
const char *ptr;
pViewData = loadViewData(pBuffer, size);
if (!pViewData)
ptr = loadViewData(pBuffer, size);
if (!ptr)
{
return false;
}
// set the pointer so the release function gets called with it
*ppData = (void *)pViewData;
*ppData = (void *)ptr;
return true;
}
/* Load research message viewdata */
static bool dataResearchMsgLoad(const char* fileName, void** ppData)
{
VIEWDATA* pViewData = loadResearchViewData(fileName);
if (!pViewData)
const char *ptr = loadResearchViewData(fileName);
if (!ptr)
{
return false;
}
// set the pointer so the release function gets called with it
*ppData = pViewData;
*ppData = (void *)ptr;
return true;
}
// release the message viewdata
static void dataSMSGRelease(void *pData)
{
viewDataShutDown((VIEWDATA *)pData);
viewDataShutDown((const char *)pData);
}
/* Load an imd */

View File

@ -4033,6 +4033,7 @@ static bool loadSaveDroidPointers(const QString &pFileName, DROID **ppsCurrentDr
DROID *psDroid;
int player = getPlayer(ini);
int id = ini.value("id").toInt();
ASSERT(id >= 0, "Negative droid ID in %s", pFileName.toUtf8().constData());
for (psDroid = ppsCurrentDroidLists[player]; psDroid && psDroid->id != id; psDroid = psDroid->psNext)
{

View File

@ -434,7 +434,7 @@ bool initMessage(void)
}
/*load the view data for the messages from the file */
VIEWDATA *loadViewData(const char *pViewMsgData, UDWORD bufferSize)
const char *loadViewData(const char *pViewMsgData, UDWORD bufferSize)
{
UDWORD i, dataInc, seqInc, dummy, numData, count, count2;
VIEW_RESEARCH *psViewRes;
@ -446,6 +446,7 @@ VIEWDATA *loadViewData(const char *pViewMsgData, UDWORD bufferSize)
SDWORD LocX,LocY,LocZ, audioID;
PROX_TYPE proxType;
int cnt;
const char *filename = strdup(GetLastResourceFilename());
numData = numCR(pViewMsgData, bufferSize);
for (i=0; i < numData; i++)
@ -457,6 +458,7 @@ VIEWDATA *loadViewData(const char *pViewMsgData, UDWORD bufferSize)
psViewData->pData = NULL;
psViewData->pName = NULL;
psViewData->type = VIEW_SIZE;
psViewData->fileName = filename;
name[0] = '\0';
//read the data into the storage - the data is delimeted using comma's
@ -683,15 +685,16 @@ VIEWDATA *loadViewData(const char *pViewMsgData, UDWORD bufferSize)
apsViewData.insert(psViewData->pName, psViewData);
}
return (VIEWDATA *)0x01; // fake pointer so that cleanup function will be called
return filename; // so that cleanup function will be called for correct data
}
VIEWDATA* loadResearchViewData(const char* fileName)
const char *loadResearchViewData(const char* fileName)
{
ASSERT_OR_RETURN(NULL, PHYSFS_exists(fileName), "%s not found", fileName);
WzConfig ini(fileName);
ASSERT_OR_RETURN(NULL, ini.status() == QSettings::NoError, "%s not loaded", fileName);
const char *filedup = strdup(fileName);
QStringList list = ini.childGroups();
for (int i = 0; i < list.size(); ++i)
{
@ -700,6 +703,7 @@ VIEWDATA* loadResearchViewData(const char* fileName)
v->pData = NULL;
v->pName = strdup(list[i].toUtf8().constData());
v->fileName = filedup;
memset(r, 0, sizeof(*r));
ini.beginGroup(list[i]);
@ -733,7 +737,7 @@ VIEWDATA* loadResearchViewData(const char* fileName)
ini.endGroup();
apsViewData.insert(v->pName, v);
}
return (VIEWDATA *)0x01; // fake pointer so that cleanup function will be called
return filedup; // so that cleanup function will be called on rigth data
}
/* Get the view data identified by the name */
@ -758,6 +762,7 @@ VIEWDATA *getViewData(const char *pName)
bool messageShutdown(void)
{
freeMessages();
apsViewData.clear();
return true;
}
@ -780,14 +785,24 @@ static void checkMessages(MSG_VIEWDATA *psViewData)
}
}
/* Release the viewdata memory -- input parameter ignored */
void viewDataShutDown(VIEWDATA *psViewDataUnused)
/* Release the viewdata memory */
void viewDataShutDown(const char *fileName)
{
debug(LOG_MSG, "calling shutdown for %s", fileName);
QMap<QString, VIEWDATA *>::iterator iter = apsViewData.begin();
char *filedup = NULL;
while (iter != apsViewData.constEnd())
{
VIEWDATA *psViewData = iter.value();
if (strcmp(psViewData->fileName, fileName) != 0)
{
++iter;
continue; // do not delete this now
}
filedup = (char *)psViewData->fileName;
// check for any messages using this viewdata
checkMessages((MSG_VIEWDATA *)psViewData);
@ -820,9 +835,9 @@ void viewDataShutDown(VIEWDATA *psViewDataUnused)
}
free(psViewData->pData);
delete psViewData;
++iter;
iter = apsViewData.erase(iter);
}
apsViewData.clear();
free(filedup);
}
/* Looks through the players list of messages to find one with the same viewData

View File

@ -63,15 +63,14 @@ void freeMessages(void);
void releaseAllProxDisp(void);
/** Load the view data for the messages from the file exported from the world editor. */
VIEWDATA* loadViewData(const char *pViewMsgData, UDWORD bufferSize);
VIEWDATA* loadResearchViewData(const char* fileName);
const char *loadViewData(const char *pViewMsgData, UDWORD bufferSize);
const char *loadResearchViewData(const char* fileName);
/** Get the view data that contains the text message pointer passed in. */
VIEWDATA *getViewData(const char *pTextMsg);
/** Release the viewdata memory. */
void viewDataShutDown(VIEWDATA *psViewData);
void viewDataShutDown(const char *fileName);
/** Looks through the players list of messages to find one with the same viewData
* pointer and which is the same type of message - used in scriptFuncs. */

View File

@ -107,6 +107,7 @@ struct VIEWDATA
QStringList textMsg; //Text messages, if any
void* pData; /*the data required to view - either a
VIEW_RESEARCH, VIEW_PROXIMITY or VIEW_REPLAY*/
const char *fileName; //file it came from, for piecemeal destruction (pretty lame reason)
};
typedef void* MSG_VIEWDATA;