simplix: Refactor a few things
- Replace some non-const-correct char * to std::string to avoid potential dangling pointers and manual memory management. - oCommonData was deemed redundant, so unitcommondata.{cpp,h} have been removed. - There was no need to define non-default destructors or operator= for TCarParam. - oSideScaleMu and oSideScaleBrake were always set to 0.95f instead of 0.97f by all categories, so assume these values as defaults and remove both TDriver::ScaleSide and these variables altogether. - Since robots now allocated driver data dynamically i.e., without any arbitrary limits, oExtended was deemed redundant. Former-commit-id: 6f64dba41e036e37345bfba1d2de75bdb347a976 Former-commit-id: bd10700dae55653ef15936f3613c942a8ec753a7
This commit is contained in:
parent
b70c47d274
commit
f1c266b487
8 changed files with 33 additions and 322 deletions
|
@ -23,8 +23,6 @@ SET(ROBOT_SOURCES
|
||||||
src/unitcollision.cpp
|
src/unitcollision.cpp
|
||||||
src/unitcollision.h
|
src/unitcollision.h
|
||||||
src/unitcommon.cpp
|
src/unitcommon.cpp
|
||||||
src/unitcommondata.cpp
|
|
||||||
src/unitcommondata.h
|
|
||||||
src/unitcommon.h
|
src/unitcommon.h
|
||||||
src/unitcubic.cpp
|
src/unitcubic.cpp
|
||||||
src/unitcubic.h
|
src/unitcubic.h
|
||||||
|
|
|
@ -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
|
// end of file unitcarparam.cpp
|
||||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
|
||||||
|
|
|
@ -46,9 +46,6 @@ class TCarParam
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TCarParam(); // Default constructor
|
TCarParam(); // Default constructor
|
||||||
// TCarParam(const TCarParam&) = default; // Default copy constructor
|
|
||||||
virtual ~TCarParam(); // Destructor
|
|
||||||
virtual TCarParam& operator= (const TCarParam& CarParam);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
double oScaleMu; // Scaling of MU
|
double oScaleMu; // Scaling of MU
|
||||||
|
|
|
@ -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
|
|
||||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
|
|
|
@ -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 <track.h>
|
|
||||||
#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
|
|
||||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
|
|
|
@ -57,9 +57,6 @@
|
||||||
// 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 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
|
// Constructor
|
||||||
//--------------------------------------------------------------------------*
|
//--------------------------------------------------------------------------*
|
||||||
TDriver::TDriver(void *params, int Index):
|
TDriver::TDriver(const std::string &name, const std::string &car,
|
||||||
oCommonData(NULL),
|
const std::string &category, int Index):
|
||||||
// TrackDesc
|
// TrackDesc
|
||||||
// Racingline
|
// Racingline
|
||||||
// oCarParams
|
// oCarParams
|
||||||
|
@ -343,9 +340,7 @@ TDriver::TDriver(void *params, int Index):
|
||||||
oAlone(true),
|
oAlone(true),
|
||||||
oAngle(0),
|
oAngle(0),
|
||||||
oAngleSpeed(0),
|
oAngleSpeed(0),
|
||||||
oBotName(NULL),
|
oDriverName(name),
|
||||||
oTeamName(NULL),
|
|
||||||
oRaceNumber(0),
|
|
||||||
oWingControl(false),
|
oWingControl(false),
|
||||||
oWingAngleFront(0),
|
oWingAngleFront(0),
|
||||||
oWingAngleRear(0),
|
oWingAngleRear(0),
|
||||||
|
@ -367,7 +362,7 @@ TDriver::TDriver(void *params, int Index):
|
||||||
oInitialBrakeCoeff(0.5f),
|
oInitialBrakeCoeff(0.5f),
|
||||||
oCar(NULL),
|
oCar(NULL),
|
||||||
oSteerAngle(0.0f),
|
oSteerAngle(0.0f),
|
||||||
oCarType(NULL),
|
oCarType(car),
|
||||||
oClutchMax(0.5),
|
oClutchMax(0.5),
|
||||||
oClutchDelta(0.009),
|
oClutchDelta(0.009),
|
||||||
oClutchRange(0.82),
|
oClutchRange(0.82),
|
||||||
|
@ -383,7 +378,6 @@ TDriver::TDriver(void *params, int Index):
|
||||||
*/
|
*/
|
||||||
oEarlyShiftFactor(1.0),
|
oEarlyShiftFactor(1.0),
|
||||||
oShiftCounter(0),
|
oShiftCounter(0),
|
||||||
oExtended(0),
|
|
||||||
oLastGear(0),
|
oLastGear(0),
|
||||||
oLetPass(false),
|
oLetPass(false),
|
||||||
oLookAhead(5.0),
|
oLookAhead(5.0),
|
||||||
|
@ -466,7 +460,7 @@ TDriver::TDriver(void *params, int Index):
|
||||||
oDecelAdjustTarget(1.0),
|
oDecelAdjustTarget(1.0),
|
||||||
oDecelAdjustPerc(1.0),
|
oDecelAdjustPerc(1.0),
|
||||||
oRandomSeed(0),
|
oRandomSeed(0),
|
||||||
oIndex(0),
|
oIndex(Index),
|
||||||
oTestPitStop(0),
|
oTestPitStop(0),
|
||||||
oShowPlot(false),
|
oShowPlot(false),
|
||||||
//LengthMargin
|
//LengthMargin
|
||||||
|
@ -493,8 +487,8 @@ TDriver::TDriver(void *params, int Index):
|
||||||
oDeltaAccel(0.05f),
|
oDeltaAccel(0.05f),
|
||||||
oDeltaAccelRain(0.025f),
|
oDeltaAccelRain(0.025f),
|
||||||
oUseAccelOut(false),
|
oUseAccelOut(false),
|
||||||
oSideScaleMu(0.97f),
|
oSideScaleMu(0.95f),
|
||||||
oSideScaleBrake(0.97f),
|
oSideScaleBrake(0.95f),
|
||||||
oSideBorderOuter(0.2f),
|
oSideBorderOuter(0.2f),
|
||||||
oSideBorderInner(0.2f),
|
oSideBorderInner(0.2f),
|
||||||
oXXX(1.0),
|
oXXX(1.0),
|
||||||
|
@ -509,7 +503,7 @@ TDriver::TDriver(void *params, int Index):
|
||||||
oFirstJump(true),
|
oFirstJump(true),
|
||||||
oStartSteerFactor(0.0),
|
oStartSteerFactor(0.0),
|
||||||
oCarHasTYC(false),
|
oCarHasTYC(false),
|
||||||
RobotType(getRobotType(params, Index)),
|
RobotType(getRobotType(category)),
|
||||||
AdvancedParameters(false),
|
AdvancedParameters(false),
|
||||||
UseOldSkilling(false),
|
UseOldSkilling(false),
|
||||||
UseSCSkilling(false),
|
UseSCSkilling(false),
|
||||||
|
@ -524,13 +518,14 @@ TDriver::TDriver(void *params, int Index):
|
||||||
BrakeLimitBase(0.025f),
|
BrakeLimitBase(0.025f),
|
||||||
SpeedLimitScale(25),
|
SpeedLimitScale(25),
|
||||||
SpeedLimitBase(0.025f),
|
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");
|
LogSimplix.debug("\n#TDriver::TDriver() >>>\n\n");
|
||||||
int I;
|
int I;
|
||||||
oIndex = Index; // Save own index
|
|
||||||
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
|
||||||
|
@ -579,9 +574,6 @@ TDriver::~TDriver()
|
||||||
LogSimplix.debug("\n#TDriver::~TDriver() >>>\n\n");
|
LogSimplix.debug("\n#TDriver::~TDriver() >>>\n\n");
|
||||||
delete [] oOpponents;
|
delete [] oOpponents;
|
||||||
|
|
||||||
if (oCarType != NULL)
|
|
||||||
free(oCarType);
|
|
||||||
|
|
||||||
if (oStrategy != NULL)
|
if (oStrategy != NULL)
|
||||||
delete oStrategy;
|
delete oStrategy;
|
||||||
if (oSysFooStuckX != NULL)
|
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
|
// Adjust car characteristic
|
||||||
//--------------------------------------------------------------------------*
|
//--------------------------------------------------------------------------*
|
||||||
|
@ -670,7 +607,7 @@ void TDriver::AdjustCarCharacteristic(PCarHandle Handle)
|
||||||
CarCharacteristic.Init(ControlPoints, X, Y, S);
|
CarCharacteristic.Init(ControlPoints, X, Y, S);
|
||||||
|
|
||||||
snprintf(buf, BUFLEN, "%sCharacteristic-%s.txt",
|
snprintf(buf, BUFLEN, "%sCharacteristic-%s.txt",
|
||||||
GetLocalDir(),oBotName);
|
GetLocalDir(), oDriverName.c_str());
|
||||||
|
|
||||||
SaveCharacteristicToFile(buf);
|
SaveCharacteristicToFile(buf);
|
||||||
};
|
};
|
||||||
|
@ -1334,9 +1271,9 @@ void TDriver::SetPathAndFilenameForRacinglines()
|
||||||
{
|
{
|
||||||
const char* PathToWriteTo = GetLocalDir();
|
const char* PathToWriteTo = GetLocalDir();
|
||||||
|
|
||||||
snprintf(PathToWriteToBuffer,sizeof(TrackLoadBuffer),
|
snprintf(PathToWriteToBuffer, sizeof(TrackLoadBuffer),
|
||||||
"%sdrivers/simplix_common/racinglines/%s/%s",
|
"%sdrivers/simplix_common/racinglines/%s/%s",
|
||||||
PathToWriteTo,MyBotName,oCarType);
|
PathToWriteTo, MyBotName, oCarType.c_str());
|
||||||
oPathToWriteTo = PathToWriteToBuffer;
|
oPathToWriteTo = PathToWriteToBuffer;
|
||||||
if (GfDirCreate(oPathToWriteTo) == GF_DIR_CREATION_FAILED)
|
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)
|
// Default params for car type (e.g. .../ROBOT_DIR/sc-petrol/default.xml)
|
||||||
snprintf(Buf,sizeof(Buf),"%s/%s/default.xml",
|
snprintf(Buf,sizeof(Buf),"%s/%s/default.xml",
|
||||||
BaseParamPath,oCarType);
|
BaseParamPath, oCarType.c_str());
|
||||||
if (GfFileExists(Buf))
|
if (GfFileExists(Buf))
|
||||||
{
|
{
|
||||||
LogSimplix.info("#Default params for car type: %s\n", 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
|
// Override params for car type with params of track
|
||||||
snprintf(Buf,sizeof(Buf),"%s/%s/%s.xml",
|
snprintf(Buf,sizeof(Buf),"%s/%s/%s.xml",
|
||||||
BaseParamPath,oCarType,oTrackName);
|
BaseParamPath, oCarType.c_str(), oTrackName);
|
||||||
if (GfFileExists(Buf))
|
if (GfFileExists(Buf))
|
||||||
{
|
{
|
||||||
LogSimplix.info("#Override params for car type with params of track: %s\n", 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
|
// Override params for car type with params of track and weather
|
||||||
snprintf(Buf,sizeof(Buf),"%s/%s/%s-%d.xml",
|
snprintf(Buf,sizeof(Buf),"%s/%s/%s-%d.xml",
|
||||||
BaseParamPath,oCarType,oTrackName,oWeatherCode);
|
BaseParamPath, oCarType.c_str(),oTrackName, oWeatherCode);
|
||||||
if (GfFileExists(Buf))
|
if (GfFileExists(Buf))
|
||||||
{
|
{
|
||||||
LogSimplix.info("#Override params for car type with params of track and weather: %s\n", 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
|
// Override params for car type on track with params of specific race type
|
||||||
snprintf(Buf,sizeof(Buf),"%s/%s/%s-%s.xml",
|
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))
|
if (GfFileExists(Buf))
|
||||||
{
|
{
|
||||||
LogSimplix.info("#Override params for car type on track with params of specific race type: %s\n", 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
|
Param.Update(); // update car parameters
|
||||||
|
|
||||||
LogSimplix.debug("# ... set track ...\n");
|
LogSimplix.debug("# ... set track ...\n");
|
||||||
if(oCommonData->Track != oTrackDesc.Track()) // New track?
|
|
||||||
{
|
|
||||||
oCommonData->Track = oTrackDesc.Track(); // Save pointer
|
|
||||||
}
|
|
||||||
|
|
||||||
LogSimplix.debug("# ... load smooth path ...\n");
|
LogSimplix.debug("# ... load smooth path ...\n");
|
||||||
if (oSituation->_raceType == RM_TYPE_PRACTICE)
|
if (oSituation->_raceType == RM_TYPE_PRACTICE)
|
||||||
|
@ -4682,17 +4615,6 @@ double TDriver::CalcSkill(double TargetSpeed)
|
||||||
}
|
}
|
||||||
return 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
|
// Set additional border to outer side
|
||||||
|
|
|
@ -63,7 +63,6 @@
|
||||||
|
|
||||||
#include "unitglobal.h"
|
#include "unitglobal.h"
|
||||||
#include "unitcommon.h"
|
#include "unitcommon.h"
|
||||||
#include "unitcommondata.h"
|
|
||||||
|
|
||||||
#include "unitcharacteristic.h"
|
#include "unitcharacteristic.h"
|
||||||
#include "unitcollision.h"
|
#include "unitcollision.h"
|
||||||
|
@ -85,7 +84,8 @@
|
||||||
class TDriver
|
class TDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TDriver(void *params, int Index); // Constructor
|
TDriver(const std::string &name, const std::string &car,
|
||||||
|
const std::string &category, int Index);
|
||||||
~TDriver(); // Destructor
|
~TDriver(); // Destructor
|
||||||
|
|
||||||
// TORCS-Interface:
|
// TORCS-Interface:
|
||||||
|
@ -156,11 +156,7 @@ class TDriver
|
||||||
void BrakingForceController(); // PID controller
|
void BrakingForceController(); // PID controller
|
||||||
void LearnBraking(double Pos); // Learn braking parameters
|
void LearnBraking(double Pos); // Learn braking parameters
|
||||||
|
|
||||||
void SetBotName // Set name of bot
|
inline const std::string &GetDriverName() const;
|
||||||
(void* RobotSettings, const char* Value);
|
|
||||||
inline void SetCommonData // Set pointer to common data
|
|
||||||
(TCommonData* CommonData);
|
|
||||||
inline const char* GetBotName();
|
|
||||||
inline float CurrSpeed();
|
inline float CurrSpeed();
|
||||||
inline int TeamIndex();
|
inline int TeamIndex();
|
||||||
|
|
||||||
|
@ -207,12 +203,11 @@ private:
|
||||||
double CalcSkill(double TargetSpeed);
|
double CalcSkill(double TargetSpeed);
|
||||||
bool CheckPitSharing();
|
bool CheckPitSharing();
|
||||||
bool SaveToFile();
|
bool SaveToFile();
|
||||||
int getRobotType(void *h, unsigned index) const;
|
int getRobotType(const std::string &h) const;
|
||||||
void setCategoryParams();
|
void setCategoryParams();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TCommonData* oCommonData; // Pointer to common data
|
|
||||||
TTrackDescription oTrackDesc; // Track description
|
TTrackDescription oTrackDesc; // Track description
|
||||||
std::vector<TClothoidLane> oRacingLine; // Racinglines
|
std::vector<TClothoidLane> oRacingLine; // Racinglines
|
||||||
|
|
||||||
|
@ -269,9 +264,7 @@ private:
|
||||||
bool oAlone; // No opponent near
|
bool oAlone; // No opponent near
|
||||||
double oAngle; // Actual Angle
|
double oAngle; // Actual Angle
|
||||||
double oAngleSpeed; // Angle of speed
|
double oAngleSpeed; // Angle of speed
|
||||||
const char* oBotName; // Name of driver
|
const std::string oDriverName;
|
||||||
const char* oTeamName; // Name of team
|
|
||||||
int oRaceNumber; // Race number
|
|
||||||
bool oWingControl; // Enable wing control
|
bool oWingControl; // Enable wing control
|
||||||
double oWingAngleFront; // Front wing angle of attack
|
double oWingAngleFront; // Front wing angle of attack
|
||||||
double oWingAngleRear; // Rear wing angle of attack
|
double oWingAngleRear; // Rear wing angle of attack
|
||||||
|
@ -295,7 +288,7 @@ private:
|
||||||
double oInitialBrakeCoeff;
|
double oInitialBrakeCoeff;
|
||||||
PtCarElt oCar; // TORCS data for own car
|
PtCarElt oCar; // TORCS data for own car
|
||||||
float oSteerAngle; // Angle to steer
|
float oSteerAngle; // Angle to steer
|
||||||
char* oCarType; // Type name of own car
|
const std::string oCarType; // Type name of own car
|
||||||
double oClutchMax;
|
double oClutchMax;
|
||||||
double oClutchDelta;
|
double oClutchDelta;
|
||||||
double oClutchRange;
|
double oClutchRange;
|
||||||
|
@ -308,7 +301,6 @@ private:
|
||||||
double oShiftUp[MAX_GEARS]; // Shift by setup
|
double oShiftUp[MAX_GEARS]; // Shift by setup
|
||||||
double oEarlyShiftFactor; // Early shifting
|
double oEarlyShiftFactor; // Early shifting
|
||||||
int oShiftCounter; // Shift timer
|
int oShiftCounter; // Shift timer
|
||||||
int oExtended; // Information if this robot is extended (oExtended = 1) or not (oExtended = 0).
|
|
||||||
int oLastGear; // Last gear
|
int oLastGear; // Last gear
|
||||||
int oLastUsedGear; // Last used gear
|
int oLastUsedGear; // Last used gear
|
||||||
bool oLetPass; // Let opoonent pass
|
bool oLetPass; // Let opoonent pass
|
||||||
|
@ -402,7 +394,7 @@ private:
|
||||||
unsigned int oRandomSeed; // seed of generator
|
unsigned int oRandomSeed; // seed of generator
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int oIndex; // index of own driver
|
const int oIndex; // index of own driver
|
||||||
int oTestPitStop; // Test pit stop
|
int oTestPitStop; // Test pit stop
|
||||||
bool oShowPlot;
|
bool oShowPlot;
|
||||||
|
|
||||||
|
@ -481,7 +473,6 @@ private:
|
||||||
|
|
||||||
static bool FirstPropagation;
|
static bool FirstPropagation;
|
||||||
|
|
||||||
void ScaleSide(float FactorMu, float FactorBrake);
|
|
||||||
void SideBorderOuter(float Factor);
|
void SideBorderOuter(float Factor);
|
||||||
void SideBorderInner(float Factor);
|
void SideBorderInner(float Factor);
|
||||||
|
|
||||||
|
@ -539,8 +530,8 @@ private:
|
||||||
//==========================================================================*
|
//==========================================================================*
|
||||||
// Get name of robot
|
// Get name of robot
|
||||||
//--------------------------------------------------------------------------*
|
//--------------------------------------------------------------------------*
|
||||||
const char* TDriver::GetBotName()
|
const std::string &TDriver::GetDriverName() const
|
||||||
{return oBotName;};
|
{return oDriverName;};
|
||||||
//==========================================================================*
|
//==========================================================================*
|
||||||
|
|
||||||
//==========================================================================*
|
//==========================================================================*
|
||||||
|
@ -550,14 +541,6 @@ int TDriver::TeamIndex()
|
||||||
{return oTeamIndex;};
|
{return oTeamIndex;};
|
||||||
//==========================================================================*
|
//==========================================================================*
|
||||||
|
|
||||||
//==========================================================================*
|
|
||||||
// Set pointer to common data
|
|
||||||
//--------------------------------------------------------------------------*
|
|
||||||
void TDriver::SetCommonData
|
|
||||||
(TCommonData* CommonData)
|
|
||||||
{oCommonData = CommonData;};
|
|
||||||
//==========================================================================*
|
|
||||||
|
|
||||||
//==========================================================================*
|
//==========================================================================*
|
||||||
// Get Pointer to TORCS data of track
|
// Get Pointer to TORCS data of track
|
||||||
//--------------------------------------------------------------------------*
|
//--------------------------------------------------------------------------*
|
||||||
|
|
|
@ -117,10 +117,10 @@ bool TSimpleStrategy::IsPitFree()
|
||||||
bool IsFree = RtTeamIsPitFree(oDriver->TeamIndex());
|
bool IsFree = RtTeamIsPitFree(oDriver->TeamIndex());
|
||||||
if (IsFree)
|
if (IsFree)
|
||||||
LogSimplix.debug("#%s pit is free (%d)\n",
|
LogSimplix.debug("#%s pit is free (%d)\n",
|
||||||
oDriver->GetBotName(),oDriver->TeamIndex());
|
oDriver->GetDriverName(),oDriver->TeamIndex());
|
||||||
else
|
else
|
||||||
LogSimplix.debug("#%s pit is locked (%d)\n",
|
LogSimplix.debug("#%s pit is locked (%d)\n",
|
||||||
oDriver->GetBotName(),oDriver->TeamIndex());
|
oDriver->GetDriverName(),oDriver->TeamIndex());
|
||||||
return IsFree;
|
return IsFree;
|
||||||
}
|
}
|
||||||
//==========================================================================*
|
//==========================================================================*
|
||||||
|
@ -150,7 +150,7 @@ bool TSimpleStrategy::NeedPitStop()
|
||||||
if (MIN(TdF,TdR) < 1.5 * oDegradationPerLap) // tyres become critical
|
if (MIN(TdF,TdR) < 1.5 * oDegradationPerLap) // tyres become critical
|
||||||
{
|
{
|
||||||
LogSimplix.warning("Tyre condition D: %.1f%% F: %.1f%% R: %.1f%% (%s)\n",
|
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)
|
if ((TdF < 1.1 * oDegradationPerLap)
|
||||||
|| (TdR < 1.1 * oDegradationPerLap))
|
|| (TdR < 1.1 * oDegradationPerLap))
|
||||||
|
@ -537,7 +537,7 @@ void TSimpleStrategy::CheckPitState(float /*PitScaleBrake*/)
|
||||||
&& ((Major > NEEDED_MAJOR_VERSION)
|
&& ((Major > NEEDED_MAJOR_VERSION)
|
||||||
|| ((Major = NEEDED_MAJOR_VERSION) && (Minor >= NEEDED_MINOR_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("#StillToGo : %.2f m\n",TeamDriver->StillToGo);
|
||||||
LogSimplix.debug("#MoreOffset: %.2f m\n",TeamDriver->MoreOffset);
|
LogSimplix.debug("#MoreOffset: %.2f m\n",TeamDriver->MoreOffset);
|
||||||
LogSimplix.debug("#TooFastBy : %.2f m/s\n",TeamDriver->TooFastBy);
|
LogSimplix.debug("#TooFastBy : %.2f m/s\n",TeamDriver->TooFastBy);
|
||||||
|
|
Loading…
Reference in a new issue