Re #138 : Temporary Ruin'dows / MSWC port workaround for r2595 commit (needs a real fix)

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

Former-commit-id: fd2ea001e03b5f9fa7e39cb6acbe81a5c7ab4b8a
Former-commit-id: 461e78742273f3019096d92a779f86d9f3e6a79f
This commit is contained in:
pouillot 2010-08-03 19:23:24 +00:00
parent 009eec38c8
commit 05c6389d7d
3 changed files with 180 additions and 13 deletions

View file

@ -36,12 +36,14 @@
// Some consts.
const char* rmdStdSkinName = "standard";
static const char* pszSkinFileExt = ".png";
static const char* pszPreviewFileSuffix = "-preview.png";
static const char* apszExcludedSkinFileSuffixes[] =
{ "-rpm.png", "-speed.png", pszPreviewFileSuffix };
static const int nExcludedSkinFileSuffixes = sizeof(apszExcludedSkinFileSuffixes) / sizeof(char*);
// Temporary workaround for MS shit : moved to driverselect.cpp
// static const char* pszSkinFileExt = ".png";
// static const char* pszPreviewFileSuffix = "-preview.png";
// static const char* apszExcludedSkinFileSuffixes[] =
// { "-rpm.png", "-speed.png", pszPreviewFileSuffix };
// static const int nExcludedSkinFileSuffixes = sizeof(apszExcludedSkinFileSuffixes) / sizeof(char*);
int rmdDriverMatchesFilters(const trmdDrvElt *drv, const char* carCat, const char* drvTyp,
@ -76,6 +78,8 @@ void rmdGetDriverType(const char* moduleName, char* driverType, size_t maxSize)
}
}
// Temporary workaround for MS shit : moved to driverselect.cpp
#if 0
void rmdGetCarSkinsInFolder(const trmdDrvElt *pDriver, const char* pszFolderPath,
std::vector<std::string>& lstSkinNames,
std::vector<std::string>& lstPreviewFiles)
@ -147,7 +151,6 @@ void rmdGetCarSkinsInSearchPath(const trmdDrvElt *pDriver,
std::vector<std::string>& lstSkinNames,
std::vector<std::string>& lstPreviewFiles)
{
tFList *pSkinFileList, *pCurSkinFile;
std::ostringstream ossDirPath;
std::string strPreviewName;
@ -230,4 +233,4 @@ void rmdGetCarSkinsInSearchPath(const trmdDrvElt *pDriver,
}
}
}
#endif

View file

