From ee42f9b62edbf4b9574ba7b431a8ddc63b8b7493 Mon Sep 17 00:00:00 2001 From: pouillot Date: Sun, 27 Feb 2011 10:47:31 +0000 Subject: [PATCH] Re #313 (Split Windows installer) Make Single event races work when some of the XML-specified drivers are not available git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3405 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: d131228896f7eb30eb1404dd80534cb0931b52bd Former-commit-id: aaabba6f24ffa73506b65aef9261b54e23b131a0 --- src/libs/raceengineclient/raceinit.cpp | 3 +- src/libs/raceengineclient/racemain.cpp | 4 +- src/libs/tgfdata/race.cpp | 104 ++++++++++++------------- src/libs/tgfdata/racemanagers.cpp | 14 ++-- 4 files changed, 61 insertions(+), 64 deletions(-) diff --git a/src/libs/raceengineclient/raceinit.cpp b/src/libs/raceengineclient/raceinit.cpp index 078061714..ea10a4510 100644 --- a/src/libs/raceengineclient/raceinit.cpp +++ b/src/libs/raceengineclient/raceinit.cpp @@ -223,10 +223,9 @@ void ReStartNewRace(void * /* dummy */) { // Save the race settings to the race manager file is anything changed. - GfLogDebug("ReStartNewRace: _reName='%s', dirty=%d\n", ReInfo->_reName, PReRace->isDirty()); if (PReRace->isDirty()) { - ReGetRace()->store(); // Save data to params. + PReRace->store(); // Save data to params. GfParmWriteFile(NULL, ReInfo->params, ReInfo->_reName); // Save params to disk. } diff --git a/src/libs/raceengineclient/racemain.cpp b/src/libs/raceengineclient/racemain.cpp index 93f2c1fd7..36bf69d1e 100644 --- a/src/libs/raceengineclient/racemain.cpp +++ b/src/libs/raceengineclient/racemain.cpp @@ -177,8 +177,8 @@ ReRaceEventInit(void) /* Read the new params */ ReInfo->params = GfParmReadFile( GfParmGetStr( ReInfo->mainResults, RE_SECT_CURRENT, RE_ATTR_CUR_FILE, "" ), GFPARM_RMODE_STD ); - GfLogDebug( "ReInfo->mainResults : curfile = %s\n", - GfParmGetStr( ReInfo->mainResults, RE_SECT_CURRENT, RE_ATTR_CUR_FILE, "" ) ); + GfLogDebug("Career : ReInfo->mainResults gives curfile = %s\n", + GfParmGetStr( ReInfo->mainResults, RE_SECT_CURRENT, RE_ATTR_CUR_FILE, "")); if (!params) GfLogWarning( "Params weren't read correctly !!!\n" ); params = ReInfo->params; diff --git a/src/libs/tgfdata/race.cpp b/src/libs/tgfdata/race.cpp index 52b8686ca..8dfb542ae 100644 --- a/src/libs/tgfdata/race.cpp +++ b/src/libs/tgfdata/race.cpp @@ -390,10 +390,11 @@ void GfRace::load(GfRaceManager* pRaceMan, void* hparmResults) // hparmStartGrid == hparmResults ? "hRes" : GfParmGetFileName(hparmStartGrid)); std::ostringstream ossDrvSecPath; - int nCompIndex = bReversedGrid ? nCompetitors : 1; const int nCompIndexDelta = bReversedGrid ? -1 : +1; const int nEndCompIndex = bReversedGrid ? 0 : nCompetitors + 1; - while (nCompIndex != nEndCompIndex) + int nCompIndex = bReversedGrid ? nCompetitors : 1; + nCompIndex -= nCompIndexDelta; + while ((nCompIndex += nCompIndexDelta) != nEndCompIndex) { // Get driver infos from the the starting grid. ossDrvSecPath.str(""); @@ -414,62 +415,58 @@ void GfRace::load(GfRaceManager* pRaceMan, void* hparmResults) continue; } - // We've got it : if we can keep it for the race, make it a competitor - // (there is a threshold on the number of competitors) : - if (acceptsMoreCompetitors()) - { - const char* pszSkinName = - GfParmGetStr(hparmStartGrid, ossDrvSecPath.str().c_str(), RM_ATTR_SKINNAME, ""); - const int nSkinTargets = - (int)GfParmGetNum(hparmStartGrid, ossDrvSecPath.str().c_str(), RM_ATTR_SKINTARGETS, NULL, 0); - const bool bExtended = - GfParmGetNum(hparmStartGrid, ossDrvSecPath.str().c_str(), RM_ATTR_EXTENDED, NULL, 0) - ? true : false; - - // Get the chosen car for the race if any specified (extended drivers only). - const GfCar* pCarForRace = 0; - if (bExtended) - { - ossDrvSecPath.str(""); - ossDrvSecPath << RM_SECT_DRIVERINFO << '/' << pszModName - << '/' << (bExtended ? 1 : 0) << '/' << nItfIndex; - const char* pszCarId = - GfParmGetStr(hparmRaceMan, ossDrvSecPath.str().c_str(), RM_ATTR_CARNAME, ""); - pCarForRace = GfCars::self()->getCar(pszCarId); - } -// GfLogDebug("GfRace::load(...) : car=%s (%s)\n", -// pCarForRace ? pCarForRace->getName().c_str() : pCompetitor->getCar()->getName().c_str(), -// pCarForRace ? "extended" : "standard"); - - // Update the driver. - GfDriverSkin skin(pszSkinName); - skin.setTargets(nSkinTargets); - pCompetitor->setSkin(skin); - if (pCarForRace) // Override default car with the one chosen for the race if any. - pCompetitor->setCar(pCarForRace); - - // Check if this driver can compete in this race. - if (acceptsDriverType(pCompetitor->getType()) - && acceptsCarCategory(pCompetitor->getCar()->getCategoryId())) - { - // Update the GfRace. - appendCompetitor(pCompetitor); - } - else - { - GfLogWarning("Ignoring '%s' (%s' #%d) : Type or car category not accepted by the race\n", - pCompetitor->getName().c_str(), pszModName, nItfIndex); - } - } - else + // We've got it but can't keep it for the race, + // because there is a threshold on the number of competitors. + if (!acceptsMoreCompetitors()) { GfLogWarning("Ignoring subsequent competitors (max=%u)\n", _pPrivate->nMaxCompetitors); break; } - // Next driver in the starting grid. - nCompIndex += nCompIndexDelta; + // We've got it and can keep it for the race => make it a competitor + const char* pszSkinName = + GfParmGetStr(hparmStartGrid, ossDrvSecPath.str().c_str(), RM_ATTR_SKINNAME, ""); + const int nSkinTargets = + (int)GfParmGetNum(hparmStartGrid, ossDrvSecPath.str().c_str(), RM_ATTR_SKINTARGETS, NULL, 0); + const bool bExtended = + GfParmGetNum(hparmStartGrid, ossDrvSecPath.str().c_str(), RM_ATTR_EXTENDED, NULL, 0) + ? true : false; + + // Get the chosen car for the race if any specified (extended drivers only). + const GfCar* pCarForRace = 0; + if (bExtended) + { + ossDrvSecPath.str(""); + ossDrvSecPath << RM_SECT_DRIVERINFO << '/' << pszModName + << '/' << (bExtended ? 1 : 0) << '/' << nItfIndex; + const char* pszCarId = + GfParmGetStr(hparmRaceMan, ossDrvSecPath.str().c_str(), RM_ATTR_CARNAME, ""); + pCarForRace = GfCars::self()->getCar(pszCarId); + } + // GfLogDebug("GfRace::load(...) : car=%s (%s)\n", + // pCarForRace ? pCarForRace->getName().c_str() : pCompetitor->getCar()->getName().c_str(), + // pCarForRace ? "extended" : "standard"); + + // Update the driver. + GfDriverSkin skin(pszSkinName); + skin.setTargets(nSkinTargets); + pCompetitor->setSkin(skin); + if (pCarForRace) // Override default car with the one chosen for the race if any. + pCompetitor->setCar(pCarForRace); + + // Check if this driver can compete in this race. + if (acceptsDriverType(pCompetitor->getType()) + && acceptsCarCategory(pCompetitor->getCar()->getCategoryId())) + { + // Update the GfRace. + appendCompetitor(pCompetitor); + } + else + { + GfLogWarning("Ignoring '%s' (%s' #%d) : Type or car category not accepted by the race\n", + pCompetitor->getName().c_str(), pszModName, nItfIndex); + } } // Load focused competitor data from the raceman params. @@ -855,10 +852,11 @@ bool GfRace::moveCompetitor(GfDriver* pComp, int nDeltaPlace) return false; // Remove the competitor from his place. + const int nOldIndex = itComp - _pPrivate->vecCompetitors.begin(); _pPrivate->vecCompetitors.erase(itComp); // Determine his new place. - const int nNewIndex = (itComp - _pPrivate->vecCompetitors.begin()) + nDeltaPlace; + const int nNewIndex = nOldIndex + nDeltaPlace; if (nNewIndex < 0) itComp = _pPrivate->vecCompetitors.begin(); else if (nNewIndex >= (int)_pPrivate->vecCompetitors.size()) diff --git a/src/libs/tgfdata/racemanagers.cpp b/src/libs/tgfdata/racemanagers.cpp index c08342e06..54c519030 100755 --- a/src/libs/tgfdata/racemanagers.cpp +++ b/src/libs/tgfdata/racemanagers.cpp @@ -343,8 +343,8 @@ void GfRaceManager::load() const ossSectionPath.str(""); ossSectionPath << RM_SECT_TRACKS << '/' << nEventNum; pszTrackId = GfParmGetStr(hparmHandle, ossSectionPath.str().c_str(), RM_ATTR_NAME, 0); - GfLogDebug("GfRaceManager::reset(...): event[%d].track = '%s'\n", - nEventNum-1, pszTrackId); +// GfLogDebug("GfRaceManager::reset(...): event[%d].track = '%s'\n", +// nEventNum-1, pszTrackId); // If not end of event list : if (pszTrackId) @@ -405,7 +405,7 @@ void GfRaceManager::load() const ossSecPath << RM_SECT_RACES << '/' << nSessionInd; const char* pszSessionName = GfParmGetStr(hparmHandle, ossSecPath.str().c_str(), RM_ATTR_NAME, 0); - GfLogDebug("GfRaceManager::reset(...): session '%s'\n", pszSessionName); +// GfLogDebug("GfRaceManager::reset(...): session '%s'\n", pszSessionName); if (pszSessionName && strlen(pszSessionName) > 0) _vecSessionNames.push_back(pszSessionName); @@ -432,8 +432,8 @@ void GfRaceManager::store() std::ostringstream ossSectionPath; for (unsigned nEventInd = 0; nEventInd < _vecEventTrackIds.size(); nEventInd++) { - GfLogDebug("GfRaceManager::store(%s): event[%u].track = '%s'\n", - _strName.c_str(), nEventInd, _vecEventTrackIds[nEventInd].c_str()); +// GfLogDebug("GfRaceManager::store(%s): event[%u].track = '%s'\n", +// _strName.c_str(), nEventInd, _vecEventTrackIds[nEventInd].c_str()); ossSectionPath.str(""); ossSectionPath << RM_SECT_TRACKS << '/' << nEventInd + 1; GfParmSetStr(_hparmHandle, ossSectionPath.str().c_str(), RM_ATTR_NAME, @@ -567,8 +567,8 @@ void GfRaceManager::setEventTrack(unsigned nEventIndex, GfTrack* pTrack) nEventIndex = _vecEventTrackIds.size() - 1; _vecEventTrackIds[nEventIndex] = pTrack->getId(); - GfLogDebug("GfRaceManager::setEventTrack(evt #%u, track '%s')\n", - nEventIndex, pTrack->getId().c_str()); +// GfLogDebug("GfRaceManager::setEventTrack(evt #%u, track '%s')\n", +// nEventIndex, pTrack->getId().c_str()); // Now we are no more consistent with the race managers params (in memory). _bIsDirty = true;