From f2ad2b3524ee40e518e6881c8b3aa549a95fc0b0 Mon Sep 17 00:00:00 2001 From: pouillot Date: Mon, 1 Nov 2010 14:35:19 +0000 Subject: [PATCH] Re #222 (more skinning targets) Added skinnability for *-int.png interior textures + improved gr traces git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3074 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: ff9f2cc028b131f2e598b9105f131a4805f8363d Former-commit-id: 16bb55deac8a8547a868c6de3b48349be6971ba2 --- src/libs/racescreens/driver.cpp | 72 ++++++++++++++++++----- src/modules/graphic/ssggraph/grcar.cpp | 29 ++++++--- src/modules/graphic/ssggraph/grloadac.cpp | 3 +- src/modules/graphic/ssggraph/grscene.cpp | 16 ++--- src/modules/graphic/ssggraph/grutil.cpp | 2 +- 5 files changed, 87 insertions(+), 35 deletions(-) diff --git a/src/libs/racescreens/driver.cpp b/src/libs/racescreens/driver.cpp index 1f818358..f5531286 100644 --- a/src/libs/racescreens/driver.cpp +++ b/src/libs/racescreens/driver.cpp @@ -39,12 +39,12 @@ const char* rmdStdSkinName = "standard"; static const char* pszSkinFileExt = ".png"; static const char* pszPreviewFileSuffix = "-preview.jpg"; +static const char* pszSkinIntFileSuffix = "-int"; static const char* pszLogoFileName = "logo"; // Warning: Must be consistent with grscene.cpp static const char* pszWheel3DFileName = "wheel3d"; // Warning: Must be consistent with wheel.ac/acc -static const char* apszExcludedSkinFileSuffixes[] = -{ "rpm.png", "speed.png", "int.png" }; -static const int nExcludedSkinFileSuffixes = sizeof(apszExcludedSkinFileSuffixes) / sizeof(char*); +static const char* apszExcludedSkinNamePrefixes[] = { "rpm", "speed", "int" }; +static const int nExcludedSkinNamePrefixes = sizeof(apszExcludedSkinNamePrefixes) / sizeof(char*); int rmdDriverMatchesFilters(const trmdDrvElt *drv, const char* carCat, const char* drvTyp, @@ -88,7 +88,7 @@ void rmdGetCarSkinsInFolder(const char* pszCarName, const char* pszFolderPath, { //GfLogDebug(" rmdGetCarSkinsInFolder(car=%s, path=%s) ...\n", pszCarName, pszFolderPath); - // Search for livery skin files, and asociated preview files if any. + // Search for skinned livery files, and associated preview files if any. tFList *pSkinFileList = GfDirGetListFiltered(pszFolderPath, pszCarName, pszSkinFileExt); if (pSkinFileList) { @@ -97,22 +97,24 @@ void rmdGetCarSkinsInFolder(const char* pszCarName, const char* pszFolderPath, { pCurSkinFile = pCurSkinFile->next; - // Ignore files with an excluded suffix. - int nExclSfxInd = 0; - for (; nExclSfxInd < nExcludedSkinFileSuffixes; nExclSfxInd++) - if (strstr(pCurSkinFile->name, apszExcludedSkinFileSuffixes[nExclSfxInd])) - break; - if (nExclSfxInd < nExcludedSkinFileSuffixes) - continue; - - // Extract the skin name from the skin file name. + // Extract the skin name from the livery file name. const int nSkinNameLen = // Expecting "-.png" strlen(pCurSkinFile->name) - strlen(pszCarName) - 1 - strlen(pszSkinFileExt); std::string strSkinName; if (nSkinNameLen > 0) + { strSkinName = std::string(pCurSkinFile->name) .substr(strlen(pszCarName) + 1, nSkinNameLen); + + // Ignore skins with an excluded prefix. + int nExclPrfxInd = 0; + for (; nExclPrfxInd < nExcludedSkinNamePrefixes; nExclPrfxInd++) + if (strSkinName.find(apszExcludedSkinNamePrefixes[nExclPrfxInd]) == 0) + break; + if (nExclPrfxInd < nExcludedSkinNamePrefixes) + continue; + } else // Assuming default/standard ".png" strSkinName = rmdStdSkinName; @@ -149,11 +151,47 @@ void rmdGetCarSkinsInFolder(const char* pszCarName, const char* pszFolderPath, // strSkinName.c_str(), ossPreviewName.str().c_str()); } - } while (pCurSkinFile != pSkinFileList); + } + while (pCurSkinFile != pSkinFileList); } GfDirFreeList(pSkinFileList, NULL); + // Search for skinned interior files, if any. + std::string strInteriorPrefix(pszCarName); + strInteriorPrefix += pszSkinIntFileSuffix; + tFList *pIntFileList = + GfDirGetListFiltered(pszFolderPath, strInteriorPrefix.c_str(), pszSkinFileExt); + if (pIntFileList) + { + tFList *pCurSkinFile = pIntFileList; + do + { + pCurSkinFile = pCurSkinFile->next; + + // Extract the skin name from the interior file name. + const int nSkinNameLen = // Expecting "-int-.png" + strlen(pCurSkinFile->name) - strInteriorPrefix.length() + - 1 - strlen(pszSkinFileExt); + std::string strSkinName; + if (nSkinNameLen > 0) + { + strSkinName = + std::string(pCurSkinFile->name) + .substr(strInteriorPrefix.length() + 1, nSkinNameLen); + + // Add the interior to the skin targets. + if (mapSkinTargets.find(strSkinName) == mapSkinTargets.end()) + mapSkinTargets[strSkinName] = 0; + mapSkinTargets[strSkinName] |= RM_CAR_SKIN_TARGET_INTERIOR; + + GfLogDebug(" Found %s-skinned interior (targets:%x)\n", + strSkinName.c_str(), mapSkinTargets[strSkinName]); + } + } + while (pCurSkinFile != pIntFileList); + } + // Search for skinned logo files if any. tFList *pLogoFileList = GfDirGetListFiltered(pszFolderPath, pszLogoFileName, pszSkinFileExt); @@ -183,7 +221,8 @@ void rmdGetCarSkinsInFolder(const char* pszCarName, const char* pszFolderPath, strSkinName.c_str(), mapSkinTargets[strSkinName]); } - } while (pCurLogoFile != pLogoFileList); + } + while (pCurLogoFile != pLogoFileList); } GfDirFreeList(pLogoFileList, NULL); @@ -217,7 +256,8 @@ void rmdGetCarSkinsInFolder(const char* pszCarName, const char* pszFolderPath, strSkinName.c_str(), mapSkinTargets[strSkinName]); } - } while (pCurWheel3DFile != pWheel3DFileList); + } + while (pCurWheel3DFile != pWheel3DFileList); } GfDirFreeList(pWheel3DFileList, NULL); diff --git a/src/modules/graphic/ssggraph/grcar.cpp b/src/modules/graphic/ssggraph/grcar.cpp index f22b1a9b..b7c6d5ba 100644 --- a/src/modules/graphic/ssggraph/grcar.cpp +++ b/src/modules/graphic/ssggraph/grcar.cpp @@ -564,12 +564,12 @@ grInitCar(tCarElt *car) const bool bMasterModel = strlen(car->_masterModel) != 0; const bool bCustomSkin = strlen(car->_skinName) != 0; - GfLogTrace("Loading graphics for %s (driver:%s, skin:%s.%x, master model:%s)\n", - car->_carName, car->_name, - bCustomSkin ? car->_skinName : "standard", car->_skinTargets, - bMasterModel ? car->_masterModel : "self"); + GfLogInfo("Loading graphics for %s (driver:%s, skin:%s.%x, master model:%s)\n", + car->_carName, car->_name, + bCustomSkin ? car->_skinName : "standard", car->_skinTargets, + bMasterModel ? car->_masterModel : "self"); - /* 1) Whole livery */ + /* 1) Whole livery : .png => -.png */ std::string strSrcTexName(bMasterModel ? car->_masterModel : car->_carName); std::string strTgtTexName(car->_carName); if (bCustomSkin && car->_skinTargets & RM_CAR_SKIN_TARGET_WHOLE_LIVERY) @@ -583,17 +583,30 @@ grInitCar(tCarElt *car) strSrcTexName += pszTexFileExt; strTgtTexName += pszTexFileExt; options.addTextureMapping(strSrcTexName.c_str(), strTgtTexName.c_str()); - GfLogDebug("Using skinned livery %s\n", strTgtTexName.c_str()); + GfLogTrace("Using skinned livery %s\n", strTgtTexName.c_str()); } - /* 2) 3D wheels if present */ + /* 2) Interior : -int.png => -int-.png */ + if (bCustomSkin && car->_skinTargets & RM_CAR_SKIN_TARGET_INTERIOR) + { + strSrcTexName = (bMasterModel ? car->_masterModel : car->_carName); + strTgtTexName = car->_carName; + strTgtTexName += "-int-"; + strTgtTexName += car->_skinName; + strSrcTexName += pszTexFileExt; + strTgtTexName += pszTexFileExt; + options.addTextureMapping(strSrcTexName.c_str(), strTgtTexName.c_str()); + GfLogTrace("Using skinned interior %s\n", strTgtTexName.c_str()); + } + + /* 3) 3D wheels if present */ if (bCustomSkin && car->_skinTargets & RM_CAR_SKIN_TARGET_3D_WHEELS) { strSrcTexName = "wheel3d"; // Warning: Must be consistent with wheel.ac/.acc contents strTgtTexName = strSrcTexName + '-' + car->_skinName + pszTexFileExt; strSrcTexName += pszTexFileExt; options.addTextureMapping(strSrcTexName.c_str(), strTgtTexName.c_str()); - GfLogDebug("Using skinned 3D wheels %s\n", strTgtTexName.c_str()); + GfLogTrace("Using skinned 3D wheels %s\n", strTgtTexName.c_str()); } grssgSetCurrentOptions(&options); diff --git a/src/modules/graphic/ssggraph/grloadac.cpp b/src/modules/graphic/ssggraph/grloadac.cpp index c3434a26..b2066ec7 100644 --- a/src/modules/graphic/ssggraph/grloadac.cpp +++ b/src/modules/graphic/ssggraph/grloadac.cpp @@ -1156,7 +1156,7 @@ ssgEntity *grssgCarLoadAC3D ( const char *fname, const grssgLoaderOptions* optio t_xmin=+999999.0; t_ymin=+999999.0; - GfOut("Loading %s\n", fname); + GfLogTrace("Loading %s\n", fname); ssgEntity *obj = myssgLoadAC ( fname, options ) ; @@ -1326,7 +1326,6 @@ void grssgLoaderOptions::addTextureMapping(const char* pszSrcFileName, const cha { _mapTextures[pszSrcFileName] = pszTgtFileName; _bTextureMapping = true; - GfTrace("grssgLoaderOptions::addTextureMapping(%s, %s)\n", pszSrcFileName, pszTgtFileName); } bool grssgLoaderOptions::textureMapping() const diff --git a/src/modules/graphic/ssggraph/grscene.cpp b/src/modules/graphic/ssggraph/grscene.cpp index 51392568..cb62fb8d 100644 --- a/src/modules/graphic/ssggraph/grscene.cpp +++ b/src/modules/graphic/ssggraph/grscene.cpp @@ -499,16 +499,16 @@ grLoadScene(tTrack *track) grWrldMaxSize = (int)(MAX(MAX(grWrldX, grWrldY), grWrldZ)); RainBool = grTrack->Rain; - printf("Rain = %d\n", RainBool); + GfLogTrace("Rain = %d\n", RainBool); //acname = GfParmGetStr(hndl, TRK_SECT_GRAPH, TRK_ATT_3DDESC, "track.ac"); /*if ((grTrack->Timeday == 1) && (grTrack->skyversion > 0)) // If night in quickrace, practice or network mode acname = GfParmGetStr(hndl, TRK_SECT_GRAPH, TRK_ATT_3DDESC3, "track.ac"); else*/ acname = GfParmGetStr(hndl, TRK_SECT_GRAPH, TRK_ATT_3DDESC, "track.ac"); - GfOut("ACname = %s\n", acname); if (strlen(acname) == 0) { + GfLogError("No specified track 3D model file\n"); return -1; } @@ -910,14 +910,14 @@ initBackground(void) { //Environment Mapping Settings grEnvSelector = new ssgStateSelector(graphic->envnb); for (i = 0; i < graphic->envnb; i++) { - GfOut("Loading Environment Mapping Image %s\n", graphic->env[i]); + GfLogTrace("Loading %d Environment Mapping Image %s\n", i, graphic->env[i]); envst = (ssgSimpleState*)grSsgLoadTexState(graphic->env[i]); // Avoid chrash with missing env.rgb files (i.e. Wheel-1) if (envst == NULL) { - GfOut("Try env.png instead\n"); + GfLogWarning("Failed : trying fallback env.png\n"); envst = (ssgSimpleState*)grSsgLoadTexState("env.png"); if (envst == NULL) { - GfOut("This will stop displaying graphics!\n"); + GfLogError("No usable Environment Mapping Image for #%d : stop displaying graphics!\n", i); DoNotUseEnv = true; break; } @@ -935,7 +935,7 @@ initBackground(void) { grEnvState=(grMultiTexState*)grSsgEnvTexState("env.png"); else { if (DoNotUseEnv) - GfOut("No env.png found!\n"); + GfLogError("No env.png found!\n"); else grEnvState=(grMultiTexState*)grSsgEnvTexState(graphic->env[0]); } @@ -985,7 +985,7 @@ grCustomizePits(void) switch (pits->type) { case TR_PIT_ON_TRACK_SIDE: for(int i = 0; i < pits->nMaxPits; i++) { - //GfOut("Pit Nbr: %d\n", i); + //GfLogDebug("Pit Nbr: %d\n", i); ssgVertexArray *pit_vtx = new ssgVertexArray(4); ssgTexCoordArray *pit_tex = new ssgTexCoordArray(4); ssgColourArray *pit_clr = new ssgColourArray(1); @@ -1017,7 +1017,7 @@ grCustomizePits(void) { strLogoFileName += '-'; strLogoFileName += pits->driversPits[i].car[0]->_skinName; - GfLogDebug("Using skinned pit door logo %s\n", strLogoFileName.c_str()); + GfLogTrace("Using skinned pit door logo %s\n", strLogoFileName.c_str()); } } else { diff --git a/src/modules/graphic/ssggraph/grutil.cpp b/src/modules/graphic/ssggraph/grutil.cpp index 5a0ed74f..b12ddcd5 100644 --- a/src/modules/graphic/ssggraph/grutil.cpp +++ b/src/modules/graphic/ssggraph/grutil.cpp @@ -128,7 +128,7 @@ static void grSetupState(grManagedState *st, char *buf) curr->state = st; curr->name = strdup(buf); - GfOut("Loading %s\n", buf); + GfLogTrace("Loading texture %s\n", buf); }