@ -53,13 +53,13 @@ extern void rmdGetDriverType(const char* moduleName, char* driverType, size_t ma
extern int rmdDriverMatchesFilters(const trmdDrvElt *drv, const char* carCat, const char* drvTyp,
const char* anyCarCat, const char* anyDrvTyp);
extern void rmdGetCarSkinsInFolder(const trmdDrvElt *pDriver, const char* pszFolderPath,
std::vector<std::string>& lstSkinNames,
std::vector<std::string>& lstPreviewFiles);
/* extern void rmdGetCarSkinsInFolder(const trmdDrvElt *pDriver, const char* pszFolderPath, */
/* std::vector<std::string>& lstSkinNames, */
/* std::vector<std::string>& lstPreviewFiles); */
extern void rmdGetCarSkinsInSearchPath(const trmdDrvElt *pDriver,
std::vector<std::string>& lstSkinNames,
std::vector<std::string>& lstPreviewFiles);
/* extern void rmdGetCarSkinsInSearchPath(const trmdDrvElt *pDriver, */
/* std::vector<std::string>& lstSkinNames, */
/* std::vector<std::string>& lstPreviewFiles); */
#endif /* __DRIVER_H__ */

View file

@ -92,6 +92,170 @@ static size_t CurSkinIndex = 0;
GF_TAILQ_HEAD(DriverListHead, trmdDrvElt);
static tDriverListHead DriverList;
// Functions and constants that should be in driver.h/cpp (temporary workaround for MS shit)
static const char* pszSkinFileExt = ".png";
static const char* pszPreviewFileSuffix = "-preview.png";
static const char* apszExcludedSkinFileSuffixes[] =
{ "-rpm.png", "-speed.png", pszPreviewFileSuffix };
static const int nExcludedSkinFileSuffixes = sizeof(apszExcludedSkinFileSuffixes) / sizeof(char*);
void rmdGetCarSkinsInFolder(const trmdDrvElt *pDriver, const char* pszFolderPath,
std::vector<std::string>& lstSkinNames,
std::vector<std::string>& lstPreviewFiles)
{
//struct stat st;
tFList *pSkinFileList, *pCurSkinFile;
GfOut("rmdGetCarSkinsInFolder(%s) :\n", pszFolderPath);
pCurSkinFile = pSkinFileList =
GfDirGetListFiltered(pszFolderPath, pDriver->carName, pszSkinFileExt);
if (pSkinFileList)
do
{
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.
const int nSkinNameLen = // Expecting "<car name>-<skin name>.png"
strlen(pCurSkinFile->name) - strlen(pDriver->carName) - 1 - strlen(pszSkinFileExt);
std::string strSkinName;
if (nSkinNameLen > 0)
strSkinName =
std::string(pCurSkinFile->name)
.substr(strlen(pDriver->carName) + 1, nSkinNameLen);
else // Assuming default/standard "<car name>.png"
strSkinName = rmdStdSkinName;
// Ignore skins that are already in the list (path search priority).
if (std::find(lstSkinNames.begin(), lstSkinNames.end(), strSkinName)
== lstSkinNames.end())
{
// Add found skin in the list
lstSkinNames.push_back(strSkinName);
// Add associated preview image
// (don't check file existence now, will be needed only at display time).
std::ostringstream ossPreviewName;
ossPreviewName << pszFolderPath << '/' << pDriver->carName;
if (strSkinName != rmdStdSkinName)
ossPreviewName << '-' << strSkinName;
ossPreviewName << pszPreviewFileSuffix;
//if (!stat(ossPreviewName.str().c_str(), &st))
{
lstPreviewFiles.push_back(ossPreviewName.str());
GfOut("* found skin=%s, preview=%s\n",
strSkinName.c_str(), ossPreviewName.str().c_str());
}
// else
// GfError("Ignoring '%s' skin for %s/%d/%s because preview file %s not found\n",
// strSkinName.c_str(), pDriver->moduleName, pDriver->interfaceIndex,
// pDriver->carName, ossPreviewName.str().c_str());
}
} while (pCurSkinFile != pSkinFileList);
GfDirFreeList(pSkinFileList, NULL);
}
void rmdGetCarSkinsInSearchPath(const trmdDrvElt *pDriver,
std::vector<std::string>& lstSkinNames,
std::vector<std::string>& lstPreviewFiles)
{
std::ostringstream ossDirPath;
std::string strPreviewName;
GfOut("rmdGetCarSkinsInSearchPath : module=%s, idx=%d, car=%s ...\n",
pDriver->moduleName, pDriver->interfaceIndex, pDriver->carName);
// Clear the skin and preview lists.
lstSkinNames.clear();
lstPreviewFiles.clear();
// Get skins/previews from the directories in the search path
// (WARNING: Must be consistent with the search path passed to ssgTexturePath in grcar.cpp,
// at least for the car skin file search).
ossDirPath.str("");
ossDirPath << GetLocalDir() << "drivers/" << pDriver->moduleName
<< '/' << pDriver->carName;
rmdGetCarSkinsInFolder(pDriver, ossDirPath.str().c_str(),
lstSkinNames, lstPreviewFiles);
ossDirPath.str("");
ossDirPath << "drivers/" << pDriver->moduleName
<< '/' << pDriver->interfaceIndex << '/' << pDriver->carName;
rmdGetCarSkinsInFolder(pDriver, ossDirPath.str().c_str(),
lstSkinNames, lstPreviewFiles);
ossDirPath.str("");
ossDirPath << "drivers/" << pDriver->moduleName
<< '/' << pDriver->interfaceIndex;
rmdGetCarSkinsInFolder(pDriver, ossDirPath.str().c_str(),
lstSkinNames, lstPreviewFiles);
ossDirPath.str("");
ossDirPath << "drivers/" << pDriver->moduleName
<< '/' << pDriver->carName;
rmdGetCarSkinsInFolder(pDriver, ossDirPath.str().c_str(),
lstSkinNames, lstPreviewFiles);
ossDirPath.str("");
ossDirPath << "drivers/" << pDriver->moduleName;
rmdGetCarSkinsInFolder(pDriver, ossDirPath.str().c_str(),
lstSkinNames, lstPreviewFiles);
ossDirPath.str("");
ossDirPath << "cars/" << pDriver->carName;
rmdGetCarSkinsInFolder(pDriver, ossDirPath.str().c_str(),
lstSkinNames, lstPreviewFiles);
// // If no skin was found, add the car's standard one, should always be there !
// if (lstSkinNames.empty())
// {
// // Skin.
// lstSkinNames.push_back(rmdStdSkinName);
// // Associated preview image.
// std::ostringstream ossPreviewName;
// ossPreviewName << "cars/" << pDriver->carName << '/' << pDriver->carName
// << pszPreviewFileSuffix;
// lstPreviewFiles.push_back(ossPreviewName.str());
// GfOut("... skin=<%s>, preview=%s\n",
// rmdStdSkinName, ossPreviewName.str().c_str());
// }
// If we have at least 1 skin, make sure that if the standard one is inside,
// it is the first one.
if (!lstSkinNames.empty())
{
std::vector<std::string>::iterator iterSkin =
std::find(lstSkinNames.begin(), lstSkinNames.end(), rmdStdSkinName);
if (iterSkin != lstSkinNames.end() && iterSkin != lstSkinNames.begin())
{
std::vector<std::string>::iterator iterPreview =
lstPreviewFiles.begin() + (iterSkin - lstSkinNames.begin());
strPreviewName = *iterPreview;
lstSkinNames.erase(iterSkin);
lstPreviewFiles.erase(iterPreview);
lstSkinNames.insert(lstSkinNames.begin(), rmdStdSkinName);
lstPreviewFiles.insert(lstPreviewFiles.begin(), strPreviewName);
}
}
}
// Local functions.
static void rmdsCleanup(void);
static void rmdsFilterDriverScrollList(const char* carCat, const char* driverType);