forked from speed-dreams/speed-dreams-code
Re #139 (Task D30) Save human car choice also in <module>.xml as a default in case no human in race + Re #138 (Task D29) Fixed crash on ESC in Car Selection / Settings menu + cosmetic on some trace messages
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2666 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: bda1a31c5eff77f502bf8a523e60157878b2830e Former-commit-id: 681347b4b998d3cff39e2a829d386ba0e1f41627
This commit is contained in:
parent
49e586fc15
commit
90e1ece910
9 changed files with 85 additions and 56 deletions
|
@ -321,7 +321,8 @@ int moduleWelcomeV1_00
|
|||
memset(DriverNames, 0, MAXNBBOTS*DRIVERLEN);
|
||||
memset(DriverDescs, 0, MAXNBBOTS*DRIVERLEN);
|
||||
|
||||
GfOut("\n#Interface Version: %d.%d\n",
|
||||
GfOut("\n");
|
||||
GfOut("#Interface Version: %d.%d\n",
|
||||
welcomeIn->itfVerMajor,welcomeIn->itfVerMinor);
|
||||
|
||||
// Get filehandle for robot's xml-file
|
||||
|
@ -330,7 +331,7 @@ int moduleWelcomeV1_00
|
|||
if (RobotSettings)
|
||||
{
|
||||
GfOut("#Robot name : %s\n",RobName);
|
||||
GfOut("#Robot directory : %s\n",RobPathDir);
|
||||
GfOut("#Robot directory : %s\n",RobPathDir);
|
||||
GfOut("#Robot XML-file : %s\n",RobPathXML);
|
||||
|
||||
char Buffer[BUFSIZE];
|
||||
|
@ -422,8 +423,9 @@ extern "C" int moduleWelcome
|
|||
return moduleWelcomeV1_00(welcomeIn, welcomeOut);
|
||||
}
|
||||
|
||||
GfOut("\n#Unhandled Interface Version: %d.%d\n",
|
||||
welcomeIn->itfVerMajor,welcomeIn->itfVerMinor);
|
||||
GfOut("\n");
|
||||
GfOut("#Unhandled Interface Version: %d.%d\n",
|
||||
welcomeIn->itfVerMajor,welcomeIn->itfVerMinor);
|
||||
welcomeOut->maxNbItf = 0;
|
||||
return -1;
|
||||
}
|
||||
|
@ -438,7 +440,8 @@ extern "C" int moduleWelcome
|
|||
//--------------------------------------------------------------------------*
|
||||
extern "C" int moduleInitialize(tModInfo *ModInfo)
|
||||
{
|
||||
GfOut("\n#Initialize from %s ...\n",RobPathXML);
|
||||
GfOut("\n");
|
||||
GfOut("#Initialize from %s ...\n",RobPathXML);
|
||||
GfOut("#NBBOTS: %d (of %d)\n",NBBOTS,MAXNBBOTS);
|
||||
|
||||
#ifdef ROB_SECT_ARBITRARY
|
||||
|
@ -485,7 +488,8 @@ extern "C" int moduleInitialize(tModInfo *ModInfo)
|
|||
//--------------------------------------------------------------------------*
|
||||
extern "C" int moduleTerminate()
|
||||
{
|
||||
GfOut("\n#Terminated %s\n",RobName);
|
||||
GfOut("\n");
|
||||
GfOut("#Terminated %s\n",RobName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -496,7 +500,8 @@ extern "C" int moduleTerminate()
|
|||
//--------------------------------------------------------------------------*
|
||||
int simplixEntryPoint(tModInfo *ModInfo, void *RobotSettings)
|
||||
{
|
||||
GfOut("\n#Torcs backward compatibility scheme used\n");
|
||||
GfOut("\n");
|
||||
GfOut("#Torcs backward compatibility scheme used\n");
|
||||
NBBOTS = MIN(10,NBBOTS);
|
||||
|
||||
memset(ModInfo, 0, NBBOTS*sizeof(tModInfo));
|
||||
|
@ -781,7 +786,9 @@ static void Shutdown(int Index)
|
|||
tInstanceInfo *copy;
|
||||
#endif //ROB_SECT_ARBITRARY
|
||||
|
||||
GfOut("\n\n#Clock\n");
|
||||
GfOut("\n");
|
||||
GfOut("\n");
|
||||
GfOut("#Clock\n");
|
||||
GfOut("#Total Time used: %g sec\n",cInstances[Index-IndexOffset].cTicks/1000.0);
|
||||
GfOut("#Min Time used: %g msec\n",cInstances[Index-IndexOffset].cMinTicks);
|
||||
GfOut("#Max Time used: %g msec\n",cInstances[Index-IndexOffset].cMaxTicks);
|
||||
|
@ -789,8 +796,8 @@ static void Shutdown(int Index)
|
|||
GfOut("#Long Time Steps: %d\n",cInstances[Index-IndexOffset].cLongSteps);
|
||||
GfOut("#Critical Steps : %d\n",cInstances[Index-IndexOffset].cCriticalSteps);
|
||||
GfOut("#Unused Steps : %d\n",cInstances[Index-IndexOffset].cUnusedCount);
|
||||
|
||||
GfOut("\n\n#");
|
||||
GfOut("\n");
|
||||
GfOut("\n");
|
||||
|
||||
cInstances[Index-IndexOffset].cRobot->Shutdown();
|
||||
delete cInstances[Index-IndexOffset].cRobot;
|
||||
|
|
|
@ -181,7 +181,8 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* wel
|
|||
// Module entry point (new fixed name scheme).
|
||||
extern "C" int moduleInitialize(tModInfo *modInfo)
|
||||
{
|
||||
GfOut("\n\n\nInitialize from %s ...\n",pathXml);
|
||||
GfOut("\n\n");
|
||||
GfOut("Initialize from %s ...\n",pathXml);
|
||||
GfOut("NBBOTS: %d (of %d)\n",NBBOTS,MAXNBBOTS);
|
||||
int i;
|
||||
|
||||
|
|
|
@ -181,7 +181,8 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* wel
|
|||
// Module entry point (new fixed name scheme).
|
||||
extern "C" int moduleInitialize(tModInfo *modInfo)
|
||||
{
|
||||
GfOut("\n\n\nInitialize from %s ...\n",pathXml);
|
||||
GfOut("\n\n");
|
||||
GfOut("Initialize from %s ...\n",pathXml);
|
||||
GfOut("NBBOTS: %d (of %d)\n",NBBOTS,MAXNBBOTS);
|
||||
int i;
|
||||
|
||||
|
|
|
@ -181,7 +181,8 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* wel
|
|||
// Module entry point (new fixed name scheme).
|
||||
extern "C" int moduleInitialize(tModInfo *modInfo)
|
||||
{
|
||||
GfOut("\n\n\nInitialize from %s ...\n",pathXml);
|
||||
GfOut("\n\n");
|
||||
GfOut("Initialize from %s ...\n",pathXml);
|
||||
GfOut("NBBOTS: %d (of %d)\n",NBBOTS,MAXNBBOTS);
|
||||
int i;
|
||||
|
||||
|
|
|
@ -181,7 +181,8 @@ extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* wel
|
|||
// Module entry point (new fixed name scheme).
|
||||
extern "C" int moduleInitialize(tModInfo *modInfo)
|
||||
{
|
||||
GfOut("\n\n\nInitialize from %s ...\n",pathXml);
|
||||
GfOut("\n\n");
|
||||
GfOut("Initialize from %s ...\n",pathXml);
|
||||
GfOut("NBBOTS: %d (of %d)\n",NBBOTS,MAXNBBOTS);
|
||||
int i;
|
||||
|
||||
|
|
|
@ -191,8 +191,8 @@ void RmCarSelectMenu::resetCarCategoryComboBox(const std::string& strSelectedCat
|
|||
// Select the requested category in the combo-box.
|
||||
GfuiComboboxSetSelectedIndex(GetMenuHandle(), nCategoryComboId, nCurrentCategoryIndex);
|
||||
|
||||
GfLogDebug("resetCarCategoryComboBox(%s) : cur=%d\n",
|
||||
strSelectedCategoryName.c_str(), nCurrentCategoryIndex);
|
||||
//GfLogDebug("resetCarCategoryComboBox(%s) : cur=%d\n",
|
||||
// strSelectedCategoryName.c_str(), nCurrentCategoryIndex);
|
||||
}
|
||||
|
||||
void RmCarSelectMenu::resetCarModelComboBox(const std::string& strCategoryName,
|
||||
|
@ -222,18 +222,15 @@ void RmCarSelectMenu::resetCarModelComboBox(const std::string& strCategoryName,
|
|||
// Select the right car in the combo-box.
|
||||
GfuiComboboxSetSelectedIndex(GetMenuHandle(), nModelComboId, nCurrentCarIndexInCategory);
|
||||
|
||||
GfLogDebug("resetCarModelComboBox(cat=%s, selCar=%s) : cur=%d (nCarsInCat=%d)\n",
|
||||
strCategoryName.c_str(), strSelectedCarRealName.c_str(),
|
||||
nCurrentCarIndexInCategory, vecCarsInCat.size());
|
||||
//GfLogDebug("resetCarModelComboBox(cat=%s, selCar=%s) : cur=%d (nCarsInCat=%d)\n",
|
||||
// strCategoryName.c_str(), strSelectedCarRealName.c_str(),
|
||||
// nCurrentCarIndexInCategory, vecCarsInCat.size());
|
||||
}
|
||||
|
||||
void RmCarSelectMenu::resetCarDataSheet(const std::string& strSelectedCarName)
|
||||
{
|
||||
// TODO : Merge params with category / user settings ?
|
||||
|
||||
// Close old car params.
|
||||
GfParmReleaseHandle(getSelectedCarParamsHandle());
|
||||
|
||||
// Open new car params.
|
||||
std::ostringstream ossCarXMLFileName;
|
||||
ossCarXMLFileName << "cars/" << strSelectedCarName << '/' << strSelectedCarName << ".xml";
|
||||
|
@ -347,7 +344,6 @@ void RmCarSelectMenu::RunMenu(trmdDrvElt* pDriver)
|
|||
|
||||
bool RmCarSelectMenu::Initialize()
|
||||
{
|
||||
GfLogDebug("RmCarSelectMenu::Init\n");
|
||||
//CarInfo::self()->print();
|
||||
|
||||
// Create the menu and all its controls.
|
||||
|
@ -403,6 +399,15 @@ void RmCarSelectMenu::setDriver(trmdDrvElt* pDriver)
|
|||
|
||||
void RmCarSelectMenu::setSelectedCarParamsHandle(void* hdle)
|
||||
{
|
||||
if (!hdle)
|
||||
return;
|
||||
|
||||
// Close old car params if not null and not the current driver's one
|
||||
// (and if it really changes).
|
||||
if (_hCarParams && _hCarParams != _pDriver->carParmHdle && _hCarParams != hdle)
|
||||
GfParmReleaseHandle(_hCarParams);
|
||||
|
||||
// Store the new one.
|
||||
_hCarParams = hdle;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ static const char* pszSkinFileExt = ".png";
|
|||
static const char* pszPreviewFileSuffix = "-preview.jpg";
|
||||
|
||||
static const char* apszExcludedSkinFileSuffixes[] =
|
||||
{ "-rpm.png", "-speed.png", pszPreviewFileSuffix };
|
||||
{ "-rpm.png", "-speed.png" , "-int.png" };
|
||||
static const int nExcludedSkinFileSuffixes = sizeof(apszExcludedSkinFileSuffixes) / sizeof(char*);
|
||||
|
||||
|
||||
|
@ -86,7 +86,7 @@ void rmdGetCarSkinsInFolder(const char* pszCarName, const char* pszFolderPath,
|
|||
//struct stat st;
|
||||
tFList *pSkinFileList, *pCurSkinFile;
|
||||
|
||||
//GfOut("rmdGetCarSkinsInFolder(%s) :\n", pszFolderPath);
|
||||
//GfLogDebug("rmdGetCarSkinsInFolder(%s) :\n", pszFolderPath);
|
||||
|
||||
pCurSkinFile = pSkinFileList =
|
||||
GfDirGetListFiltered(pszFolderPath, pszCarName, pszSkinFileExt);
|
||||
|
@ -133,10 +133,10 @@ void rmdGetCarSkinsInFolder(const char* pszCarName, const char* pszFolderPath,
|
|||
|
||||
struct stat st;
|
||||
if (stat(ossPreviewName.str().c_str(), &st))
|
||||
GfError("No preview file %s found for '%s' skin\n",
|
||||
ossPreviewName.str().c_str(), strSkinName.c_str());
|
||||
GfLogWarning("No preview file %s found for '%s' skin\n",
|
||||
ossPreviewName.str().c_str(), strSkinName.c_str());
|
||||
|
||||
//GfOut("* found skin=%s, preview=%s\n",
|
||||
//GfLogDebug("* found skin=%s, preview=%s\n",
|
||||
// strSkinName.c_str(), ossPreviewName.str().c_str());
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ void rmdGetCarSkinsInSearchPath(const trmdDrvElt *pDriver, const char* pszForced
|
|||
std::ostringstream ossDirPath;
|
||||
std::string strPreviewName;
|
||||
|
||||
//GfOut("rmdGetCarSkinsInSearchPath : module=%s, idx=%d, car=%s ...\n",
|
||||
//GfLogDebug("rmdGetCarSkinsInSearchPath : module=%s, idx=%d, car=%s ...\n",
|
||||
// pDriver->moduleName, pDriver->interfaceIndex, pszCarName);
|
||||
|
||||
// Clear the skin and preview lists.
|
||||
|
@ -214,8 +214,8 @@ void rmdGetCarSkinsInSearchPath(const trmdDrvElt *pDriver, const char* pszForced
|
|||
// (that way, the skin list will never be empty, and that's safer)
|
||||
else
|
||||
{
|
||||
GfError("No skin found for '%s/%d/%s' : adding dummy '%s' one\n",
|
||||
pDriver->moduleName, pDriver->interfaceIndex, pszCarName, rmdStdSkinName);
|
||||
GfLogWarning("No skin found for '%s/%d/%s' : adding dummy '%s' one\n",
|
||||
pDriver->moduleName, pDriver->interfaceIndex, pszCarName, rmdStdSkinName);
|
||||
|
||||
// Skin.
|
||||
vecSkinNames.push_back(rmdStdSkinName);
|
||||
|
@ -228,8 +228,8 @@ void rmdGetCarSkinsInSearchPath(const trmdDrvElt *pDriver, const char* pszForced
|
|||
|
||||
struct stat st;
|
||||
if (stat(ossPreviewName.str().c_str(), &st))
|
||||
GfError("No preview file %s found for '%s' skin\n",
|
||||
ossPreviewName.str().c_str(), rmdStdSkinName);
|
||||
GfLogWarning("No preview file %s found for '%s' skin\n",
|
||||
ossPreviewName.str().c_str(), rmdStdSkinName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -206,18 +206,17 @@ rmdsSetFocus(void * /* dummy */)
|
|||
static void
|
||||
rmdsNextMenu(void * /* dummy */)
|
||||
{
|
||||
char drvSec[256];
|
||||
char buffer[256];
|
||||
char drvSec[32];
|
||||
char drvInfoSec[64];
|
||||
const char *name;
|
||||
trmdDrvElt *curDrv;
|
||||
int index;
|
||||
|
||||
// Clear the race starting grid.
|
||||
GfParmListClean(MenuData->param, RM_SECT_DRIVERS);
|
||||
|
||||
// And then rebuild it from the current Competitors scroll list state
|
||||
// (for each competitor, module name, interface index, car name if human, skin name if any).
|
||||
index = 1;
|
||||
int index = 1;
|
||||
while ((name = GfuiScrollListExtractElement(ScrHandle, CompetitorsScrollListId,
|
||||
0, (void**)&curDrv))) {
|
||||
sprintf(drvSec, "%s/%d", RM_SECT_DRIVERS, index);
|
||||
|
@ -225,14 +224,27 @@ rmdsNextMenu(void * /* dummy */)
|
|||
GfParmSetStr(MenuData->param, drvSec, RM_ATTR_MODULE, curDrv->moduleName);
|
||||
if (curDrv->carName && curDrv->isHuman)
|
||||
{
|
||||
// TODO: Save chosen car as the default/prefered one in human.xml ?
|
||||
GfParmSetNum(MenuData->param, drvSec, RM_ATTR_EXTENDED, NULL, 1); /* Set extended */
|
||||
sprintf( buffer, "%s/%s/%d/%d", RM_SECT_DRIVERINFO, curDrv->moduleName, 1 /*extended*/, curDrv->interfaceIndex );
|
||||
GfParmSetStr(MenuData->param, buffer, RM_ATTR_CARNAME, curDrv->carName);
|
||||
sprintf(drvInfoSec, "%s/%s/%d/%d", RM_SECT_DRIVERINFO, curDrv->moduleName,
|
||||
1 /*extended*/, curDrv->interfaceIndex );
|
||||
GfParmSetStr(MenuData->param, drvInfoSec, RM_ATTR_CARNAME, curDrv->carName);
|
||||
|
||||
// Save also the chosen car as the default one for this human driver
|
||||
// (may be needed later for races where it is not specified in <race>.xml)
|
||||
char robParamsPath[256];
|
||||
sprintf(robParamsPath, "%sdrivers/%s/%s.xml",
|
||||
GetLocalDir(), curDrv->moduleName, curDrv->moduleName);
|
||||
void* robHdle = GfParmReadFile(robParamsPath, GFPARM_RMODE_STD);
|
||||
char robSec[32];
|
||||
sprintf(robSec, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, curDrv->interfaceIndex);
|
||||
GfParmSetStr(robHdle, robSec, ROB_ATTR_CAR, curDrv->carName);
|
||||
GfParmWriteFile(NULL, robHdle, curDrv->moduleName);
|
||||
GfParmReleaseHandle(robHdle);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfParmSetNum(MenuData->param, drvSec, RM_ATTR_EXTENDED, NULL, 0); /*No extended for robots yet in driverconfig*/
|
||||
/* Not extended for robots yet in driverconfig */
|
||||
GfParmSetNum(MenuData->param, drvSec, RM_ATTR_EXTENDED, NULL, 0);
|
||||
}
|
||||
if ((curDrv->skinName && strcmp(curDrv->skinName, rmdStdSkinName))
|
||||
|| GfParmGetStr(MenuData->param, drvSec, RM_ATTR_SKINNAME, 0))
|
||||
|
@ -562,7 +574,8 @@ RmDriversSelect(void *vs)
|
|||
robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD);
|
||||
}
|
||||
if (!robhdle) {
|
||||
GfError("No driver '%s' selected because no readable '%s.xml' found\n", modName, modName);
|
||||
GfLogError("No driver '%s' selected because no readable '%s.xml' found\n",
|
||||
modName, modName);
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < curmod->modInfoSize; i++) {
|
||||
|
@ -577,7 +590,7 @@ RmDriversSelect(void *vs)
|
|||
curDrv = (trmdDrvElt*)calloc(1, sizeof(trmdDrvElt));
|
||||
curDrv->interfaceIndex = curmod->modInfo[i].index;
|
||||
curDrv->moduleName = strdup(modName);
|
||||
curDrv->carName = strdup(carName);
|
||||
curDrv->carName = strdup(carName); // Default one if not specified in race file.
|
||||
curDrv->skinName = 0; // Initialized later if needed from race params.
|
||||
curDrv->name = strdup(curmod->modInfo[i].name);
|
||||
curDrv->carParmHdle = carhdle;
|
||||
|
@ -670,14 +683,14 @@ RmDriversSelect(void *vs)
|
|||
free(curDrv->carName);
|
||||
curDrv->carName = strdup(carName);
|
||||
} else {
|
||||
GfError("Falling back to default car '%s' "
|
||||
"for %s because '%s' is not readable\n",
|
||||
curDrv->carName, curDrv->name, path);
|
||||
GfLogError("Falling back to default car '%s' "
|
||||
"for %s because '%s' is not readable\n",
|
||||
curDrv->carName, curDrv->name, path);
|
||||
}
|
||||
} else {
|
||||
GfError("Falling back to default car '%s' "
|
||||
"for %s because '%s' was not found\n",
|
||||
curDrv->carName, curDrv->name, path);
|
||||
GfLogError("Falling back to default car '%s' "
|
||||
"for %s because '%s' was not found\n",
|
||||
curDrv->carName, curDrv->name, path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,8 +72,8 @@ CarInfo::CarInfo()
|
|||
ossCarFileName << "cars/" << pszCarName << '/' << pszCarName << ".xml";
|
||||
carParmHdle = GfParmReadFile(ossCarFileName.str().c_str(), GFPARM_RMODE_STD);
|
||||
if (!carParmHdle) {
|
||||
GfError("CarInfo : Ignoring car %s (failed to read from %s)\n",
|
||||
pszCarName, ossCarFileName.str().c_str());
|
||||
GfLogWarning("CarInfo : Ignoring car %s (failed to read from %s)\n",
|
||||
pszCarName, ossCarFileName.str().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -182,19 +182,19 @@ CarData* CarInfo::GetCarData(const std::string& strCarName) const
|
|||
|
||||
void CarInfo::print() const
|
||||
{
|
||||
GfOut("CarInfo : %d cars, %d categories\n",
|
||||
m_priv->vecCars.size(), m_priv->setCategoryNames.size());
|
||||
GfLogDebug("CarInfo : %d cars, %d categories\n",
|
||||
m_priv->vecCars.size(), m_priv->setCategoryNames.size());
|
||||
std::set<std::string>::const_iterator iterCat;
|
||||
for (iterCat = m_priv->setCategoryNames.begin();
|
||||
iterCat != m_priv->setCategoryNames.end(); iterCat++)
|
||||
{
|
||||
GfOut(" %s category :\n", iterCat->c_str());
|
||||
GfLogDebug(" %s category :\n", iterCat->c_str());
|
||||
const std::vector<CarData> vecCarsInCat = GetCarsInCategory(iterCat->c_str());
|
||||
std::vector<CarData>::const_iterator iterCar;
|
||||
for (iterCar = vecCarsInCat.begin(); iterCar != vecCarsInCat.end(); iterCar++)
|
||||
{
|
||||
GfOut(" %s (%s) : %s\n",
|
||||
iterCar->strRealName.c_str(), iterCar->strName.c_str(), iterCar->strXMLPath.c_str());
|
||||
GfLogDebug(" %s (%s) : %s\n", iterCar->strRealName.c_str(),
|
||||
iterCar->strName.c_str(), iterCar->strXMLPath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue