Bug fix career mode modifications

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

Former-commit-id: 002f687b583c4b87a2efc70cf9a99f39b3e19fc2
Former-commit-id: a4089d6026007b47c5399111109b57e536089319
This commit is contained in:
wdbee 2010-09-25 11:10:19 +00:00
parent 8b37ca77ce
commit 36137ab5b7
2 changed files with 49 additions and 25 deletions

View file

@ -9,10 +9,10 @@
// //
// File : unitdriver.cpp // File : unitdriver.cpp
// Created : 2007.11.25 // Created : 2007.11.25
// Last changed : 2010.02.08 // Last changed : 2010.09.25
// Copyright : © 2007-2010 Wolf-Dieter Beelitz // Copyright : © 2007-2010 Wolf-Dieter Beelitz
// eMail : wdb@wdbee.de // eMail : wdb@wdbee.de
// Version : 2.00.000 // Version : 2.00.001
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
// Teile dieser Unit basieren auf diversen Header-Dateien von TORCS // Teile dieser Unit basieren auf diversen Header-Dateien von TORCS
// //
@ -58,6 +58,12 @@
// GNU GPL (General Public License) // GNU GPL (General Public License)
// Version 2 oder nach eigener Wahl eine spätere Version. // Version 2 oder nach eigener Wahl eine spätere Version.
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
// THIS VERSION WAS MODIFIED TO BE USED WITH SD CAREER MODE
// This results in some issues while using it with windows!
// Known bugs:
// Heap corruption -> do not used delete for oCarType, use free (oCarType)
//
//--------------------------------------------------------------------------*
//#undef SPEED_DREAMS //#undef SPEED_DREAMS
#include <v2_t.h> #include <v2_t.h>
@ -82,9 +88,9 @@
int TDriver::NBBOTS = MAX_NBBOTS; // Nbr of drivers/robots int TDriver::NBBOTS = MAX_NBBOTS; // Nbr of drivers/robots
//double TDriver::CurrSimTime = 0; // Current simulation time //double TDriver::CurrSimTime = 0; // Current simulation time
const char* TDriver::MyBotName = "simplix"; // Name of this bot const char* TDriver::MyBotName = "simplix"; // Name of this bot
const char* TDriver::ROBOT_DIR = "drivers/simplix"; // Sub path to dll const char* TDriver::ROBOT_DIR = "drivers/simplix";// Sub path to dll
const char* TDriver::SECT_PRIV = "simplix private"; // Private section const char* TDriver::SECT_PRIV = "simplix private";// Private section
const char* TDriver::DEFAULTCARTYPE = "car1-trb1"; // Default car type const char* TDriver::DEFAULTCARTYPE = "car1-trb1";// Default car type
bool TDriver::AdvancedParameters = false; // Advanced parameters bool TDriver::AdvancedParameters = false; // Advanced parameters
bool TDriver::UseOldSkilling = false; // Use old skilling bool TDriver::UseOldSkilling = false; // Use old skilling
bool TDriver::UseSCSkilling = false; // Use supercar skilling bool TDriver::UseSCSkilling = false; // Use supercar skilling
@ -333,7 +339,8 @@ TDriver::TDriver(int Index):
// GfOut("#TDriver::TDriver() >>>\n"); // GfOut("#TDriver::TDriver() >>>\n");
int I; int I;
oIndex = Index; // Save own index oIndex = Index; // Save own index
oExtended = ( Index < 0 || Index >= NBBOTS ) ? 1 : 0; //Determine if it is extended or not oExtended = // Determine if it
( Index < 0 || Index >= NBBOTS ) ? 1 : 0; // is extended or not
// Motion survey // Motion survey
oSysFooStuckX = new TSysFoo(1,128); // Ringbuffer for X oSysFooStuckX = new TSysFoo(1,128); // Ringbuffer for X
@ -362,7 +369,9 @@ TDriver::~TDriver()
delete [] oOpponents; delete [] oOpponents;
if (oCarType != NULL) if (oCarType != NULL)
delete oCarType; // delete oCarType; // CAUSES HEAP CORRUPTION ASSERTION
free(oCarType);
if (oStrategy != NULL) if (oStrategy != NULL)
delete oStrategy; delete oStrategy;
if (oSysFooStuckX != NULL) if (oSysFooStuckX != NULL)
@ -385,6 +394,7 @@ void TDriver::SetBotName(void* RobotSettings, char* Value)
// in the teams xml file and to load depending // in the teams xml file and to load depending
// setup files we have to find it out: // setup files we have to find it out:
// Needed for Career mode?
if (oCarType) if (oCarType)
free (oCarType); free (oCarType);
oCarType = NULL; oCarType = NULL;
@ -398,19 +408,27 @@ void TDriver::SetBotName(void* RobotSettings, char* Value)
,ROB_SECT_ROBOTS,ROB_LIST_INDEX,oIndex); // Index of own driver ,ROB_SECT_ROBOTS,ROB_LIST_INDEX,oIndex); // Index of own driver
char* Section = SectionBuffer; char* Section = SectionBuffer;
#ifdef SPEED_DREAMS
// Modified to avoid memory leaks
// Speed dreams has a trick to find out the oCarType
RtGetCarindexString(oIndex, "simplix", oExtended, indexstr, 32);
if( oExtended )
oCarType = strdup( indexstr );
else // avoid empty car type
oCarType = strdup(GfParmGetStr // Get pointer to oCarType = strdup(GfParmGetStr // Get pointer to
(RobotSettings // car type (RobotSettings // car type
, Section // defined in corresponding , Section // defined in corresponding
, ROB_ATTR_CAR, DEFAULTCARTYPE)); // section, default car type , ROB_ATTR_CAR, DEFAULTCARTYPE)); // section, default car type
#else // IF NOT SPEED_DREAMS use simplix way to do it
oCarType = strdup(GfParmGetStr // Get pointer to
(RobotSettings // car type
, Section // defined in corresponding
, ROB_ATTR_CAR, DEFAULTCARTYPE)); // section, default car type
#endif //SPEED_DREAMS
oBotName = Value; // Get pointer to drivers name oBotName = Value; // Get pointer to drivers name
#ifdef SPEED_DREAMS //Speed dreams has a trick to find out the oCarType
RtGetCarindexString(oIndex, "simplix", oExtended, indexstr, 32);
if( oExtended )
oCarType = strdup( indexstr );
#endif //SPEED_DREAMS
oTeamName = GfParmGetStr // Get pointer to oTeamName = GfParmGetStr // Get pointer to
(RobotSettings // drivers team name (RobotSettings // drivers team name
, Section // defined in corresponding , Section // defined in corresponding

View file

@ -2,16 +2,20 @@
// unitmain.cpp // unitmain.cpp
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
// TORCS: "The Open Racing Car Simulator" // TORCS: "The Open Racing Car Simulator"
// A robot for Speed Dreams-Version 1.4.0 // A robot for Speed Dreams-Version 1.4.0/2.0
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
// Interface to TORCS // Interface to TORCS
// //
// File : unitmain.cpp // File : unitmain.cpp
// Created : 2008.01.27 // Created : 2008.01.27
// Last changed : 2009.12.22 // Last changed : 2010.09.25
// Copyright : © 2007-2009 Wolf-Dieter Beelitz // Copyright : © 2007-2010 Wolf-Dieter Beelitz
// eMail : wdb@wdbee.de // eMail : wdb@wdbee.de
// Version : 2.00.000 // Version : 2.00.001
//--------------------------------------------------------------------------*
// V2.00.01 (Speed Dreams - Career mode):
// Uses new Speed Dreams Interfaces and was extended to use career mode
// - Still work in progress
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
// V2.00 (Speed Dreams): // V2.00 (Speed Dreams):
// Uses new Speed Dreams Interfaces // Uses new Speed Dreams Interfaces
@ -178,6 +182,7 @@ typedef struct stInstanceInfo
int cUnusedCount; int cUnusedCount;
} tInstanceInfo; } tInstanceInfo;
//#undef ROB_SECT_ARBITRARY
#ifdef ROB_SECT_ARBITRARY #ifdef ROB_SECT_ARBITRARY
static tInstanceInfo *cInstances; static tInstanceInfo *cInstances;
static int cInstancesCount; static int cInstancesCount;
@ -562,8 +567,6 @@ extern "C" int simplixShut()
static int InitFuncPt(int Index, void *Pt) static int InitFuncPt(int Index, void *Pt)
{ {
tRobotItf *Itf = (tRobotItf *)Pt; // Get typed pointer tRobotItf *Itf = (tRobotItf *)Pt; // Get typed pointer
int xx;
tInstanceInfo *copy;
Itf->rbNewTrack = InitTrack; // Store function pointers Itf->rbNewTrack = InitTrack; // Store function pointers
Itf->rbNewRace = NewRace; Itf->rbNewRace = NewRace;
@ -574,6 +577,9 @@ static int InitFuncPt(int Index, void *Pt)
Itf->index = Index; // Store index Itf->index = Index; // Store index
#ifdef ROB_SECT_ARBITRARY #ifdef ROB_SECT_ARBITRARY
int xx;
tInstanceInfo *copy;
//Make sure enough data is allocated //Make sure enough data is allocated
if (cInstancesCount <= Index-IndexOffset) { if (cInstancesCount <= Index-IndexOffset) {
copy = new tInstanceInfo[Index-IndexOffset+1]; copy = new tInstanceInfo[Index-IndexOffset+1];