ssggraph: replace global variable grFilePath with function grSetFilePath

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9429 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 629adb423cf17d4b60a37cc49ab756f08283756d
Former-commit-id: 763a6cdb6de25bd36d38040f01f9b0996de03a7a
This commit is contained in:
iobyte 2024-06-09 17:10:27 +00:00
parent 7375c14241
commit 4cab08adcd
5 changed files with 49 additions and 47 deletions

View file

@ -504,7 +504,7 @@ grLoadBackground()
snprintf(buf, sizeof(buf), "tracks/%s/%s;data/img;data/textures;.",
grTrack->category, grTrack->internalname);
grFilePath = buf;
grSetFilePath(buf);
grGammaValue = 1.8;
grMipMap = 0;

View file

@ -1634,49 +1634,51 @@ void grInitBoardCar(tCarElt *car)
2) driver level specified,
3) car level specified,
4) common textures */
grFilePath = (char*)malloc(nMaxTexPathSize);
char filePath[nMaxTexPathSize];
int lg = 0;
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;",
GfLocalDir(), car->_modName, car->_driverIndex, car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;",
GfLocalDir(), car->_modName, car->_driverIndex, car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d;",
GfLocalDir(), car->_modName, car->_driverIndex);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%s;",
GfLocalDir(), car->_modName, car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%s;",
GfLocalDir(), car->_modName, car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s;",
GfLocalDir(), car->_modName);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d/%s;",
car->_modName, car->_driverIndex, car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d/%s;",
car->_modName, car->_driverIndex, car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d;",
car->_modName, car->_driverIndex);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%s;",
car->_modName, car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%s;",
car->_modName, car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s;", car->_modName);
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s;", car->_modName);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "cars/models/%s;", car->_carName);
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "cars/models/%s;", car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "cars/models/%s;", car->_masterModel);
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "cars/models/%s;", car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "data/textures");
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "data/textures");
grSetFilePath(filePath);
/* Tachometer --------------------------------------------------------- */
tgrCarInstrument *curInst = &(carInfo->instrument[0]);
@ -1763,8 +1765,6 @@ void grInitBoardCar(tCarElt *car)
if (curInst->texture == 0)
curInst->texture = (ssgSimpleState*)grSsgLoadTexState("speed360.rgb");
free(grFilePath);
cleanup[nstate] = curInst->texture;
nstate++;

View file

@ -687,7 +687,7 @@ grInitShadow(tCarElt *car)
if (strlen(car->_masterModel) > 0) // Add the master model path if we are using a template.
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "cars/models/%s;", car->_masterModel);
grFilePath = buf;
grSetFilePath(buf);
shdTexName = GfParmGetStr(car->_carHandle, SECT_GROBJECTS, PRM_SHADOW_TEXTURE, "");
@ -961,48 +961,50 @@ grInitCar(tCarElt *car)
/* Set textures search path for (?) rear/front/brake lights, exhaust fires and wheels :
0) driver level specified, in the user settings
1) driver level specified, 2) car level specified, 3) common textures */
grFilePath = (char*)malloc(nMaxTexPathSize);
char filePath[nMaxTexPathSize];
lg = 0;
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;",
GfLocalDir(), car->_modName, car->_driverIndex, car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d/%s;",
GfLocalDir(), car->_modName, car->_driverIndex, car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%d;",
GfLocalDir(), car->_modName, car->_driverIndex);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%s;",
GfLocalDir(), car->_modName, car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s/%s;",
GfLocalDir(), car->_modName, car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "%sdrivers/%s;",
GfLocalDir(), car->_modName);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d/%s;",
car->_modName, car->_driverIndex, car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d/%s;",
car->_modName, car->_driverIndex, car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%d;",
car->_modName, car->_driverIndex);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%s;",
car->_modName, car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s/%s;",
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s/%s;",
car->_modName, car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "drivers/%s;", car->_modName);
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "drivers/%s;", car->_modName);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "cars/models/%s;", car->_carName);
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "cars/models/%s;", car->_carName);
if (bMasterModel)
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "cars/models/%s;", car->_masterModel);
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "cars/models/%s;", car->_masterModel);
lg += snprintf(grFilePath + lg, nMaxTexPathSize - lg, "data/textures");
lg += snprintf(filePath + lg, nMaxTexPathSize - lg, "data/textures");
grSetFilePath(filePath);
grCarInfo[index].envSelector = (ssgStateSelector*)grEnvSelector->clone();
grCarInfo[index].envSelector->ref();
@ -1020,7 +1022,6 @@ grInitCar(tCarElt *car)
if (nranges < 2)
{
GfOut("Error not enough levels of detail\n");
FREEZ(grFilePath);
return;
}
@ -1441,8 +1442,6 @@ grInitCar(tCarElt *car)
//grCarInfo[index].carTransform->print(stdout, "-", 1);
FREEZ(grFilePath);
TRACE_GL("loadcar: end");
}

View file

@ -31,10 +31,14 @@ namespace ssggraph {
float grGammaValue = 1.8;
int grMipMap = 0;
char *grFilePath; // Multiple path (';' separated) used to search for files.
static std::string grFilePath; // Multiple path (';' separated) used to search for files.
void grSetFilePath(const char *paths)
{
grFilePath = paths;
}
int grGetFilename(const char *filename, const char *filepath, char *buf)
static int grGetFilename(const char *filename, const char *filepath, char *buf)
{
const char *c1, *c2;
int found = 0;
@ -140,9 +144,9 @@ ssgState* grSsgLoadTexState(const char *img, int errIfNotFound)
s++;
}
if (!grGetFilename(s, grFilePath, buf)) {
if (!grGetFilename(s, grFilePath.c_str(), buf)) {
if (errIfNotFound)
GfLogError("Texture file %s not found in %s\n", s, grFilePath);
GfLogError("Texture file %s not found in %s\n", s, grFilePath.c_str());
return NULL;
}
@ -201,9 +205,9 @@ cgrMultiTexState* grSsgEnvTexState(const char *img, cgrMultiTexState::tfnTexSche
else
s++;
if (!grGetFilename(s, grFilePath, buf)) {
if (!grGetFilename(s, grFilePath.c_str(), buf)) {
if (errIfNotFound)
GfLogError("Env. texture file %s not found in %s\n", s, grFilePath);
GfLogError("Env. texture file %s not found in %s\n", s, grFilePath.c_str());
return 0;
}

View file

@ -52,9 +52,8 @@ namespace ssggraph {
extern float grGammaValue;
extern int grMipMap;
extern char *grFilePath; /* Multiple path (: separated) used to search for files */
extern void grSetFilePath(const char *paths); /* Multiple path (: separated) used to search for files */
extern int grGetFilename(const char *filename, const char *filepath, char *buf);
extern cgrMultiTexState* grSsgEnvTexState(const char *img,
cgrMultiTexState::tfnTexScheme fnTexScheme,
int errIfNotFound = TRUE);