diff --git a/src/interfaces/car.h b/src/interfaces/car.h index 6a57d430..dc926dd6 100644 --- a/src/interfaces/car.h +++ b/src/interfaces/car.h @@ -98,12 +98,14 @@ typedef struct { - RM_CAR_SKIN_TARGET_3D_WHEELS - RM_CAR_SKIN_TARGET_INTERIOR - RM_CAR_SKIN_TARGET_BOARD + - RM_CAR_SKIN_TARGET_DRIVER - RM_CAR_SKIN_TARGET_PIT_DOOR */ #define RM_CAR_SKIN_TARGET_WHOLE_LIVERY 0x00000001 /**< The whole car external livery */ #define RM_CAR_SKIN_TARGET_3D_WHEELS 0x00000002 /**< The 3D wheels */ #define RM_CAR_SKIN_TARGET_INTERIOR 0x00000010 /**< The car interior */ #define RM_CAR_SKIN_TARGET_BOARD 0x00000020 /**< The interior instrument board */ +#define RM_CAR_SKIN_TARGET_DRIVER 0x00000040 /**< The driver */ #define RM_CAR_SKIN_TARGET_PIT_DOOR 0x00000100 /**< The pit door logo */ } tInitCar; diff --git a/src/libs/tgfdata/drivers.cpp b/src/libs/tgfdata/drivers.cpp index 4f8f49de..9d0ac4e7 100644 --- a/src/libs/tgfdata/drivers.cpp +++ b/src/libs/tgfdata/drivers.cpp @@ -239,13 +239,13 @@ void GfDrivers::print() const // GfDriverSkin class --------------------------------------------------------------- -GfDriverSkin::GfDriverSkin(const std::string& strName) : _strName(strName), _nTargets(0) +GfDriverSkin::GfDriverSkin(const std::string& strName) : _strName(strName), _bfTargets(0) { } int GfDriverSkin::getTargets() const { - return _nTargets; + return _bfTargets; } const std::string& GfDriverSkin::getName() const @@ -258,14 +258,14 @@ const std::string& GfDriverSkin::getCarPreviewFileName() const return _strCarPreviewFileName; } -void GfDriverSkin::setTargets(int nTargets) +void GfDriverSkin::setTargets(int bfTargets) { - _nTargets = nTargets; + _bfTargets = bfTargets; } -void GfDriverSkin::addTargets(int nTargets) +void GfDriverSkin::addTargets(int bfTargets) { - _nTargets |= nTargets; + _bfTargets |= bfTargets; } void GfDriverSkin::setName(const std::string& strName) @@ -459,6 +459,8 @@ static const char* pszLiveryTexExt = ".png"; static const char* pszPreviewTexSufx = "-preview.jpg"; static const char* pszInteriorTexExt = ".png"; static const char* pszInteriorTexSufx = "-int"; +static const char* pszDriverTexName = "driver"; // Warning: Must be consistent with .ac/acc +static const char* pszDriverTexExt = ".png"; static const char* pszLogoTexName = "logo"; // Warning: Must be consistent with grscene.cpp static const char* pszLogoTexExt = ".png"; static const char* pszWheel3DTexName = "wheel3d"; // Warning: Must be consistent with wheel.ac/acc @@ -641,7 +643,7 @@ void GfDriver::getPossibleSkinsInFolder(const std::string& strCarId, pCurWheel3DFile = pCurWheel3DFile->next; // Extract the skin name from the 3D wheel texture file name. - const int nSkinNameLen = // Expecting "logo-.png" + const int nSkinNameLen = // Expecting "wheel3d-.png" strlen(pCurWheel3DFile->name) - strlen(pszWheel3DTexName) - 1 - strlen(pszWheel3DTexExt); if (nSkinNameLen > 0) @@ -664,6 +666,41 @@ void GfDriver::getPossibleSkinsInFolder(const std::string& strCarId, } GfDirFreeList(pWheel3DFileList, NULL); + + // Search for skinned driver files if any. + tFList *pDriverFileList = + GfDirGetListFiltered(strFolderPath.c_str(), pszDriverTexName, pszDriverTexExt); + if (pDriverFileList) + { + tFList *pCurDriverFile = pDriverFileList; + do + { + pCurDriverFile = pCurDriverFile->next; + + // Extract the skin name from the 3D wheel texture file name. + const int nSkinNameLen = // Expecting "driver-.png" + strlen(pCurDriverFile->name) - strlen(pszDriverTexName) + - 1 - strlen(pszDriverTexExt); + if (nSkinNameLen > 0) + { + const std::string strSkinName = + std::string(pCurDriverFile->name) + .substr(strlen(pszDriverTexName) + 1, nSkinNameLen); + + // If a skin with such name already exists in the list, update it. + std::vector::iterator itSkin = findSkin(vecPossSkins, strSkinName); + if (itSkin != vecPossSkins.end()) + { + itSkin->addTargets(RM_CAR_SKIN_TARGET_DRIVER); + GfLogDebug(" Found %s-skinned driver (targets:%x)\n", + strSkinName.c_str(), itSkin->getTargets()); + } + } + } + while (pCurDriverFile != pDriverFileList); + } + + GfDirFreeList(pDriverFileList, NULL); } std::vector GfDriver::getPossibleSkins(const std::string& strAltCarId) const diff --git a/src/libs/tgfdata/drivers.h b/src/libs/tgfdata/drivers.h index 57513faa..03135c43 100644 --- a/src/libs/tgfdata/drivers.h +++ b/src/libs/tgfdata/drivers.h @@ -45,14 +45,14 @@ public: const std::string& getName() const; const std::string& getCarPreviewFileName() const; - void setTargets(int nTargets); // Overwrite any previous target. + void setTargets(int bfTargets); // Overwrite any previous target. void addTargets(int nTargets); // Bit-or. void setName(const std::string& strName); void setCarPreviewFileName(const std::string& strFileName); protected: - int _nTargets; // Skin targets bit-field (see car.h for possible values) + int _bfTargets; // Skin targets bit-field (see car.h for possible values) std::string _strName; // Skin name (empty if standard skin) std::string _strCarPreviewFileName; // Car preview for this skin name (empty if none) }; diff --git a/src/modules/graphic/ssggraph/grcar.cpp b/src/modules/graphic/ssggraph/grcar.cpp index 974355d9..8cf1c9ad 100644 --- a/src/modules/graphic/ssggraph/grcar.cpp +++ b/src/modules/graphic/ssggraph/grcar.cpp @@ -599,10 +599,20 @@ grInitCar(tCarElt *car) GfLogTrace("Using skinned interior %s\n", strTgtTexName.c_str()); } - /* 3) 3D wheels if present */ + /* 3) driver if present */ + if (bCustomSkin && car->_skinTargets & RM_CAR_SKIN_TARGET_DRIVER) + { + strSrcTexName = "driver"; // Warning: Must be consistent with wheel.ac/.acc contents + strTgtTexName = strSrcTexName + '-' + car->_skinName + pszTexFileExt; + strSrcTexName += pszTexFileExt; + options.addTextureMapping(strSrcTexName.c_str(), strTgtTexName.c_str()); + GfLogTrace("Using skinned driver %s\n", strTgtTexName.c_str()); + } + + /* 4) 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 + strSrcTexName = "wheel3d"; // Warning: Must be consistent with .ac/.acc contents strTgtTexName = strSrcTexName + '-' + car->_skinName + pszTexFileExt; strSrcTexName += pszTexFileExt; options.addTextureMapping(strSrcTexName.c_str(), strTgtTexName.c_str());