diff --git a/src/drivers/simplix/CMakeLists.txt b/src/drivers/simplix/CMakeLists.txt index 4c6336ec..ace7349c 100644 --- a/src/drivers/simplix/CMakeLists.txt +++ b/src/drivers/simplix/CMakeLists.txt @@ -23,8 +23,6 @@ SET(ROBOT_SOURCES src/unitcollision.cpp src/unitcollision.h src/unitcommon.cpp - src/unitcommondata.cpp - src/unitcommondata.h src/unitcommon.h src/unitcubic.cpp src/unitcubic.h diff --git a/src/drivers/simplix/src/unitcarparam.cpp b/src/drivers/simplix/src/unitcarparam.cpp index 4b657338..7284187a 100644 --- a/src/drivers/simplix/src/unitcarparam.cpp +++ b/src/drivers/simplix/src/unitcarparam.cpp @@ -61,36 +61,6 @@ TCarParam::TCarParam(): } //==========================================================================* -//==========================================================================* -// Destructor -//--------------------------------------------------------------------------* -TCarParam::~TCarParam() -{ -} -//=========================================================================== - -//==========================================================================* -// Zuweisung -//--------------------------------------------------------------------------* -TCarParam& TCarParam::operator= (const TCarParam& CarParam) -{ - oScaleMu = CarParam.oScaleMu; - oScaleMinMu = CarParam.oScaleMinMu; - oScaleBrake = CarParam.oScaleBrake; - oScaleBrakePit = CarParam.oScaleBrakePit; - oScaleBump = CarParam.oScaleBump; - oScaleBumpOuter = CarParam.oScaleBumpOuter; - oScaleBumpLeft = CarParam.oScaleBumpLeft; - oScaleBumpRight = CarParam.oScaleBumpRight; - oLimitSideUse = CarParam.oLimitSideUse; - oLimitSideWidth = CarParam.oLimitSideWidth; - oUglyCrvZ = CarParam.oUglyCrvZ; - oBrakeForce = CarParam.oBrakeForce; - - return *this; -} -//=========================================================================== - //--------------------------------------------------------------------------* // end of file unitcarparam.cpp //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++* diff --git a/src/drivers/simplix/src/unitcarparam.h b/src/drivers/simplix/src/unitcarparam.h index 6e3a11d5..6b462ac7 100644 --- a/src/drivers/simplix/src/unitcarparam.h +++ b/src/drivers/simplix/src/unitcarparam.h @@ -46,9 +46,6 @@ class TCarParam { public: TCarParam(); // Default constructor -// TCarParam(const TCarParam&) = default; // Default copy constructor - virtual ~TCarParam(); // Destructor - virtual TCarParam& operator= (const TCarParam& CarParam); public: double oScaleMu; // Scaling of MU diff --git a/src/drivers/simplix/src/unitcommondata.cpp b/src/drivers/simplix/src/unitcommondata.cpp deleted file mode 100644 index e24eac35..00000000 --- a/src/drivers/simplix/src/unitcommondata.cpp +++ /dev/null @@ -1,81 +0,0 @@ -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++* -// unitcommondata.cpp -//--------------------------------------------------------------------------* -// A robot for Speed Dreams-Version 2.X simuV4 -//--------------------------------------------------------------------------* -// Common data -// Gemeinsame Daten -// -// File : unitcommondata.cpp -// Created : 2007.11.17 -// Last changed : 2014.11.29 -// Copyright : © 2007-2014 Wolf-Dieter Beelitz -// eMail : wdbee@users.sourceforge.net -// Version : 4.05.000 -//--------------------------------------------------------------------------* -// Teile diese Unit basieren auf diversen Header-Dateien von TORCS -// -// Copyright: (C) 2000 by Eric Espie -// eMail : torcs@free.fr -// -// dem erweiterten Robot-Tutorial bt -// -// Copyright: (C) 2002-2004 Bernhard Wymann -// eMail : berniw@bluewin.ch -// -// dem Roboter wdbee_2007 -// -// Copyright: (C) 2006-2007 Wolf-Dieter Beelitz -// eMail : wdbee@users.sourceforge.net -// -// und dem Roboter delphin -// -// Copyright: (C) 2006-2007 Wolf-Dieter Beelitz -// eMail : wdbee@users.sourceforge.net -// -//--------------------------------------------------------------------------* -// This program was developed and tested on windows XP -// There are no known Bugs, but: -// Who uses the files accepts, that no responsibility is adopted -// for bugs, dammages, aftereffects or consequential losses. -// -// Das Programm wurde unter Windows XP entwickelt und getestet. -// Fehler sind nicht bekannt, dennoch gilt: -// Wer die Dateien verwendet erkennt an, dass für Fehler, Schäden, -// Folgefehler oder Folgeschäden keine Haftung übernommen wird. -//--------------------------------------------------------------------------* -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Im übrigen gilt für die Nutzung und/oder Weitergabe die -// GNU GPL (General Public License) -// Version 2 oder nach eigener Wahl eine spätere Version. -//--------------------------------------------------------------------------* - -#include "unitglobal.h" -#include "unitcommon.h" - -#include "unitcommondata.h" - -//==========================================================================* -// Default constructor -//--------------------------------------------------------------------------* -TCommonData::TCommonData(): - Track(NULL) -{ -} -//==========================================================================* - -//==========================================================================* -// Destructor -//--------------------------------------------------------------------------* -TCommonData::~TCommonData() -{ -} -//==========================================================================* - -//--------------------------------------------------------------------------* -// end of file unitcommondata.cpp -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++* diff --git a/src/drivers/simplix/src/unitcommondata.h b/src/drivers/simplix/src/unitcommondata.h deleted file mode 100644 index 4bb09892..00000000 --- a/src/drivers/simplix/src/unitcommondata.h +++ /dev/null @@ -1,78 +0,0 @@ -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++* -// unitcommondata.h -//--------------------------------------------------------------------------* -// A robot for Speed Dreams-Version 2.X simuV4 -//--------------------------------------------------------------------------* -// Common used data -// Gemeinsam verwendete Daten -// -// File : unitcommondata.h -// Created : 2007.11.17 -// Last changed : 2014.11.29 -// Copyright : © 2007-2014 Wolf-Dieter Beelitz -// eMail : wdbee@users.sourceforge.net -// Version : 4.05.000 -//--------------------------------------------------------------------------* -// Teile diese Unit basieren auf diversen Header-Dateien von TORCS -// -// Copyright: (C) 2000 by Eric Espie -// eMail : torcs@free.fr -// -// dem erweiterten Robot-Tutorial bt -// -// Copyright: (C) 2002-2004 Bernhard Wymann -// eMail : berniw@bluewin.ch -// -// dem Roboter delphin -// -// Copyright: (C) 2006-2007 Wolf-Dieter Beelitz -// eMail : wdbee@users.sourceforge.net -// -// dem Roboter wdbee_2007 -// -// Copyright: (C) 2006-2007 Wolf-Dieter Beelitz -// eMail : wdbee@users.sourceforge.net -// -// und dem Roboter mouse_2006 -// -// Copyright: (C) 2006-2007 Tim Foden -// -//--------------------------------------------------------------------------* -// Das Programm wurde unter Windows XP entwickelt und getestet. -// Fehler sind nicht bekannt, dennoch gilt: -// Wer die Dateien verwendet erkennt an, dass für Fehler, Schäden, -// Folgefehler oder Folgeschäden keine Haftung übernommen wird. -// -// Im übrigen gilt für die Nutzung und/oder Weitergabe die -// GNU GPL (General Public License) -// Version 2 oder nach eigener Wahl eine spätere Version. -//--------------------------------------------------------------------------* -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -//--------------------------------------------------------------------------* -#ifndef _UNITCOMMONDATA_H_ -#define _UNITCOMMONDATA_H_ - -#include -#include "unitglobal.h" -#include "unitclothoid.h" - -//==========================================================================* -// Deklaration der Klasse TCommonData -//--------------------------------------------------------------------------* -class TCommonData -{ - public: - TCommonData(); // Default constructor - ~TCommonData(); // Destructor - - public: - PTrack Track; // TORCS Track data -}; -//==========================================================================* -#endif // _UNITCOMMONDATA_H_ -//--------------------------------------------------------------------------* -// end of file unitcommondata.h -//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++* diff --git a/src/drivers/simplix/src/unitdriver.cpp b/src/drivers/simplix/src/unitdriver.cpp index 9be67f56..4301be7d 100644 --- a/src/drivers/simplix/src/unitdriver.cpp +++ b/src/drivers/simplix/src/unitdriver.cpp @@ -57,9 +57,6 @@ // 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 use delete for oCarType, use free (oCarType) // //--------------------------------------------------------------------------* @@ -295,8 +292,8 @@ void TDriver::setCategoryParams() //==========================================================================* // Constructor //--------------------------------------------------------------------------* -TDriver::TDriver(void *params, int Index): - oCommonData(NULL), +TDriver::TDriver(const std::string &name, const std::string &car, + const std::string &category, int Index): // TrackDesc // Racingline // oCarParams @@ -343,9 +340,7 @@ TDriver::TDriver(void *params, int Index): oAlone(true), oAngle(0), oAngleSpeed(0), - oBotName(NULL), - oTeamName(NULL), - oRaceNumber(0), + oDriverName(name), oWingControl(false), oWingAngleFront(0), oWingAngleRear(0), @@ -367,7 +362,7 @@ TDriver::TDriver(void *params, int Index): oInitialBrakeCoeff(0.5f), oCar(NULL), oSteerAngle(0.0f), - oCarType(NULL), + oCarType(car), oClutchMax(0.5), oClutchDelta(0.009), oClutchRange(0.82), @@ -383,7 +378,6 @@ TDriver::TDriver(void *params, int Index): */ oEarlyShiftFactor(1.0), oShiftCounter(0), - oExtended(0), oLastGear(0), oLetPass(false), oLookAhead(5.0), @@ -466,7 +460,7 @@ TDriver::TDriver(void *params, int Index): oDecelAdjustTarget(1.0), oDecelAdjustPerc(1.0), oRandomSeed(0), - oIndex(0), + oIndex(Index), oTestPitStop(0), oShowPlot(false), //LengthMargin @@ -493,8 +487,8 @@ TDriver::TDriver(void *params, int Index): oDeltaAccel(0.05f), oDeltaAccelRain(0.025f), oUseAccelOut(false), - oSideScaleMu(0.97f), - oSideScaleBrake(0.97f), + oSideScaleMu(0.95f), + oSideScaleBrake(0.95f), oSideBorderOuter(0.2f), oSideBorderInner(0.2f), oXXX(1.0), @@ -509,7 +503,7 @@ TDriver::TDriver(void *params, int Index): oFirstJump(true), oStartSteerFactor(0.0), oCarHasTYC(false), - RobotType(getRobotType(params, Index)), + RobotType(getRobotType(category)), AdvancedParameters(false), UseOldSkilling(false), UseSCSkilling(false), @@ -524,13 +518,14 @@ TDriver::TDriver(void *params, int Index): BrakeLimitBase(0.025f), SpeedLimitScale(25), SpeedLimitBase(0.025f), - Learning(false) + Learning(false), + CalcSkillingFoo(&TDriver::CalcSkilling_simplix), + CalcFrictionFoo(&TDriver::CalcFriction_simplix_Identity), + CalcCrvFoo(&TDriver::CalcCrv_simplix_Identity), + CalcHairpinFoo(&TDriver::CalcHairpin_simplix_Identity) { LogSimplix.debug("\n#TDriver::TDriver() >>>\n\n"); int I; - oIndex = Index; // Save own index - oExtended = // Determine if it - ( Index < 0 || Index >= NBBOTS ) ? 1 : 0; // is extended or not // Motion survey oSysFooStuckX = new TSysFoo(1,128); // Ringbuffer for X @@ -579,9 +574,6 @@ TDriver::~TDriver() LogSimplix.debug("\n#TDriver::~TDriver() >>>\n\n"); delete [] oOpponents; - if (oCarType != NULL) - free(oCarType); - if (oStrategy != NULL) delete oStrategy; if (oSysFooStuckX != NULL) @@ -593,61 +585,6 @@ TDriver::~TDriver() } //==========================================================================* -//==========================================================================* -// Set name of robot (and other appendant features) -//--------------------------------------------------------------------------* -void TDriver::SetBotName(void* RobotSettings, const char* Value) -{ - // At this point TORCS gives us no information - // about the name of the driver, the team and - // our own car type! - // Because we want it to set the name as defined - // in the teams xml file and to load depending - // setup files we have to find it out: - - // Needed for Career mode? - if (oCarType) - free (oCarType); - oCarType = NULL; - - char SectionBuffer[256]; // Buffer - char indexstr[32]; - - snprintf(SectionBuffer,BUFLEN, // Build name of - "%s/%s/%d" // section from - ,ROB_SECT_ROBOTS,ROB_LIST_INDEX,oIndex); // Index of own driver - char* Section = SectionBuffer; - - // Modified to avoid memory leaks - // Speed dreams has a trick to find out the oCarType - RtGetCarindexString(oIndex, "simplix", (char) oExtended, indexstr, 32); - if( oExtended ) - oCarType = strdup( indexstr ); - else // avoid empty car type - oCarType = strdup(GfParmGetStr // Get pointer to - (RobotSettings // car type - , Section // defined in corresponding - , ROB_ATTR_CAR, DEFAULTCARTYPE)); // section, default car type - - oBotName = Value; // Get pointer to drv. name - - oTeamName = GfParmGetStr // Get pointer to - (RobotSettings // drivers team name - , Section // defined in corresponding - , ROB_ATTR_TEAM, (char *) oCarType); // section, default car type - - oRaceNumber = (int) GfParmGetNum // Get pointer to - (RobotSettings // race number - , Section, ROB_ATTR_RACENUM // defined in corresponding - , (char *) NULL, (tdble) oIndex + 1); // section, index as default - - LogSimplix.debug("#Bot name : %s\n",oBotName); - LogSimplix.debug("#Team name : %s\n",oTeamName); - LogSimplix.debug("#Car type : %s\n",oCarType); - LogSimplix.debug("#Race number : %d\n",oRaceNumber); -}; -//==========================================================================* - //==========================================================================* // Adjust car characteristic //--------------------------------------------------------------------------* @@ -670,7 +607,7 @@ void TDriver::AdjustCarCharacteristic(PCarHandle Handle) CarCharacteristic.Init(ControlPoints, X, Y, S); snprintf(buf, BUFLEN, "%sCharacteristic-%s.txt", - GetLocalDir(),oBotName); + GetLocalDir(), oDriverName.c_str()); SaveCharacteristicToFile(buf); }; @@ -1334,9 +1271,9 @@ void TDriver::SetPathAndFilenameForRacinglines() { const char* PathToWriteTo = GetLocalDir(); - snprintf(PathToWriteToBuffer,sizeof(TrackLoadBuffer), + snprintf(PathToWriteToBuffer, sizeof(TrackLoadBuffer), "%sdrivers/simplix_common/racinglines/%s/%s", - PathToWriteTo,MyBotName,oCarType); + PathToWriteTo, MyBotName, oCarType.c_str()); oPathToWriteTo = PathToWriteToBuffer; if (GfDirCreate(oPathToWriteTo) == GF_DIR_CREATION_FAILED) { @@ -1476,7 +1413,7 @@ void TDriver::InitTrack // Default params for car type (e.g. .../ROBOT_DIR/sc-petrol/default.xml) snprintf(Buf,sizeof(Buf),"%s/%s/default.xml", - BaseParamPath,oCarType); + BaseParamPath, oCarType.c_str()); if (GfFileExists(Buf)) { LogSimplix.info("#Default params for car type: %s\n", Buf); @@ -1515,7 +1452,7 @@ void TDriver::InitTrack // Override params for car type with params of track snprintf(Buf,sizeof(Buf),"%s/%s/%s.xml", - BaseParamPath,oCarType,oTrackName); + BaseParamPath, oCarType.c_str(), oTrackName); if (GfFileExists(Buf)) { LogSimplix.info("#Override params for car type with params of track: %s\n", Buf); @@ -1528,7 +1465,7 @@ void TDriver::InitTrack // Override params for car type with params of track and weather snprintf(Buf,sizeof(Buf),"%s/%s/%s-%d.xml", - BaseParamPath,oCarType,oTrackName,oWeatherCode); + BaseParamPath, oCarType.c_str(),oTrackName, oWeatherCode); if (GfFileExists(Buf)) { LogSimplix.info("#Override params for car type with params of track and weather: %s\n", Buf); @@ -1541,7 +1478,7 @@ void TDriver::InitTrack // Override params for car type on track with params of specific race type snprintf(Buf,sizeof(Buf),"%s/%s/%s-%s.xml", - BaseParamPath,oCarType,oTrackName,RaceType[oSituation->_raceType]); + BaseParamPath, oCarType.c_str(), oTrackName, RaceType[oSituation->_raceType]); if (GfFileExists(Buf)) { LogSimplix.info("#Override params for car type on track with params of specific race type: %s\n", Buf); @@ -2108,10 +2045,6 @@ void TDriver::FindRacinglines() Param.Update(); // update car parameters LogSimplix.debug("# ... set track ...\n"); - if(oCommonData->Track != oTrackDesc.Track()) // New track? - { - oCommonData->Track = oTrackDesc.Track(); // Save pointer - } LogSimplix.debug("# ... load smooth path ...\n"); if (oSituation->_raceType == RM_TYPE_PRACTICE) @@ -4682,17 +4615,6 @@ double TDriver::CalcSkill(double TargetSpeed) } return TargetSpeed; } -//==========================================================================* - -//==========================================================================* -// Set scaling factor for avoiding racinglines -//--------------------------------------------------------------------------* -void TDriver::ScaleSide(float FactorMu, float FactorBrake) -{ - oSideScaleMu = FactorMu; - oSideScaleBrake = FactorBrake; -} -//==========================================================================* //==========================================================================* // Set additional border to outer side diff --git a/src/drivers/simplix/src/unitdriver.h b/src/drivers/simplix/src/unitdriver.h index 856ec21a..aeafbc54 100644 --- a/src/drivers/simplix/src/unitdriver.h +++ b/src/drivers/simplix/src/unitdriver.h @@ -63,7 +63,6 @@ #include "unitglobal.h" #include "unitcommon.h" -#include "unitcommondata.h" #include "unitcharacteristic.h" #include "unitcollision.h" @@ -85,7 +84,8 @@ class TDriver { public: - TDriver(void *params, int Index); // Constructor + TDriver(const std::string &name, const std::string &car, + const std::string &category, int Index); ~TDriver(); // Destructor // TORCS-Interface: @@ -156,11 +156,7 @@ class TDriver void BrakingForceController(); // PID controller void LearnBraking(double Pos); // Learn braking parameters - void SetBotName // Set name of bot - (void* RobotSettings, const char* Value); - inline void SetCommonData // Set pointer to common data - (TCommonData* CommonData); - inline const char* GetBotName(); + inline const std::string &GetDriverName() const; inline float CurrSpeed(); inline int TeamIndex(); @@ -207,12 +203,11 @@ private: double CalcSkill(double TargetSpeed); bool CheckPitSharing(); bool SaveToFile(); - int getRobotType(void *h, unsigned index) const; + int getRobotType(const std::string &h) const; void setCategoryParams(); private: - TCommonData* oCommonData; // Pointer to common data TTrackDescription oTrackDesc; // Track description std::vector oRacingLine; // Racinglines @@ -269,9 +264,7 @@ private: bool oAlone; // No opponent near double oAngle; // Actual Angle double oAngleSpeed; // Angle of speed - const char* oBotName; // Name of driver - const char* oTeamName; // Name of team - int oRaceNumber; // Race number + const std::string oDriverName; bool oWingControl; // Enable wing control double oWingAngleFront; // Front wing angle of attack double oWingAngleRear; // Rear wing angle of attack @@ -295,7 +288,7 @@ private: double oInitialBrakeCoeff; PtCarElt oCar; // TORCS data for own car float oSteerAngle; // Angle to steer - char* oCarType; // Type name of own car + const std::string oCarType; // Type name of own car double oClutchMax; double oClutchDelta; double oClutchRange; @@ -308,7 +301,6 @@ private: double oShiftUp[MAX_GEARS]; // Shift by setup double oEarlyShiftFactor; // Early shifting int oShiftCounter; // Shift timer - int oExtended; // Information if this robot is extended (oExtended = 1) or not (oExtended = 0). int oLastGear; // Last gear int oLastUsedGear; // Last used gear bool oLetPass; // Let opoonent pass @@ -402,7 +394,7 @@ private: unsigned int oRandomSeed; // seed of generator public: - int oIndex; // index of own driver + const int oIndex; // index of own driver int oTestPitStop; // Test pit stop bool oShowPlot; @@ -481,7 +473,6 @@ private: static bool FirstPropagation; - void ScaleSide(float FactorMu, float FactorBrake); void SideBorderOuter(float Factor); void SideBorderInner(float Factor); @@ -539,8 +530,8 @@ private: //==========================================================================* // Get name of robot //--------------------------------------------------------------------------* -const char* TDriver::GetBotName() - {return oBotName;}; +const std::string &TDriver::GetDriverName() const + {return oDriverName;}; //==========================================================================* //==========================================================================* @@ -550,14 +541,6 @@ int TDriver::TeamIndex() {return oTeamIndex;}; //==========================================================================* -//==========================================================================* -// Set pointer to common data -//--------------------------------------------------------------------------* -void TDriver::SetCommonData - (TCommonData* CommonData) - {oCommonData = CommonData;}; -//==========================================================================* - //==========================================================================* // Get Pointer to TORCS data of track //--------------------------------------------------------------------------* diff --git a/src/drivers/simplix/src/unitstrategy.cpp b/src/drivers/simplix/src/unitstrategy.cpp index 65da355d..7e838e9a 100644 --- a/src/drivers/simplix/src/unitstrategy.cpp +++ b/src/drivers/simplix/src/unitstrategy.cpp @@ -117,10 +117,10 @@ bool TSimpleStrategy::IsPitFree() bool IsFree = RtTeamIsPitFree(oDriver->TeamIndex()); if (IsFree) LogSimplix.debug("#%s pit is free (%d)\n", - oDriver->GetBotName(),oDriver->TeamIndex()); + oDriver->GetDriverName(),oDriver->TeamIndex()); else LogSimplix.debug("#%s pit is locked (%d)\n", - oDriver->GetBotName(),oDriver->TeamIndex()); + oDriver->GetDriverName(),oDriver->TeamIndex()); return IsFree; } //==========================================================================* @@ -150,7 +150,7 @@ bool TSimpleStrategy::NeedPitStop() if (MIN(TdF,TdR) < 1.5 * oDegradationPerLap) // tyres become critical { LogSimplix.warning("Tyre condition D: %.1f%% F: %.1f%% R: %.1f%% (%s)\n", - oDegradationPerLap,TdF,TdR,oDriver->GetBotName()); + oDegradationPerLap,TdF,TdR,oDriver->GetDriverName()); if ((TdF < 1.1 * oDegradationPerLap) || (TdR < 1.1 * oDegradationPerLap)) @@ -537,7 +537,7 @@ void TSimpleStrategy::CheckPitState(float /*PitScaleBrake*/) && ((Major > NEEDED_MAJOR_VERSION) || ((Major = NEEDED_MAJOR_VERSION) && (Minor >= NEEDED_MINOR_VERSION)))) { - LogSimplix.debug("#Pitting issues %s\n",oDriver->GetBotName()); + LogSimplix.debug("#Pitting issues %s\n",oDriver->GetDriverName()); LogSimplix.debug("#StillToGo : %.2f m\n",TeamDriver->StillToGo); LogSimplix.debug("#MoreOffset: %.2f m\n",TeamDriver->MoreOffset); LogSimplix.debug("#TooFastBy : %.2f m/s\n",TeamDriver->TooFastBy);