From 2a363cb01bbecb5bbc70ae8cc93fc079c7b4c44c Mon Sep 17 00:00:00 2001 From: pouillot Date: Sat, 16 Feb 2013 15:25:07 +0000 Subject: [PATCH] Re #784 New advanced CMake option OPTION_REPEATABLE_RANDOM + Fixed GCC 4.7 warnings in genparoptv1 + Renamed GfParmSetNumEx to GfParmSetNum (let's use overloading) git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5147 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: c50a9469f8248e33855198d7052d2936884507eb Former-commit-id: 8335e345c1863cf09c4479c05cd9f9af2073d35c --- cmake/options.cmake | 12 ++++++++ src/libs/tgf/params.cpp | 2 +- src/libs/tgf/tgf.h | 2 +- src/modules/racing/genparoptv1/genetic.cpp | 24 +++++++-------- src/modules/racing/genparoptv1/genetic.h | 4 +-- src/modules/racing/genparoptv1/racemain.cpp | 34 ++++++++------------- 6 files changed, 41 insertions(+), 37 deletions(-) diff --git a/cmake/options.cmake b/cmake/options.cmake index 2118608a2..8887a6e02 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -58,6 +58,9 @@ MACRO(ADD_SD_COMPILE_OPTIONS) SET(OPTION_TRACE_LEVEL "5" CACHE STRING "Trace level integer threshold, only if OPTION_TRACE (traces with higher level are not logged ; 0=Fatal, 1=Error, 2=Warning, 3=Info, 4=Trace, 5=Debug, ...)") + SET(OPTION_REPEATABLE_RANDOM false CACHE BOOL "Not for production use ; if On, enables repeatable random processes (srand is called multiple times)") + MARK_AS_ADVANCED(OPTION_REPEATABLE_RANDOM) + SET(OPTION_PROFILER false CACHE BOOL "Enable profiler") SET(OPTION_SCHEDULE_SPY false CACHE BOOL "Enable fine grained scheduling spy") @@ -120,18 +123,27 @@ MACRO(ADD_SD_COMPILE_OPTIONS) IF(OPTION_FORCE_DEBUG) ADD_DEFINITIONS(-DSD_DEBUG) ENDIF(OPTION_FORCE_DEBUG) + IF(OPTION_TRACE) ADD_DEFINITIONS(-DTRACE_OUT) ENDIF(OPTION_TRACE) + IF(OPTION_TRACE_LEVEL) ADD_DEFINITIONS(-DTRACE_LEVEL=${OPTION_TRACE_LEVEL}) ENDIF(OPTION_TRACE_LEVEL) + + IF(OPTION_REPEATABLE_RANDOM) + ADD_DEFINITIONS(-DREPEATABLE_RANDOM) + ENDIF(OPTION_REPEATABLE_RANDOM) + IF(OPTION_XRANDR) ADD_DEFINITIONS(-DUSE_RANDR_EXT) ENDIF(OPTION_XRANDR) + IF(OPTION_PROFILER) ADD_DEFINITIONS(-DPROFILER) ENDIF(OPTION_PROFILER) + IF(OPTION_SCHEDULE_SPY) ADD_DEFINITIONS(-DSCHEDULE_SPY) ENDIF(OPTION_SCHEDULE_SPY) diff --git a/src/libs/tgf/params.cpp b/src/libs/tgf/params.cpp index db9596387..2221a4fed 100644 --- a/src/libs/tgf/params.cpp +++ b/src/libs/tgf/params.cpp @@ -3272,7 +3272,7 @@ GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, @warning The key is created is necessary */ int -GfParmSetNumEx(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max) +GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max) { struct parmHandle *parmHandle = (struct parmHandle *)handle; struct parmHeader *conf; diff --git a/src/libs/tgf/tgf.h b/src/libs/tgf/tgf.h index e768730f4..68ecb7178 100644 --- a/src/libs/tgf/tgf.h +++ b/src/libs/tgf/tgf.h @@ -351,7 +351,7 @@ TGF_API tdble GfParmGetCurNumMax(void *handle, const char *path, const char *key /* set num parameter value */ TGF_API int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val); /* set num parameter value with min an max */ -TGF_API int GfParmSetNumEx(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max); +TGF_API int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max); /* set num parameter value */ TGF_API int GfParmSetCurNum(void *handle, const char *path, const char *key, const char *unit, tdble val); diff --git a/src/modules/racing/genparoptv1/genetic.cpp b/src/modules/racing/genparoptv1/genetic.cpp index 3a6eef8a9..78ec95054 100644 --- a/src/modules/racing/genparoptv1/genetic.cpp +++ b/src/modules/racing/genparoptv1/genetic.cpp @@ -41,19 +41,19 @@ TGeneticParameter::TGeneticParameter(): Active(false), Min(FLT_MIN), Max(FLT_MAX), - Def(0.0), Val(0.0), + Def(0.0), Weight(1.0), Scale(1.0), Round(1.0), - oLabel(NULL), - oSection(NULL), - oParameter(NULL), - oUnit(NULL), Tries(0), Changed(0), Selected(false), - LeftRight(false) + LeftRight(false), + oLabel(NULL), + oSection(NULL), + oParameter(NULL), + oUnit(NULL) { Range = Max - Min; }; @@ -168,7 +168,7 @@ int TGeneticParameter::Set(const char* Part, int Index) GfParmSetStr(Handle, ParamSection, PRM_SECT, oSection); GfParmSetStr(Handle, ParamSection, PRM_PRM, oParameter); GfParmSetStr(Handle, ParamSection, PRM_UNIT, oUnit); - GfParmSetNumEx(Handle, ParamSection, PRM_RANGE, oUnit, Val, Min, Max); + GfParmSetNum(Handle, ParamSection, PRM_RANGE, oUnit, Val, Min, Max); GfParmSetNum(Handle, ParamSection, PRM_WEIGHT, 0, Weight); GfParmSetNum(Handle, ParamSection, PRM_SCALE, 0, Scale); GfParmSetNum(Handle, ParamSection, PRM_ROUND, 0, Round); @@ -300,20 +300,20 @@ int TGeneticParameter::SetVal(void* SetupHandle, int Index) if (Index > 0) sprintf(ParamSection,"%s/%d",oSection,Index); else - sprintf(ParamSection,"%s",oSection,Index); + sprintf(ParamSection,"%s",oSection); if (LeftRight) { char SideParam[64]; sprintf(SideParam,ParamSection,SECT_PH_LEFT); - GfParmSetNumEx(SetupHandle, SideParam, oParameter, oUnit, Val, Min, Max); + GfParmSetNum(SetupHandle, SideParam, oParameter, oUnit, Val, Min, Max); sprintf(SideParam,ParamSection,SECT_PH_RGHT); - return GfParmSetNumEx(SetupHandle, SideParam, oParameter, oUnit, Val, Min, Max); + return GfParmSetNum(SetupHandle, SideParam, oParameter, oUnit, Val, Min, Max); } else - return GfParmSetNumEx(SetupHandle, ParamSection, oParameter, oUnit, Val, Min, Max); + return GfParmSetNum(SetupHandle, ParamSection, oParameter, oUnit, Val, Min, Max); } @@ -535,4 +535,4 @@ int TGeneticParameterTOC::Get() return 0; }; -// end of file genetic.cpp \ No newline at end of file +// end of file genetic.cpp diff --git a/src/modules/racing/genparoptv1/genetic.h b/src/modules/racing/genparoptv1/genetic.h index d4d9f6ebe..7501b42cd 100644 --- a/src/modules/racing/genparoptv1/genetic.h +++ b/src/modules/racing/genparoptv1/genetic.h @@ -241,13 +241,13 @@ class TGeneticParameter bool Selected; // Parameter is in current selection // (to avoid multiple variations) + bool LeftRight; + char *oLabel; char *oSection; char *oParameter; char *oUnit; - bool LeftRight; - // Common data (class variables) static tgenData Data; // Structure with all data // needed for optimization diff --git a/src/modules/racing/genparoptv1/racemain.cpp b/src/modules/racing/genparoptv1/racemain.cpp index 668f64757..63d621424 100644 --- a/src/modules/racing/genparoptv1/racemain.cpp +++ b/src/modules/racing/genparoptv1/racemain.cpp @@ -146,9 +146,6 @@ void ReRaceSkipSession() int ReRaceEventInit(void) { - void *mainParams = ReInfo->mainParams; - void *params = ReInfo->params; - // Initialize the race session name. ReInfo->_reRaceName = ReGetCurrentRaceName(); GfLogInfo("Starting new event (%s session)\n", ReInfo->_reRaceName); @@ -277,7 +274,7 @@ ReParseStartingOrder(const char *StartingOrder, tReGridPart **pGridList, int nCa } // Find driver position in params/RM_SECT_DRIVERS based on module name and ID -// returns with the driver position or -1 when not found or error +// returns the driver position or -1 when not found or error int ReFindDriverIdx (const char *modulename, int idx) { @@ -995,7 +992,7 @@ ReRaceEventShutdown(void) void *results = ReInfo->results; int curRaceIdx; // bool careerMode = false; - bool first = true; +// bool first = true; // Notify the UI that the race event is finishing now. ReUI().onRaceEventFinishing(); @@ -1117,14 +1114,6 @@ ReInitialiseGeneticOptimisation() ReImportGeneticParameters(); } -int GetNumberOfSubsections(void* Handle, char* Section) -{ - if (GfParmExistsSection(Handle,Section)) - return GfParmGetEltNb(Handle,Section); - else - return 0; -} - void ReImportGeneticParameters() { @@ -1193,15 +1182,15 @@ ReImportGeneticParameters() GfParmReleaseHandle(Handle); // Store tank capacity as initial fuel - GfParmSetNumEx(Data->Handle, Data->PrivateSection, PRM_FUEL, + GfParmSetNum(Data->Handle, Data->PrivateSection, PRM_FUEL, (char*) NULL, Data->MaxFuel, -1.0, Data->MaxFuel); // Set optimisation flag for robot - GfParmSetNumEx(Data->Handle, Data->PrivateSection, PRV_OPTI, + GfParmSetNum(Data->Handle, Data->PrivateSection, PRV_OPTI, (char*) NULL, 1, 0, 1); - Data->NbrOfParam = GetNumberOfSubsections(MetaDataFile,SECT_GLOBAL); - Data->NbrOfParts = GetNumberOfSubsections(MetaDataFile,SECT_LOCAL); + Data->NbrOfParam = GfParmGetEltNb(MetaDataFile,SECT_GLOBAL); + Data->NbrOfParts = GfParmGetEltNb(MetaDataFile,SECT_LOCAL); // We need at least one part to store the offset // as index to the last global parameter @@ -1237,7 +1226,7 @@ ReImportGeneticParameters() // Get number of parts defined in the meta data configuration snprintf(buf,sizeof(buf),"%s/%d/%s",SECT_LOCAL,I+1,SECT_PARAM); - Data->Part[I].Count = GetNumberOfSubsections(MetaDataFile,buf); + Data->Part[I].Count = GfParmGetEltNb(MetaDataFile,buf); // Store the data to the list of parts if (TrackParam->Parameter) @@ -1246,7 +1235,7 @@ ReImportGeneticParameters() Data->Part[I].Subsection = strdup(GroupParam->Subsection); // Get number of local sections defined in the car setup - Data->Part[I].NbrOfSect = GetNumberOfSubsections(Data->Handle,buf); + Data->Part[I].NbrOfSect = GfParmGetEltNb(Data->Handle,buf); // Update number of parameters Data->NbrOfParam += Data->Part[I].Count * Data->Part[I].NbrOfSect; @@ -1397,12 +1386,12 @@ ReCleanupGeneticOptimisation() printf ("Reset fuel control\n"); // Reset fuel control - GfParmSetNumEx(Handle, Data->PrivateSection, PRM_FUEL, + GfParmSetNum(Handle, Data->PrivateSection, PRM_FUEL, (char*) NULL, -1, -1.0, Data->MaxFuel); printf ("Reset optimisation flag for robot\n"); // Reset optimisation flag for robot - GfParmSetNumEx(Handle, Data->PrivateSection, PRV_OPTI, + GfParmSetNum(Handle, Data->PrivateSection, PRV_OPTI, (char*) NULL, 0, 0, 1); printf ("Set filename for use with local dir\n"); @@ -1486,6 +1475,9 @@ ReEvolution() if (Data->First) // First race was done using the initial parameters { +#ifdef REPEATABLE_RANDOM // For testing only (not for production use) + srand((unsigned)time(NULL)); // Initialize the random number generator +#endif // First race is done with the initial parameters to get the reference laptime GfLogOpt("Initial Lap Time : %g\n",TotalLapTime);