Cleanup of PIE stats loading.

master
per 2013-09-07 14:44:08 +02:00
parent d0496e6859
commit 7007cc8af8
10 changed files with 41 additions and 74 deletions

View File

@ -24,10 +24,16 @@
#else
# include <physfs.h>
#endif
#include <QtCore/QString>
#define PHYSFS_APPEND 1
#define PHYSFS_PREPEND 0
static inline bool PHYSFS_exists(const QString &filename)
{
return PHYSFS_exists(filename.toUtf8().constData());
}
static inline bool PHYSFS_writeSLE8(PHYSFS_file* file, int8_t val)
{
return (PHYSFS_write(file, &val, sizeof(int8_t), 1) == 1);

View File

@ -157,7 +157,7 @@ bool anim_Create3D(char szPieFileName[], UWORD uwStates, UWORD uwFrameRate, UWOR
}
/* get local pointer to shape */
psAnim3D->psFrames = (iIMDShape*)resGetData("IMD", szPieFileName);
psAnim3D->psFrames = modelGet(szPieFileName);
/* count frames in imd */
psFrames = psAnim3D->psFrames;

View File

@ -20,8 +20,15 @@
#ifndef _imd_
#define _imd_
#include <QtCore/QString>
#include "ivisdef.h"
#include "lib/framework/frameresource.h"
static inline iIMDShape *modelGet(const QString &filename)
{
return (iIMDShape *) resGetData("IMD", filename.toUtf8().constData());
}
#define PIE_NAME "PIE" // Pumpkin image export data file
#define PIE_VER 2

View File

@ -2136,7 +2136,7 @@ void effectSetupExplosion(EFFECT *psEffect)
SET_ESSENTIAL(psEffect); // Landing lights are permanent and cyclic
break;
case EXPLOSION_TYPE_SHOCKWAVE:
psEffect->imd = getImdFromIndex(MI_SHOCK);//resGetData("IMD","blbhq.pie");
psEffect->imd = getImdFromIndex(MI_SHOCK);
psEffect->size = 50;
psEffect->velocity.y = 0.0f;
break;
@ -2586,7 +2586,7 @@ bool readFXData(const char *fileName)
QString imd_name = ini.value("imd_name").toString();
if (!imd_name.isEmpty())
{
curEffect->imd = (iIMDShape*)resGetData("IMD", imd_name.toUtf8().constData());
curEffect->imd = modelGet(imd_name);
}
}
else

View File

@ -95,7 +95,7 @@ bool loadFeatureStats(const char *pFileName)
else if (subType == "TREE") p->subType = FEAT_TREE;
else if (subType == "SKYSCRAPER") p->subType = FEAT_SKYSCRAPER;
else ASSERT(false, "Unknown feature type: %s", subType.toUtf8().constData());
p->psImd = (iIMDShape *)resGetData("IMD", ini.value("model").toString().toUtf8().constData());
p->psImd = modelGet(ini.value("model").toString());
p->baseWidth = ini.value("width", 1).toInt();
p->baseBreadth = ini.value("breadth", 1).toInt();
p->tileDraw = ini.value("tiledraw", 1).toInt();

View File

@ -423,7 +423,7 @@ void releaseAllProxDisp(void)
bool initMessage(void)
{
//set up the imd used for proximity messages
pProximityMsgIMD = (iIMDShape *)resGetData("IMD", "arrow.pie");
pProximityMsgIMD = modelGet("arrow.pie");
if (pProximityMsgIMD == NULL)
{
ASSERT(false, "Unable to load Proximity Message PIE");
@ -503,7 +503,7 @@ const char *loadViewData(const char *pViewMsgData, UDWORD bufferSize)
imdName, imdName2, string, audioName, &dummy, &cnt);
pViewMsgData += cnt;
psViewRes = (VIEW_RESEARCH *)psViewData->pData;
psViewRes->pIMD = (iIMDShape *) resGetData("IMD", imdName);
psViewRes->pIMD = modelGet(imdName);
if (psViewRes->pIMD == NULL)
{
ASSERT(false, "Cannot find the PIE for message %s", name);
@ -512,7 +512,7 @@ const char *loadViewData(const char *pViewMsgData, UDWORD bufferSize)
}
if (strcmp(imdName2, "0"))
{
psViewRes->pIMD2 = (iIMDShape *) resGetData("IMD", imdName2);
psViewRes->pIMD2 = modelGet(imdName2);
if (psViewRes->pIMD2 == NULL)
{
ASSERT(false, "Cannot find the 2nd PIE for message %s", name);
@ -719,11 +719,11 @@ const char *loadResearchViewData(const char* fileName)
v->pData = r;
if (ini.contains("imdName"))
{
r->pIMD = (iIMDShape *) resGetData("IMD", ini.value("imdName").toString().toUtf8().constData());
r->pIMD = modelGet(ini.value("imdName").toString());
}
if (ini.contains("imdName2"))
{
r->pIMD2 = (iIMDShape *) resGetData("IMD", ini.value("imdName2").toString().toUtf8().constData());
r->pIMD2 = modelGet(ini.value("imdName2").toString());
}
if (ini.contains("sequenceName"))
{

View File

@ -99,7 +99,7 @@ char name[15]; // hopefully!
snprintf(name, sizeof(name), "%s.pie", miscImds[i].pName);
/* see if the resource loader can find it */
miscImds[i].pImd = (iIMDShape*)resGetData("IMD",name);
miscImds[i].pImd = modelGet(name);
/* If it didn't get it then... */
if(!miscImds[i].pImd)
{
@ -144,11 +144,10 @@ static bool initMiscImd(unsigned i, unsigned n, const char *nameFormat, unsigned
{
char pieName[100];
snprintf(pieName, sizeof(pieName), nameFormat, n);
pAssemblyPointIMDs[flagType][i] = (iIMDShape *)resGetData("IMD", pieName);
pAssemblyPointIMDs[flagType][i] = modelGet(pieName);
if (!pAssemblyPointIMDs[flagType][i])
{
debug(LOG_ERROR, "Can't find assembly point graphic %s for factory", pieName);
return false;
}
return true;

View File

@ -194,24 +194,16 @@ bool loadResearch(QString filename)
QString imdName = ini.value("imdName", "").toString();
if (imdName.compare("") != 0)
{
research.pIMD = (iIMDShape *) resGetData("IMD", imdName.toUtf8().data());
research.pIMD = modelGet(imdName);
ASSERT(research.pIMD != NULL, "Cannot find the research PIE '%s' for record '%s'",imdName.toUtf8().data(), getName(&research));
}
else
{
research.pIMD = NULL;
}
QString imdName2 = ini.value("imdName2", "").toString();
if (imdName2.compare("") != 0)
{
research.pIMD2 = (iIMDShape *) resGetData("IMD", imdName2.toUtf8().data());
research.pIMD2 = modelGet(imdName2);
ASSERT(research.pIMD2 != NULL, "Cannot find the 2nd research '%s' PIE for record '%s'",imdName2.toUtf8().data(), getName(&research));
}
else
{
research.pIMD2 = NULL;
}
QString msgName = ini.value("msgName", "").toString();
if (msgName.compare("") != 0)

View File

@ -260,15 +260,18 @@ bool statsAllocConstruct(UDWORD numStats)
* Load stats functions
*******************************************************************************/
static iIMDShape *statsGetIMD(WzConfig &ini, BASE_STATS *psStats, QString key)
static iIMDShape *statsGetIMD(WzConfig &ini, BASE_STATS *psStats, QString key, int index = 0)
{
iIMDShape *retval = NULL;
if (ini.contains(key))
{
QString model = ini.value(key).toString();
retval = (iIMDShape *)resGetData("IMD", model.toUtf8().constData());
ASSERT(retval != NULL, "Cannot find the PIE model %s for stat %s in %s",
model.toUtf8().constData(), getName(psStats), ini.fileName().toUtf8().constData());
QStringList values = ini.value(key).toStringList();
if (values[index].compare("0") != 0)
{
retval = modelGet(values[index]);
ASSERT(retval != NULL, "Cannot find the PIE model %s for stat %s in %s",
values[index].toUtf8().constData(), getName(psStats), ini.fileName().toUtf8().constData());
}
}
return retval;
}
@ -1121,51 +1124,11 @@ bool loadBodyPropulsionIMDs(const char *pFileName)
debug(LOG_FATAL, "Invalid propulsion name %s", keys[j].toUtf8().constData());
return false;
}
//allocate the left and right propulsion IMDs
QStringList values = ini.value(keys[j]).toStringList();
if (values[0].compare("0") != 0)
{
iIMDShape *psShape = (iIMDShape *)resGetData("IMD", values[0].toUtf8().constData());
if (psShape == NULL)
{
debug(LOG_FATAL, "Cannot find the left propulsion PIE for body %s", list[i].toUtf8().constData());
return false;
}
psBodyStat->ppIMDList[numStats * NUM_PROP_SIDES + LEFT_PROP] = psShape;
}
//right IMD might not be there
if (values.size() > 1 && values[1].compare("0") != 0)
{
iIMDShape *psShape = (iIMDShape *)resGetData("IMD", values[1].toUtf8().constData());
if (psShape == NULL)
{
debug(LOG_FATAL, "Cannot find the right propulsion PIE for body %s", list[i].toUtf8().constData());
return false;
}
psBodyStat->ppIMDList[numStats * NUM_PROP_SIDES + RIGHT_PROP] = psShape;
}
// movement animation effect, if any
if (values.size() > 2 && values[2].compare("0") != 0)
{
iIMDShape *psShape = (iIMDShape *)resGetData("IMD", values[2].toUtf8().constData());
if (psShape == NULL)
{
debug(LOG_FATAL, "Cannot find the movement propulsion PIE for body %s", list[i].toUtf8().constData());
return false;
}
psBodyStat->ppMoveIMDList[numStats] = psShape;
}
// standing still animation effect, if any
if (values.size() > 3 && values[3].compare("0") != 0)
{
iIMDShape *psShape = (iIMDShape *)resGetData("IMD", values[3].toUtf8().constData());
if (psShape == NULL)
{
debug(LOG_FATAL, "Cannot find the standing still propulsion PIE for body %s", list[i].toUtf8().constData());
return false;
}
psBodyStat->ppStillIMDList[numStats] = psShape;
}
//allocate the left and right propulsion IMDs + movement and standing still animations
psBodyStat->ppIMDList[numStats * NUM_PROP_SIDES + LEFT_PROP] = statsGetIMD(ini, psBodyStat, keys[j], 0);
psBodyStat->ppIMDList[numStats * NUM_PROP_SIDES + RIGHT_PROP] = statsGetIMD(ini, psBodyStat, keys[j], 1);
psBodyStat->ppMoveIMDList[numStats] = statsGetIMD(ini, psBodyStat, keys[j], 2);
psBodyStat->ppStillIMDList[numStats] = statsGetIMD(ini, psBodyStat, keys[j], 3);
}
ini.endGroup();
}

View File

@ -515,7 +515,7 @@ bool loadStructureStats(QString filename)
QStringList models = ini.value("structureModel").toStringList();
for (int j = 0; j < models.size(); j++)
{
iIMDShape *imd = (iIMDShape *)resGetData("IMD", models[j].trimmed().toUtf8().constData());
iIMDShape *imd = modelGet(models[j].trimmed());
ASSERT(imd != NULL, "Cannot find the PIE structureModel '%s' for structure '%s'", models[j].toUtf8().constData(), getID(psStats));
psStats->pIMD.push_back(imd);
}
@ -524,7 +524,7 @@ bool loadStructureStats(QString filename)
QString baseModel = ini.value("baseModel","").toString();
if (baseModel.compare("") != 0)
{
iIMDShape *imd = (iIMDShape *)resGetData("IMD", baseModel.toUtf8().constData());
iIMDShape *imd = modelGet(baseModel);
ASSERT(imd != NULL, "Cannot find the PIE baseModel '%s' for structure '%s'", baseModel.toUtf8().constData(), getID(psStats));
psStats->pBaseIMD = imd;
}