diff --git a/src/interfaces/CMakeLists.txt b/src/interfaces/CMakeLists.txt index 39cef89a..ea796aa5 100644 --- a/src/interfaces/CMakeLists.txt +++ b/src/interfaces/CMakeLists.txt @@ -1,8 +1,8 @@ INCLUDE(../../cmake/macros.cmake) SET(INTERFACES_HEADERS car.h graphic.h playerpref.h raceman.h - replay.h robot.h simu.h telemetry.h track.h + replay.h robot.h telemetry.h track.h iraceengine.h iuserinterface.h igraphicsengine.h - itrackloader.h) + iphysicsengine.h itrackloader.h) SD_INSTALL_FILES(INCLUDE FILES ${INTERFACES_HEADERS}) diff --git a/src/interfaces/iphysicsengine.h b/src/interfaces/iphysicsengine.h new file mode 100644 index 00000000..c32c1dac --- /dev/null +++ b/src/interfaces/iphysicsengine.h @@ -0,0 +1,62 @@ +/*************************************************************************** + iphysicsengine.h -- Interface for physics engines + + created : Tue May 10 22:40:04 CEST 2011 + copyright : (C) 2011 by Jean-Philippe Meuret + web : http://www.speed-dreams.org + version : $Id$ + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +/** @file + Interface for physics engines + @version $Id$ +*/ + +#ifndef __IPHYSICSENGINE__H__ +#define __IPHYSICSENGINE__H__ + +struct DynPt; + + +class IPhysicsEngine +{ +public: + + //! Initial setup + virtual void initialize(int nCars, struct Track* pTrack) = 0; + + //! Initial configuration + virtual void configureCar(struct CarElt* pCar) = 0; + + //! After pit stop + virtual void reconfigureCar(struct CarElt* pCar) = 0; + + //! Activate / Deactivate telemetry for a given car (Limitation: only one at a time). + virtual void toggleCarTelemetry(int nCarIndex, bool bOn = true) = 0; + + //! Update the situation (1 simulation step) + virtual void updateSituation(struct Situation *pSituation, double fDeltaTime) = 0; + + //! Update only a given car (1 simulation step) + virtual void updateCar(struct Situation *pSituation, double fDeltaTime, int nCarIndex) = 0; + + //! For network races, force the DynGCG of a given car (computed by a remote instance). + virtual void setCar(const struct DynPt& dynGCG, int nCarIndex) = 0; + + //! For network races, read the DynGCG of a given car. + virtual struct DynPt* getCar(int nCarIndex) = 0; + + //! Reset => ready for a new initialize + virtual void shutdown() = 0; +}; + +#endif // __IPHYSICSENGINE__H__ diff --git a/src/interfaces/raceman.h b/src/interfaces/raceman.h index c4d9df77..c50bcc4b 100755 --- a/src/interfaces/raceman.h +++ b/src/interfaces/raceman.h @@ -30,7 +30,6 @@ #include #include #include -#include #define RCM_IDENT 0 @@ -100,12 +99,7 @@ typedef struct Situation { tCarElt **cars; /**< list of cars */ } tSituation; -/** Race Engine */ -typedef struct -{ - tSimItf simItf; -} tRaceModIft; - +/** Race Engine states */ #define RE_STATE_CONFIG 0 #define RE_STATE_EVENT_INIT 1 #define RE_STATE_PRE_RACE 3 @@ -148,7 +142,6 @@ typedef struct { int state; void *param; - tRaceModIft itf; void *gameScreen; void *menuScreen; const char *filename; @@ -210,7 +203,7 @@ typedef struct RmInfo void *mainParams; /**< Stays the same even if params change because of more xml-files per raceman */ void *results; /**< Race results */ void *mainResults; /**< Stays the same even if params change because of more xml-files per raceman */ - tModList **modList; /**< drivers loaded */ + tModList **robModList; /**< robot modules loaded */ tRmCarRules *rules; /**< by car rules */ tRaceEngineInfo raceEngineInfo; } tRmInfo; diff --git a/src/interfaces/simu.h b/src/interfaces/simu.h deleted file mode 100755 index c1f84f04..00000000 --- a/src/interfaces/simu.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - - file : simu.h - created : Sun Jan 30 12:02:05 CET 2000 - copyright : (C) 2000 by Eric Espie - email : torcs@free.fr - version : $Id$ - - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 _SIMUV1_H_ -#define _SIMUV1_H_ - -#include -#include - -#define SIM_IDENT 0 - -struct Situation; -struct RmInfo; - -typedef void (*tfSimInit)(int, tTrack*); -typedef void (*tfSimConfig)(tCarElt*, struct RmInfo*); -typedef void (*tfSimReConfig)(tCarElt*); -typedef void (*tfSimUpdate)(struct Situation*, double, int); -typedef void (*tfSimSingleUpdate)(int index,double deltaTime, struct Situation* s); -typedef void (*tfSimShutdown)(void); -typedef void (*tfUpdateSimCarTable)(tDynPt DynGCG,int index); -typedef tDynPt* (*tfGetSimCarTable)(int index); - -typedef struct -{ - tfSimInit init; - tfSimConfig config; - tfSimReConfig reconfig; - tfSimUpdate update; - tfSimSingleUpdate singleupdate; - tfSimShutdown shutdown; - tfUpdateSimCarTable updatesimcartable; - tfGetSimCarTable getsimcartable; - -} tSimItf; - - - -#endif /* _SIMUV1_H_ */ - - - diff --git a/src/libs/raceengine/racecars.cpp b/src/libs/raceengine/racecars.cpp index ba749c65..fb6089fd 100644 --- a/src/libs/raceengine/racecars.cpp +++ b/src/libs/raceengine/racecars.cpp @@ -55,7 +55,8 @@ ReCarsUpdateCarPitTime(tCarElt *car) case RM_PIT_REPAIR: info->totalPitTime = 2.0f + fabs((double)(car->_pitFuel)) / 8.0f + (tdble)(fabs((double)(car->_pitRepair))) * 0.007f; car->_scheduledEventTime = s->currentTime + info->totalPitTime; - ReInfo->_reSimItf.reconfig(car); + RePhysicsEngine().reconfigureCar(car); + for (i=0; i<4; i++) { car->_tyreCondition(i) = 1.01f; car->_tyreT_in(i) = 50.0f; diff --git a/src/libs/raceengine/raceengine.cpp b/src/libs/raceengine/raceengine.cpp index e5ab396c..3e41a143 100644 --- a/src/libs/raceengine/raceengine.cpp +++ b/src/libs/raceengine/raceengine.cpp @@ -171,6 +171,19 @@ IUserInterface& RaceEngine::userInterface() return *_piUserItf; } +// Set the physics engine. +void RaceEngine::setPhysicsEngine(IPhysicsEngine* piPhysEngine) +{ + _piPhysEngine = piPhysEngine; +} + +// Accessor to the physics engine. +IPhysicsEngine& RaceEngine::physicsEngine() +{ + return *_piPhysEngine; +} + + //************************************************************ // WIP : dedicated situation setters. diff --git a/src/libs/raceengine/raceengine.h b/src/libs/raceengine/raceengine.h index 7814fb4d..5840a7cb 100644 --- a/src/libs/raceengine/raceengine.h +++ b/src/libs/raceengine/raceengine.h @@ -24,6 +24,7 @@ #ifndef _RACEENGINE_H_ #define _RACEENGINE_H_ +#include #include @@ -92,6 +93,12 @@ public: // Accessor to the user interface. IUserInterface& userInterface(); + // Set the physics engine. + void setPhysicsEngine(IPhysicsEngine* piPhysEngine); + + // Accessor to the physics engine. + IPhysicsEngine& physicsEngine(); + protected: // Protected constructor to avoid instanciation outside of self(). @@ -104,6 +111,9 @@ protected: // The user interface. IUserInterface* _piUserItf; + + // The physics engine. + IPhysicsEngine* _piPhysEngine; }; //! Shortcut to the user interface. @@ -112,4 +122,10 @@ inline extern IUserInterface& ReUI() return RaceEngine::self().userInterface(); } +//! Shortcut to the physics engine. +inline extern IPhysicsEngine& RePhysicsEngine() +{ + return RaceEngine::self().physicsEngine(); +} + #endif /* _RACEENGINE_H_ */ diff --git a/src/libs/raceengine/raceinit.cpp b/src/libs/raceengine/raceinit.cpp index 2feffa01..79c0ea92 100644 --- a/src/libs/raceengine/raceinit.cpp +++ b/src/libs/raceengine/raceinit.cpp @@ -17,14 +17,11 @@ ***************************************************************************/ /** @file - + Race initialization routines @author Eric Espie @version $Id$ */ - -/* Race initialization routines */ - #include #include #include @@ -56,18 +53,17 @@ #include "raceinit.h" -static const char *level_str[] = +static const char *aPszSkillLevelNames[] = { ROB_VAL_ROOKIE, ROB_VAL_AMATEUR, ROB_VAL_SEMI_PRO, ROB_VAL_PRO }; +static const int NSkillLevels = (int)(sizeof(aPszSkillLevelNames)/sizeof(char*)); -static tModList *reEventModList = 0; - -// Modules ... ? -tModList *ReRaceModList = 0; +// The list of robot modules loaded for the race. +tModList *ReRacingRobotsModList = 0; // The race situation tRmInfo *ReInfo = 0; -// The race (temporary partially duplicates ReInfo, as long as not merged). +// The race (temporary partial duplicate of ReInfo, as long as not merged). static GfRace* PReRace = 0; GfRace* ReGetRace() @@ -75,7 +71,6 @@ GfRace* ReGetRace() return PReRace; } - /* Race Engine Initialization */ void ReInit(void) @@ -91,7 +86,7 @@ ReInit(void) // Allocate race engine info structures. ReInfo = ReSituation::self().data(); - ReInfo->modList = &ReRaceModList; + ReInfo->robModList = &ReRacingRobotsModList; // Load Race engine params. char buf[256]; @@ -110,8 +105,11 @@ ReInit(void) ITrackLoader* piTrkLoader = 0; if (pmodTrkLoader) piTrkLoader = pmodTrkLoader->getInterface(); - if (!piTrkLoader) + if (pmodTrkLoader && !piTrkLoader) + { + GfModule::unload(pmodTrkLoader); return; + } // Initialize GfTracks' track module interface (needed for some track infos). GfTracks::self()->setTrackLoader(piTrkLoader); @@ -148,13 +146,21 @@ void ReShutdown(void) ITrackLoader* piTrkLoader = GfTracks::self()->getTrackLoader(); piTrkLoader->unload(); - // Unload the Simu, Track loader and Graphics modules. - GfModUnloadList(&reEventModList); - - GfModule* pmodTrkLoader = dynamic_cast(piTrkLoader); - GfModule::unload(pmodTrkLoader); - GfTracks::self()->setTrackLoader(0); + // Unload the Physics engine, Track loader and Graphics modules if not already done. + GfModule* pmodPhysEngine = dynamic_cast(&RePhysicsEngine()); + if (pmodPhysEngine) + { + GfModule::unload(pmodPhysEngine); + RaceEngine::self().setPhysicsEngine(0); + } + GfModule* pmodTrkLoader = dynamic_cast(piTrkLoader); + if (pmodTrkLoader) + { + GfModule::unload(pmodTrkLoader); + GfTracks::self()->setTrackLoader(0); + } + ReUI().shutdownGraphics(); // => onRaceEngineShutdown ? // Free ReInfo memory. @@ -342,7 +348,8 @@ initStartingGrid(void) car->_pos_Z = RtTrackHeightL(&(car->_trkPos)) + heightInit; NORM0_2PI(car->_yaw); - ReInfo->_reSimItf.config(car, ReInfo); + + RePhysicsEngine().configureCar(car); } } @@ -491,7 +498,7 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int int robotIdx = relativeRobotIdx; /* good robot found */ - curModInfo = &((*(ReInfo->modList))->modInfo[modindex]); + curModInfo = &((*(ReInfo->robModList))->modInfo[modindex]); GfLogInfo("Driver's name: %s\n", curModInfo->name); isHuman = strcmp( cardllname, "human" ) == 0 || strcmp( cardllname, "networkhuman" ) == 0; @@ -593,8 +600,8 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int elt->_raceNumber += elt->_moduleIndex; elt->_skillLevel = 0; str = GfParmGetStr(robhdle, path, ROB_ATTR_LEVEL, ROB_VAL_SEMI_PRO); - for(k = 0; k < (int)(sizeof(level_str)/sizeof(char*)); k++) { - if (strcmp(level_str[k], str) == 0) { + for(k = 0; k < NSkillLevels; k++) { + if (strcmp(aPszSkillLevelNames[k], str) == 0) { elt->_skillLevel = k; break; } @@ -752,7 +759,7 @@ ReInitCars(void) snprintf(path, sizeof(path), "%sdrivers/%s/%s.%s", GfLibDir(), robotModuleName, robotModuleName, DLLEXT); /* Load the robot shared library */ - if (GfModLoad(CAR_IDENT, path, ReInfo->modList)) + if (GfModLoad(CAR_IDENT, path, ReInfo->robModList)) { GfLogError("Failed to load robot module %s\n", path); continue; @@ -765,9 +772,9 @@ ReInitCars(void) { /* Search for the index of the racing driver in the list of interfaces of the module */ - for (j = 0; j < (*(ReInfo->modList))->modInfoSize; j++) + for (j = 0; j < (*(ReInfo->robModList))->modInfoSize; j++) { - if ((*(ReInfo->modList))->modInfo[j].name && (*(ReInfo->modList))->modInfo[j].index == robotIdx) + if ((*(ReInfo->robModList))->modInfo[j].name && (*(ReInfo->robModList))->modInfo[j].index == robotIdx) { /* We have the right driver : load it */ elt = reLoadSingleCar( index, i, j, robotIdx, TRUE, robotModuleName ); @@ -800,12 +807,12 @@ ReInitCars(void) if (robhdle && ( strcmp( robotModuleName, "human" ) == 0 || strcmp( robotModuleName, "networkhuman" ) == 0 ) ) { /* Human driver */ - elt = reLoadSingleCar( index, i, robotIdx - (*(ReInfo->modList))->modInfo[0].index, robotIdx, FALSE, robotModuleName ); + elt = reLoadSingleCar( index, i, robotIdx - (*(ReInfo->robModList))->modInfo[0].index, robotIdx, FALSE, robotModuleName ); } else if (robhdle && ( strcmp( GfParmGetStr( robhdle, ROB_SECT_ARBITRARY, ROB_ATTR_TEAM, "foo" ), GfParmGetStr( robhdle, ROB_SECT_ARBITRARY, ROB_ATTR_TEAM, "bar" ) ) == 0 ) ) { - elt = reLoadSingleCar( index, i, (*(ReInfo->modList))->modInfoSize, robotIdx, FALSE, robotModuleName ); + elt = reLoadSingleCar( index, i, (*(ReInfo->robModList))->modInfoSize, robotIdx, FALSE, robotModuleName ); } else GfLogError("No descriptor for robot %s (2)\n", robotModuleName ); @@ -839,7 +846,7 @@ ReInitCars(void) // I stuff for now anything into one call because collision detection works with the same // library on all objects, so it is a bit dangerous to distribute the handling to various // locations (because the library maintains global state like a default collision handler etc.). - ReInfo->_reSimItf.init(nCars, ReInfo->track); + RePhysicsEngine().initialize(nCars, ReInfo->track); initStartingGrid(); @@ -853,7 +860,7 @@ ReRaceCleanup(void) { ReInfo->_reGameScreen = ReUI().createRaceEventLoopHook(); - ReInfo->_reSimItf.shutdown(); + RePhysicsEngine().shutdown(); if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL) { @@ -896,7 +903,7 @@ ReRaceCleanDrivers(void) FREEZ(ReInfo->s->cars); ReInfo->s->cars = 0; ReInfo->s->_ncars = 0; - GfModUnloadList(&ReRaceModList); + GfModUnloadList(&ReRacingRobotsModList); } // Get the name of the current "race" diff --git a/src/libs/raceengine/raceinit.h b/src/libs/raceengine/raceinit.h index e5c53232..747072c1 100644 --- a/src/libs/raceengine/raceinit.h +++ b/src/libs/raceengine/raceinit.h @@ -50,7 +50,7 @@ extern char *ReGetCurrentRaceName(void); extern char *ReGetPrevRaceName(void); -extern tModList *ReRaceModList; +extern tModList *ReRacingRobotsModList; // The race situation data structure. // WIP: Remove this global variable that anyone can wildly change diff --git a/src/libs/raceengine/racemain.cpp b/src/libs/raceengine/racemain.cpp index daaecaa9..d94f3e8c 100644 --- a/src/libs/raceengine/racemain.cpp +++ b/src/libs/raceengine/racemain.cpp @@ -22,7 +22,10 @@ @version $Id$ */ +#include + #include +#include #include #include @@ -79,7 +82,7 @@ void ReRaceAbort() { ReShutdownUpdaters(); - ReInfo->_reSimItf.shutdown(); + RePhysicsEngine().shutdown(); // TODO: Move these 3 XXGraphicsYY calls to the user interface module ? if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL) @@ -257,8 +260,6 @@ ReRaceRealStart(void) int i, j; tRobotItf *robot; tReCarInfo *carInfo; - const char *dllname; - char path[256]; char buf[128]; int foundHuman; void *params = ReInfo->params; @@ -267,14 +268,27 @@ ReRaceRealStart(void) tMemoryPool oldPool = NULL; void* carHdle; - // Load simulation engine - dllname = GfParmGetStr(ReInfo->_reParam, "Modules", "simu", ""); - snprintf(buf, sizeof(buf), "Loading simulation engine (%s) ...", dllname); + // Load the physics engine + const char* pszModName = GfParmGetStr(ReInfo->_reParam, "Modules", "simu", ""); + snprintf(buf, sizeof(buf), "Loading physics engine (%s) ...", pszModName); ReUI().addLoadingMessage(buf); - snprintf(path, sizeof(path), "%smodules/simu/%s.%s", GfLibDir (), dllname, DLLEXT); - if (GfModLoad(0, path, &ReRaceModList)) + + std::ostringstream ossModLibName; + ossModLibName << GfLibDir() << "modules/simu/" << pszModName << '.' << DLLEXT; + GfModule* pmodPhysEngine = GfModule::load(ossModLibName.str()); + IPhysicsEngine* piPhysEngine = 0; + if (pmodPhysEngine) + { + piPhysEngine = pmodPhysEngine->getInterface(); + if (piPhysEngine) // Check that it implements IPhysicsEngine. + RaceEngine::self().setPhysicsEngine(piPhysEngine); + } + + if (pmodPhysEngine && !piPhysEngine) + GfModule::unload(pmodPhysEngine); + + if (!pmodPhysEngine) return RM_ERROR; - ReRaceModList->modInfo->fctInit(ReRaceModList->modInfo->index, &ReInfo->_reSimItf); // Check if there is a human in the driver list foundHuman = ReHumanInGroup() ? 2 : 0; @@ -361,7 +375,7 @@ ReRaceRealStart(void) RtTeamManagerStart(); // TODO: Try and move this into the user interface module, - // right after it called ReRaceStart ? + // right after it calls ReRaceStart ? // Initialize the graphics engine if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL) { @@ -378,7 +392,8 @@ ReRaceRealStart(void) } // Initialize the physics engine - ReInfo->_reSimItf.update(s, RCM_MAX_DT_SIMU, -1); + RePhysicsEngine().updateSituation(s, RCM_MAX_DT_SIMU); + for (i = 0; i < s->_ncars; i++) { carInfo[i].prevTrkPos = s->cars[i]->_trkPos; } @@ -390,7 +405,7 @@ ReRaceRealStart(void) s->cars[i]->ctrl.brakeCmd = 1.0; } for (j = 0; j < (int)(1.0 / RCM_MAX_DT_SIMU); j++) { - ReInfo->_reSimItf.update(s, RCM_MAX_DT_SIMU, -1); + RePhysicsEngine().updateSituation(s, RCM_MAX_DT_SIMU); } if (ReInfo->_displayMode != RM_DISP_MODE_NORMAL) { diff --git a/src/libs/raceengine/racenetwork.cpp b/src/libs/raceengine/racenetwork.cpp index 3e0634f8..335def41 100644 --- a/src/libs/raceengine/racenetwork.cpp +++ b/src/libs/raceengine/racenetwork.cpp @@ -33,8 +33,7 @@ static void reNetworkSetCarPhysics(double timeDelta,CarControlsData *pCt) { - tDynPt *pDynCG = NULL; - pDynCG = ReInfo->_reSimItf.getsimcartable(pCt->startRank); + tDynPt *pDynCG = RePhysicsEngine().getCar(pCt->startRank); // double errX = pDynCG->pos.x-pCt->DynGCg.pos.x; // double errY = pDynCG->pos.y-pCt->DynGCg.pos.y; @@ -68,14 +67,14 @@ reNetworkSetCarPhysics(double timeDelta,CarControlsData *pCt) step = timeDelta; timeDelta-=step; - ReInfo->_reSimItf.singleupdate(pCt->startRank,step,ReInfo->s); + RePhysicsEngine().updateCar(ReInfo->s, step, pCt->startRank); } } //GfLogTrace("Network position error is %lf %lf %lf and delta is %lf\n",errX,errY,errZ,timeDelta); //Car physics -// ReInfo->_reSimItf.updatesimcartable(pCt->DynGCg,pCt->startRank); +// RePhysicsEngine().setCar(pCt->DynGCg, pCt->startRank); } static void diff --git a/src/libs/raceengine/racesituation.cpp b/src/libs/raceengine/racesituation.cpp index da04ff7a..71f1dc98 100644 --- a/src/libs/raceengine/racesituation.cpp +++ b/src/libs/raceengine/racesituation.cpp @@ -34,6 +34,8 @@ #include #include +#include "raceengine.h" + #include "racecars.h" #include "racesituation.h" @@ -293,15 +295,15 @@ void ReSituationUpdater::runOneStep(double deltaTimeIncrement) if (GetNetwork()) ReNetworkOneStep(); - GfProfStartProfile("_reSimItf.update*"); + GfProfStartProfile("physicsEngine.update*"); GfSchedBeginEvent("raceupdate", "physics"); - pCurrReInfo->_reSimItf.update(s, deltaTimeIncrement, -1); + RePhysicsEngine().updateSituation(s, deltaTimeIncrement); bool bestLapChanged = false; for (int i = 0; i < s->_ncars; i++) ReCarsManageCar(s->cars[i], bestLapChanged); GfSchedEndEvent("raceupdate", "physics"); - GfProfStopProfile("_reSimItf.update*"); + GfProfStopProfile("physicsEngine.update*"); ReCarsSortCars(); @@ -563,8 +565,7 @@ tRmInfo* ReSituationUpdater::initSituation(const tRmInfo* pSource) pTarget->mainParams = pSource->mainParams; // Never read/written during the race. pTarget->results = pSource->results; // Never read/written during the race. pTarget->mainResults = pSource->mainResults; // Never read/written during the race. - pTarget->modList = pSource->modList; // Not used / written by updater. - // pTarget->movieCapture = pSource->movieCapture; // Not used by updater. + pTarget->robModList = pSource->robModList; // Not used / written by updater. // Assign level 2 constants and initialize lists in carList field. for (int nCarInd = 0; nCarInd < _nInitDrivers; nCarInd++) @@ -590,7 +591,6 @@ tRmInfo* ReSituationUpdater::initSituation(const tRmInfo* pSource) // Assign level 2 constants in raceEngineInfo field. pTarget->_reParam = pSource->_reParam; // Not used / written by updater. - pTarget->_reSimItf = pSource->_reSimItf; // Not used / written by updater. pTarget->_reGameScreen = pSource->_reGameScreen; // Nor changed nor shared during the race. pTarget->_reMenuScreen = pSource->_reMenuScreen; // Nor changed nor shared during the race. pTarget->_reFilename = pSource->_reFilename; // Not used during the race. diff --git a/src/libs/tgf/tgf.h b/src/libs/tgf/tgf.h index a4c60107..54b6a562 100644 --- a/src/libs/tgf/tgf.h +++ b/src/libs/tgf/tgf.h @@ -26,11 +26,6 @@ #define __TGF__H__ #include -//#include -//#include -//#include -//#include -//#include #include "osspec.h" @@ -138,7 +133,8 @@ typedef struct { /** 6 DOF position. @ingroup definitions */ -typedef struct { +typedef struct Posd +{ tdble x; /**< x coordinate */ tdble y; /**< y coordinate */ tdble z; /**< z coordinate */ @@ -150,7 +146,7 @@ typedef struct { /** Dynamic point structure. @ingroup definitions */ -typedef struct +typedef struct DynPt { tPosd pos; /**< position */ tPosd vel; /**< velocity */ @@ -158,7 +154,7 @@ typedef struct } tDynPt; /** Forces and moments */ -typedef struct +typedef struct Forces { t3Dd F; /**< Forces */ t3Dd M; /**< Moments */ diff --git a/src/modules/simu/simuv2.1/CMakeLists.txt b/src/modules/simu/simuv2.1/CMakeLists.txt index 442504bf..87da0880 100644 --- a/src/modules/simu/simuv2.1/CMakeLists.txt +++ b/src/modules/simu/simuv2.1/CMakeLists.txt @@ -8,30 +8,34 @@ ADD_SDLIB_INCLUDEDIR(portability) SET(SOLID_SOURCES SOLID-2.0/src/Transform.cpp SOLID-2.0/src/Convex.cpp SOLID-2.0/src/Box.cpp SOLID-2.0/src/Cone.cpp SOLID-2.0/src/Cylinder.cpp SOLID-2.0/src/Sphere.cpp SOLID-2.0/src/Simplex.cpp - SOLID-2.0/src/Polygon.cpp SOLID-2.0/src/Polyhedron.cpp - SOLID-2.0/src/Complex.cpp SOLID-2.0/src/BBoxTree.cpp - SOLID-2.0/src/Endpoint.cpp SOLID-2.0/src/Object.cpp - SOLID-2.0/src/Response.cpp SOLID-2.0/src/RespTable.cpp - SOLID-2.0/src/C-api.cpp) + SOLID-2.0/src/Polygon.cpp SOLID-2.0/src/Polyhedron.cpp + SOLID-2.0/src/Complex.cpp SOLID-2.0/src/BBoxTree.cpp + SOLID-2.0/src/Endpoint.cpp SOLID-2.0/src/Object.cpp + SOLID-2.0/src/Response.cpp SOLID-2.0/src/RespTable.cpp + SOLID-2.0/src/C-api.cpp) INCLUDE_DIRECTORIES(SOLID-2.0/include) IF(UNIX) - ADD_LIBRARY(SOLID-2.0/src/libsolid ${SOLID_SOURCES}) - SET_TARGET_PROPERTIES(SOLID-2.0/src/libsolid PROPERTIES PREFIX "" - COMPILE_FLAGS -fPIC) + ADD_LIBRARY(SOLID-2.0/src/libsolid ${SOLID_SOURCES}) + SET_TARGET_PROPERTIES(SOLID-2.0/src/libsolid PROPERTIES PREFIX "" + COMPILE_FLAGS -fPIC) ENDIF(UNIX) IF(WIN32) - # Ignore some run-time libs to avoid link time warnings and sometimes even crashes. + # DLL export stuff under Windows (to avoid .def file) + ADD_DEFINITIONS(-DSIMUV21_DLL) + + # Ignore some run-time libs to avoid link time warnings and sometimes even crashes. SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib") ENDIF(WIN32) -SET(SIMUV2.1_SOURCES aero.cpp axle.cpp brake.cpp car.cpp categories.cpp - collide.cpp differential.cpp engine.cpp simu.cpp simuitf.cpp - steer.cpp susp.cpp transmission.cpp wheel.cpp - aero.h axle.h brake.h carstruct.h differential.h engine.h - sim.h steer.h susp.h transmission.h wheel.h) +SET(SIMU_SOURCES aero.cpp axle.cpp brake.cpp car.cpp categories.cpp + collide.cpp differential.cpp engine.cpp simu.cpp + steer.cpp susp.cpp transmission.cpp wheel.cpp + aero.h axle.h brake.h carstruct.h differential.h engine.h + sim.h steer.h susp.h transmission.h wheel.h + simuv21.cpp simuv21.h) ADD_INTERFACE_INCLUDEDIR() @@ -39,17 +43,13 @@ ADD_PLIB_INCLUDEDIR() ADD_SDLIB_INCLUDEDIR(math tgf robottools) INCLUDE_DIRECTORIES(SOLID-2.0/include) -IF(WIN32) - ADD_LIBRARY(simuv2.1 SHARED ${SIMUV2.1_SOURCES} simuv2.1.def) -ELSE(WIN32) - ADD_LIBRARY(simuv2.1 SHARED ${SIMUV2.1_SOURCES}) -ENDIF(WIN32) - -IF(UNIX) - SET_TARGET_PROPERTIES(simuv2.1 PROPERTIES PREFIX "") -ENDIF(UNIX) +ADD_LIBRARY(simuv2.1 SHARED ${SIMU_SOURCES}) ADD_SDLIB_LIBRARY(simuv2.1 tgf robottools solid) +IF(UNIX) + SET_TARGET_PROPERTIES(simuv2.1 PROPERTIES PREFIX "") +ENDIF(UNIX) + SD_INSTALL_FILES(LIB modules/simu TARGETS simuv2.1) diff --git a/src/modules/simu/simuv2.1/sim.h b/src/modules/simu/simuv2.1/sim.h index bb4532ea..b3550ced 100644 --- a/src/modules/simu/simuv2.1/sim.h +++ b/src/modules/simu/simuv2.1/sim.h @@ -20,31 +20,30 @@ #ifndef _SIMFCT_H_ #define _SIMFCT_H_ -#include -#include +#include +#include #include -#ifdef WIN32 -#include -#define isnan _isnan -#endif +#include #include #include #include #include -#include -#include "carstruct.h" #include -extern void SimConfig(tCarElt *carElt, RmInfo *); +#include "carstruct.h" + + +extern void SimConfig(tCarElt *carElt); extern void SimReConfig(tCarElt *carElt); -extern void SimUpdate(tSituation*, double deltaTime, int telemetry); +extern void SimUpdate(tSituation*, double deltaTime); extern void SimInit(int nbcars, tTrack* track); extern void SimShutdown(void); + +extern void SimCarTelemetry(int nCarIndex, bool bOn = true); extern void UpdateSimCarTable(tDynPt DynGCG,int index); extern void SimUpdateSingleCar(int index, double deltaTime,tSituation *s); - -extern tDynPt * GetSimCarTable(int index); +extern tDynPt* GetSimCarTable(int index); extern void SimAxleConfig(tCar *car, int index); diff --git a/src/modules/simu/simuv2.1/simu.cpp b/src/modules/simu/simuv2.1/simu.cpp index 0ef799e3..9b5f2972 100644 --- a/src/modules/simu/simuv2.1/simu.cpp +++ b/src/modules/simu/simuv2.1/simu.cpp @@ -28,17 +28,20 @@ #include "sim.h" + tCar *SimCarTable = 0; tdble SimDeltaTime; -int SimTelemetry; - -static int SimNbCars = 0; +int SimTelemetry = -1; t3Dd vectStart[16]; t3Dd vectEnd[16]; +static tTrack *PTrack = 0; + +static int SimNbCars = 0; + #define MEANNB 0 #define MEANW 1 @@ -121,7 +124,7 @@ ctrlCheck(tCar *car) /* Initial configuration */ void -SimConfig(tCarElt *carElt, RmInfo *info) +SimConfig(tCarElt *carElt) { tCar *car = &(SimCarTable[carElt->index]); @@ -135,7 +138,7 @@ SimConfig(tCarElt *carElt, RmInfo *info) SimCarConfig(car); - SimCarCollideConfig(car, info->track); + SimCarCollideConfig(car, PTrack); sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z, RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch)); } @@ -305,10 +308,14 @@ RemoveCar(tCar *car, tSituation *s) car->restPos.vel.ay = dang / travelTime; } - +void +SimCarTelemetry(int nCarIndex, bool bOn) +{ + SimTelemetry = bOn ? nCarIndex : -1; +} void -SimUpdate(tSituation *s, double deltaTime, int telemetry) +SimUpdate(tSituation *s, double deltaTime) { int i; int ncar; @@ -316,7 +323,6 @@ SimUpdate(tSituation *s, double deltaTime, int telemetry) tCar *car; SimDeltaTime = deltaTime; - SimTelemetry = telemetry; for (ncar = 0; ncar < s->_ncars; ncar++) { SimCarTable[ncar].collision = 0; SimCarTable[ncar].blocked = 0; @@ -430,7 +436,8 @@ SimInit(int nbcars, tTrack* track) { SimNbCars = nbcars; SimCarTable = (tCar*)calloc(nbcars, sizeof(tCar)); - SimCarCollideInit(track); + PTrack = track; + SimCarCollideInit(PTrack); } void @@ -448,6 +455,8 @@ SimShutdown(void) free(SimCarTable); SimCarTable = 0; } + + PTrack = 0; } /* Used for network games to update client physics */ @@ -481,7 +490,6 @@ SimUpdateSingleCar(int index, double deltaTime,tSituation *s) car = &(SimCarTable[index]); carElt = car->carElt; - CHECK(car); ctrlCheck(car); @@ -522,17 +530,12 @@ SimUpdateSingleCar(int index, double deltaTime,tSituation *s) SimCarUpdate(car, s); CHECK(car); - - car = &(SimCarTable[index]); - CHECK(car); - carElt = car->carElt; - /* copy back the data to carElt */ carElt->pub.DynGC = car->DynGC; carElt->pub.DynGCg = car->DynGCg; sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z, - RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch)); + RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch)); carElt->_trkPos = car->trkPos; for (i = 0; i < 4; i++) { carElt->priv.wheel[i].relPos = car->wheel[i].relPos; @@ -545,6 +548,5 @@ SimUpdateSingleCar(int index, double deltaTime,tSituation *s) carElt->_fuel = car->fuel; carElt->priv.collision |= car->collision; carElt->_dammage = car->dammage; - } diff --git a/src/modules/simu/simuv2.1/simuitf.cpp b/src/modules/simu/simuv2.1/simuitf.cpp deleted file mode 100644 index 4e261be4..00000000 --- a/src/modules/simu/simuv2.1/simuitf.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************** - - file : simuitf.cpp - created : Sun Mar 19 00:08:04 CET 2000 - copyright : (C) 2000 by Eric Espie - email : torcs@free.fr - version : $Id$ - - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#include - -#include - -#include "sim.h" - -#ifdef _WIN32 -BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWORD dwReason, LPVOID Reserved) -{ - return TRUE; -} -#endif - -/* - * Function - * simuInit - * - * Description - * init the simu functions - * - * Parameters - * - * - * Return - * - * - * Remarks - * - */ -static int -simuInit(int /* index */, void *pt) -{ - tSimItf *sim = (tSimItf*)pt; - - sim->init = SimInit; - sim->config = SimConfig; - sim->reconfig = SimReConfig; - sim->update = SimUpdate; - sim->singleupdate = SimUpdateSingleCar; - sim->shutdown = SimShutdown; - sim->updatesimcartable = UpdateSimCarTable; - sim->getsimcartable = GetSimCarTable; - - return 0; -} - - -/* - * Function - * moduleWelcome - * - * Description - * First function of the module called at load time : - * - the caller gives the module some information about its run-time environment - * - the module gives the caller some information about what he needs - * - * Parameters - * welcomeIn : Run-time info given by the module loader at load time - * welcomeOut : Module run-time information returned to the called - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * MUST be called before moduleInitialize() - */ -extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* welcomeOut) -{ - welcomeOut->maxNbItf = 1; - - return 0; -} - -/* - * Function - * moduleInitialize - * - * Description - * Module entry point - * - * Parameters - * modInfo : Module interfaces info array to fill-in - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * - */ -extern "C" int -moduleInitialize(tModInfo *modInfo) -{ - modInfo->name = "simu"; /* name of the module (short) */ - modInfo->desc = "Simulation Engine V2.0"; /* description of the module (can be long) */ - modInfo->fctInit = simuInit; /* init function */ - modInfo->gfId = SIM_IDENT; /* ident */ - modInfo->index = 0; - return 0; -} - -/* - * Function - * moduleTerminate - * - * Description - * Module exit point - * - * Parameters - * None - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * - */ -extern "C" int -moduleTerminate() -{ - return 0; -} - - - diff --git a/src/modules/simu/simuv2.1/simuv2.1.def b/src/modules/simu/simuv2.1/simuv2.1.def deleted file mode 100644 index b3729051..00000000 --- a/src/modules/simu/simuv2.1/simuv2.1.def +++ /dev/null @@ -1,16 +0,0 @@ -; -; simuv2.def -; - -LIBRARY - -SECTIONS .data READ WRITE - -EXPORTS - moduleWelcome - moduleInitialize - moduleTerminate - UpdateSimCarTable - GetSimCarTable - SimUpdateSingleCar - diff --git a/src/modules/simu/simuv2.1/simuv21.cpp b/src/modules/simu/simuv2.1/simuv21.cpp new file mode 100644 index 00000000..c3fd582b --- /dev/null +++ b/src/modules/simu/simuv2.1/simuv21.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + + file : simuv21.cpp + created : Sun Mar 19 00:08:04 CET 2000 + copyright : (C) 2000 by Eric Espie + email : torcs@free.fr + version : $Id$ + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "simuv21.h" + +#include "sim.h" + + +// The Simuv21: singleton. +Simuv21* Simuv21::_pSelf = 0; + +int openGfModule(const char* pszShLibName, void* hShLibHandle) +{ + // Instanciate the (only) module instance. + Simuv21::_pSelf = new Simuv21(pszShLibName, hShLibHandle); + + // Register it to the GfModule module manager if OK. + if (Simuv21::_pSelf) + GfModule::register_(Simuv21::_pSelf); + + // Report about success or error. + return Simuv21::_pSelf ? 0 : 1; +} + +int closeGfModule() +{ + // Unregister it from the GfModule module manager. + if (Simuv21::_pSelf) + GfModule::unregister(Simuv21::_pSelf); + + // Delete the (only) module instance. + delete Simuv21::_pSelf; + Simuv21::_pSelf = 0; + + // Report about success or error. + return 0; +} + +Simuv21& Simuv21::self() +{ + // Pre-condition : 1 successfull openGfModule call. + return *_pSelf; +} + +Simuv21::Simuv21(const std::string& strShLibName, void* hShLibHandle) +: GfModule(strShLibName, hShLibHandle) +{ +} + +Simuv21::~Simuv21() +{ +} + +// Implementation of IPhysicsEngine. +void Simuv21::initialize(int nCars, struct Track* pTrack) +{ + ::SimInit(nCars, pTrack); +} + +void Simuv21::configureCar(struct CarElt* pCar) +{ + ::SimConfig(pCar); +} + +void Simuv21::reconfigureCar(struct CarElt* pCar) +{ + ::SimReConfig(pCar); +} + +void Simuv21::toggleCarTelemetry(int nCarIndex, bool bOn) +{ + ::SimCarTelemetry(nCarIndex, bOn); +} + +void Simuv21::updateSituation(struct Situation *pSituation, double fDeltaTime) +{ + ::SimUpdate(pSituation, fDeltaTime); +} + +void Simuv21::updateCar(struct Situation *pSituation, double fDeltaTime, int nCarIndex) +{ + ::SimUpdateSingleCar(nCarIndex, fDeltaTime, pSituation); +} + +void Simuv21::setCar(const struct DynPt& dynGCG, int nCarIndex) +{ + ::UpdateSimCarTable(dynGCG, nCarIndex); +} + +tDynPt* Simuv21::getCar(int nCarIndex) +{ + return ::GetSimCarTable(nCarIndex); +} + +void Simuv21::shutdown() +{ + ::SimShutdown(); +} diff --git a/src/modules/simu/simuv2.1/simuv21.h b/src/modules/simu/simuv2.1/simuv21.h new file mode 100644 index 00000000..f4ebaf8c --- /dev/null +++ b/src/modules/simu/simuv2.1/simuv21.h @@ -0,0 +1,85 @@ +/*************************************************************************** + + file : simuv21.h + copyright : (C) 2011 by Jean-Philippe Meuret + email : pouillot@users.sourceforge.net + version : $Id$ + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +/** @file + The "Simu V2.1" physics engine module + @version $Id$ +*/ + +#ifndef _SIMUV21_H_ +#define _SIMUV21_H_ + +#include + +#include + + +// DLL exported symbols declarator for Windows. +#ifdef WIN32 +# ifdef SIMUV21_DLL +# define SIMUV21_API __declspec(dllexport) +# else +# define SIMUV21_API __declspec(dllimport) +# endif +#else +# define SIMUV21_API +#endif + + +// The C interface of the module. +extern "C" int SIMUV21_API openGfModule(const char* pszShLibName, void* hShLibHandle); +extern "C" int SIMUV21_API closeGfModule(); + +// The module main class (Singleton, inherits GfModule, and implements IPhysicsEngine). +class SIMUV21_API Simuv21 : public GfModule, public IPhysicsEngine +{ + public: + + // Implementation of IPhysicsEngine. + virtual void initialize(int nCars, struct Track* pTrack); + virtual void configureCar(struct CarElt* pCar); + virtual void reconfigureCar(struct CarElt* pCar); + virtual void toggleCarTelemetry(int nCarIndex, bool bOn = true); + virtual void updateSituation(struct Situation *pSituation, double fDeltaTime); + virtual void updateCar(struct Situation *pSituation, double fDeltaTime, int nCarIndex); + virtual void setCar(const struct DynPt& dynGCG, int nCarIndex); + virtual struct DynPt* getCar(int nCarIndex); + virtual void shutdown(); + + // Accessor to the singleton. + static Simuv21& self(); + + // Destructor. + virtual ~Simuv21(); + + protected: + + // Protected constructor to avoid instanciation outside (but friends). + Simuv21(const std::string& strShLibName, void* hShLibHandle); + + // Make the C interface functions nearly member functions. + friend int openGfModule(const char* pszShLibName, void* hShLibHandle); + friend int closeGfModule(); + + protected: + + // The singleton. + static Simuv21* _pSelf; +}; + +#endif /* _SIMUV21_H_ */ diff --git a/src/modules/simu/simuv2/CMakeLists.txt b/src/modules/simu/simuv2/CMakeLists.txt index 3ce73673..1952d454 100644 --- a/src/modules/simu/simuv2/CMakeLists.txt +++ b/src/modules/simu/simuv2/CMakeLists.txt @@ -1,36 +1,34 @@ -INCLUDE(../../../../cmake/macros.cmake) +INCLUDE("../../../../cmake/macros.cmake") -ADD_SDLIB_INCLUDEDIR(portability) - -INCLUDE_DIRECTORIES(../simuv2.1/SOLID-2.0/include) - -SET(SIMUV2_SOURCES aero.cpp axle.cpp brake.cpp car.cpp categories.cpp - collide.cpp differential.cpp engine.cpp simu.cpp simuitf.cpp - steer.cpp susp.cpp transmission.cpp wheel.cpp - aero.h axle.h brake.h carstruct.h differential.h engine.h - sim.h steer.h susp.h transmission.h wheel.h) +SET(_SOURCES aero.cpp axle.cpp brake.cpp car.cpp categories.cpp + collide.cpp differential.cpp engine.cpp simu.cpp + steer.cpp susp.cpp transmission.cpp wheel.cpp + aero.h axle.h brake.h carstruct.h differential.h engine.h + sim.h steer.h susp.h transmission.h wheel.h + simuv20.cpp simuv20.h) ADD_INTERFACE_INCLUDEDIR() ADD_PLIB_INCLUDEDIR() -ADD_SDLIB_INCLUDEDIR(math tgf robottools) +ADD_SDLIB_INCLUDEDIR(math tgf robottools portability) + +INCLUDE_DIRECTORIES(../simuv2.1/SOLID-2.0/include) IF(WIN32) - # Ignore some run-time libs to avoid link time warnings and sometimes even crashes. + # DLL export stuff under Windows (to avoid .def file) + ADD_DEFINITIONS(-DSIMUV20_DLL) + + # Ignore some run-time libs to avoid link time warnings and sometimes even crashes. SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib") ENDIF(WIN32) -IF(WIN32) - ADD_LIBRARY(simuv2 SHARED ${SIMUV2_SOURCES} simuv2.def) -ELSE(WIN32) - ADD_LIBRARY(simuv2 SHARED ${SIMUV2_SOURCES}) -ENDIF(WIN32) - -IF(UNIX) - SET_TARGET_PROPERTIES(simuv2 PROPERTIES PREFIX "") -ENDIF(UNIX) +ADD_LIBRARY(simuv2 SHARED ${_SOURCES}) ADD_SDLIB_LIBRARY(simuv2 tgf robottools solid) +IF(UNIX) + SET_TARGET_PROPERTIES(simuv2 PROPERTIES PREFIX "") +ENDIF(UNIX) + SD_INSTALL_FILES(LIB modules/simu TARGETS simuv2) diff --git a/src/modules/simu/simuv2/sim.h b/src/modules/simu/simuv2/sim.h index bb4532ea..b3550ced 100644 --- a/src/modules/simu/simuv2/sim.h +++ b/src/modules/simu/simuv2/sim.h @@ -20,31 +20,30 @@ #ifndef _SIMFCT_H_ #define _SIMFCT_H_ -#include -#include +#include +#include #include -#ifdef WIN32 -#include -#define isnan _isnan -#endif +#include #include #include #include #include -#include -#include "carstruct.h" #include -extern void SimConfig(tCarElt *carElt, RmInfo *); +#include "carstruct.h" + + +extern void SimConfig(tCarElt *carElt); extern void SimReConfig(tCarElt *carElt); -extern void SimUpdate(tSituation*, double deltaTime, int telemetry); +extern void SimUpdate(tSituation*, double deltaTime); extern void SimInit(int nbcars, tTrack* track); extern void SimShutdown(void); + +extern void SimCarTelemetry(int nCarIndex, bool bOn = true); extern void UpdateSimCarTable(tDynPt DynGCG,int index); extern void SimUpdateSingleCar(int index, double deltaTime,tSituation *s); - -extern tDynPt * GetSimCarTable(int index); +extern tDynPt* GetSimCarTable(int index); extern void SimAxleConfig(tCar *car, int index); diff --git a/src/modules/simu/simuv2/simu.cpp b/src/modules/simu/simuv2/simu.cpp index 0ef799e3..0f9da354 100644 --- a/src/modules/simu/simuv2/simu.cpp +++ b/src/modules/simu/simuv2/simu.cpp @@ -28,17 +28,20 @@ #include "sim.h" + tCar *SimCarTable = 0; tdble SimDeltaTime; -int SimTelemetry; - -static int SimNbCars = 0; +int SimTelemetry = -1; t3Dd vectStart[16]; t3Dd vectEnd[16]; +static tTrack *PTrack = 0; + +static int SimNbCars = 0; + #define MEANNB 0 #define MEANW 1 @@ -121,7 +124,7 @@ ctrlCheck(tCar *car) /* Initial configuration */ void -SimConfig(tCarElt *carElt, RmInfo *info) +SimConfig(tCarElt *carElt) { tCar *car = &(SimCarTable[carElt->index]); @@ -135,7 +138,7 @@ SimConfig(tCarElt *carElt, RmInfo *info) SimCarConfig(car); - SimCarCollideConfig(car, info->track); + SimCarCollideConfig(car, PTrack); sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z, RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch)); } @@ -305,10 +308,14 @@ RemoveCar(tCar *car, tSituation *s) car->restPos.vel.ay = dang / travelTime; } - +void +SimCarTelemetry(int nCarIndex, bool bOn) +{ + SimTelemetry = bOn ? nCarIndex : -1; +} void -SimUpdate(tSituation *s, double deltaTime, int telemetry) +SimUpdate(tSituation *s, double deltaTime) { int i; int ncar; @@ -316,7 +323,6 @@ SimUpdate(tSituation *s, double deltaTime, int telemetry) tCar *car; SimDeltaTime = deltaTime; - SimTelemetry = telemetry; for (ncar = 0; ncar < s->_ncars; ncar++) { SimCarTable[ncar].collision = 0; SimCarTable[ncar].blocked = 0; @@ -430,7 +436,8 @@ SimInit(int nbcars, tTrack* track) { SimNbCars = nbcars; SimCarTable = (tCar*)calloc(nbcars, sizeof(tCar)); - SimCarCollideInit(track); + PTrack = track; + SimCarCollideInit(PTrack); } void @@ -448,11 +455,13 @@ SimShutdown(void) free(SimCarTable); SimCarTable = 0; } + + PTrack = 0; } /* Used for network games to update client physics */ void -UpdateSimCarTable(tDynPt DynGCG,int index) +UpdateSimCarTable(tDynPt DynGCG, int index) { tCar *pCar = SimCarTable; pCar[index].DynGCg = DynGCG; @@ -468,10 +477,9 @@ GetSimCarTable(int index) void -SimUpdateSingleCar(int index, double deltaTime,tSituation *s) +SimUpdateSingleCar(int index, double deltaTime, tSituation *s) { int i; - //int ncar; tCarElt *carElt; tCar *car; diff --git a/src/modules/simu/simuv2/simuitf.cpp b/src/modules/simu/simuv2/simuitf.cpp deleted file mode 100644 index 4e261be4..00000000 --- a/src/modules/simu/simuv2/simuitf.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************** - - file : simuitf.cpp - created : Sun Mar 19 00:08:04 CET 2000 - copyright : (C) 2000 by Eric Espie - email : torcs@free.fr - version : $Id$ - - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#include - -#include - -#include "sim.h" - -#ifdef _WIN32 -BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWORD dwReason, LPVOID Reserved) -{ - return TRUE; -} -#endif - -/* - * Function - * simuInit - * - * Description - * init the simu functions - * - * Parameters - * - * - * Return - * - * - * Remarks - * - */ -static int -simuInit(int /* index */, void *pt) -{ - tSimItf *sim = (tSimItf*)pt; - - sim->init = SimInit; - sim->config = SimConfig; - sim->reconfig = SimReConfig; - sim->update = SimUpdate; - sim->singleupdate = SimUpdateSingleCar; - sim->shutdown = SimShutdown; - sim->updatesimcartable = UpdateSimCarTable; - sim->getsimcartable = GetSimCarTable; - - return 0; -} - - -/* - * Function - * moduleWelcome - * - * Description - * First function of the module called at load time : - * - the caller gives the module some information about its run-time environment - * - the module gives the caller some information about what he needs - * - * Parameters - * welcomeIn : Run-time info given by the module loader at load time - * welcomeOut : Module run-time information returned to the called - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * MUST be called before moduleInitialize() - */ -extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* welcomeOut) -{ - welcomeOut->maxNbItf = 1; - - return 0; -} - -/* - * Function - * moduleInitialize - * - * Description - * Module entry point - * - * Parameters - * modInfo : Module interfaces info array to fill-in - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * - */ -extern "C" int -moduleInitialize(tModInfo *modInfo) -{ - modInfo->name = "simu"; /* name of the module (short) */ - modInfo->desc = "Simulation Engine V2.0"; /* description of the module (can be long) */ - modInfo->fctInit = simuInit; /* init function */ - modInfo->gfId = SIM_IDENT; /* ident */ - modInfo->index = 0; - return 0; -} - -/* - * Function - * moduleTerminate - * - * Description - * Module exit point - * - * Parameters - * None - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * - */ -extern "C" int -moduleTerminate() -{ - return 0; -} - - - diff --git a/src/modules/simu/simuv2/simuv2.def b/src/modules/simu/simuv2/simuv2.def deleted file mode 100644 index b3729051..00000000 --- a/src/modules/simu/simuv2/simuv2.def +++ /dev/null @@ -1,16 +0,0 @@ -; -; simuv2.def -; - -LIBRARY - -SECTIONS .data READ WRITE - -EXPORTS - moduleWelcome - moduleInitialize - moduleTerminate - UpdateSimCarTable - GetSimCarTable - SimUpdateSingleCar - diff --git a/src/modules/simu/simuv2/simuv20.cpp b/src/modules/simu/simuv2/simuv20.cpp new file mode 100644 index 00000000..1b0e822b --- /dev/null +++ b/src/modules/simu/simuv2/simuv20.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + + file : simuitf.cpp + created : Sun Mar 19 00:08:04 CET 2000 + copyright : (C) 2000 by Eric Espie + email : torcs@free.fr + version : $Id$ + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "simuv20.h" + +#include "sim.h" + + +// The SimuV20: singleton. +SimuV20* SimuV20::_pSelf = 0; + +int openGfModule(const char* pszShLibName, void* hShLibHandle) +{ + // Instanciate the (only) module instance. + SimuV20::_pSelf = new SimuV20(pszShLibName, hShLibHandle); + + // Register it to the GfModule module manager if OK. + if (SimuV20::_pSelf) + GfModule::register_(SimuV20::_pSelf); + + // Report about success or error. + return SimuV20::_pSelf ? 0 : 1; +} + +int closeGfModule() +{ + // Unregister it from the GfModule module manager. + if (SimuV20::_pSelf) + GfModule::unregister(SimuV20::_pSelf); + + // Delete the (only) module instance. + delete SimuV20::_pSelf; + SimuV20::_pSelf = 0; + + // Report about success or error. + return 0; +} + +SimuV20& SimuV20::self() +{ + // Pre-condition : 1 successfull openGfModule call. + return *_pSelf; +} + +SimuV20::SimuV20(const std::string& strShLibName, void* hShLibHandle) +: GfModule(strShLibName, hShLibHandle) +{ +} + +SimuV20::~SimuV20() +{ +} + +// Implementation of IPhysicsEngine. +void SimuV20::initialize(int nCars, struct Track* pTrack) +{ + ::SimInit(nCars, pTrack); +} + +void SimuV20::configureCar(struct CarElt* pCar) +{ + ::SimConfig(pCar); +} + +void SimuV20::reconfigureCar(struct CarElt* pCar) +{ + ::SimReConfig(pCar); +} + +void SimuV20::toggleCarTelemetry(int nCarIndex, bool bOn) +{ + ::SimCarTelemetry(nCarIndex, bOn); +} + +void SimuV20::updateSituation(struct Situation *pSituation, double fDeltaTime) +{ + ::SimUpdate(pSituation, fDeltaTime); +} + +void SimuV20::updateCar(struct Situation *pSituation, double fDeltaTime, int nCarIndex) +{ + ::SimUpdateSingleCar(nCarIndex, fDeltaTime, pSituation); +} + +void SimuV20::setCar(const struct DynPt& dynGCG, int nCarIndex) +{ + ::UpdateSimCarTable(dynGCG, nCarIndex); +} + +tDynPt* SimuV20::getCar(int nCarIndex) +{ + return ::GetSimCarTable(nCarIndex); +} + +void SimuV20::shutdown() +{ + ::SimShutdown(); +} diff --git a/src/modules/simu/simuv2/simuv20.h b/src/modules/simu/simuv2/simuv20.h new file mode 100644 index 00000000..56bc6439 --- /dev/null +++ b/src/modules/simu/simuv2/simuv20.h @@ -0,0 +1,85 @@ +/*************************************************************************** + + file : simuv20.h + copyright : (C) 2011 by Jean-Philippe Meuret + email : pouillot@users.sourceforge.net + version : $Id$ + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +/** @file + The "Simu V2.0" physics engine module + @version $Id$ +*/ + +#ifndef _SIMUV20_H_ +#define _SIMUV20_H_ + +#include + +#include + + +// DLL exported symbols declarator for Windows. +#ifdef WIN32 +# ifdef SIMUV20_DLL +# define SIMUV20_API __declspec(dllexport) +# else +# define SIMUV20_API __declspec(dllimport) +# endif +#else +# define SIMUV20_API +#endif + + +// The C interface of the module. +extern "C" int SIMUV20_API openGfModule(const char* pszShLibName, void* hShLibHandle); +extern "C" int SIMUV20_API closeGfModule(); + +// The module main class (Singleton, inherits GfModule, and implements IGraphicsEngine). +class SIMUV20_API SimuV20 : public GfModule, public IPhysicsEngine +{ + public: + + // Implementation of IPhysicsEngine. + virtual void initialize(int nCars, struct Track* pTrack); + virtual void configureCar(struct CarElt* pCar); + virtual void reconfigureCar(struct CarElt* pCar); + virtual void toggleCarTelemetry(int nCarIndex, bool bOn = true); + virtual void updateSituation(struct Situation *pSituation, double fDeltaTime); + virtual void updateCar(struct Situation *pSituation, double fDeltaTime, int nCarIndex); + virtual void setCar(const struct DynPt& dynGCG, int nCarIndex); + virtual struct DynPt* getCar(int nCarIndex); + virtual void shutdown(); + + // Accessor to the singleton. + static SimuV20& self(); + + // Destructor. + virtual ~SimuV20(); + + protected: + + // Protected constructor to avoid instanciation outside (but friends). + SimuV20(const std::string& strShLibName, void* hShLibHandle); + + // Make the C interface functions nearly member functions. + friend int openGfModule(const char* pszShLibName, void* hShLibHandle); + friend int closeGfModule(); + + protected: + + // The singleton. + static SimuV20* _pSelf; +}; + +#endif /* _SIMUV20_H_ */ diff --git a/src/modules/simu/simuv3/CMakeLists.txt b/src/modules/simu/simuv3/CMakeLists.txt index 539a0311..f2468fbe 100644 --- a/src/modules/simu/simuv3/CMakeLists.txt +++ b/src/modules/simu/simuv3/CMakeLists.txt @@ -1,29 +1,34 @@ INCLUDE("../../../../cmake/macros.cmake") -SET(SIMUV3_SOURCES SimulationOptions.cpp aero.cpp axle.cpp brake.cpp - car.cpp categories.cpp collide.cpp differential.cpp - engine.cpp simu.cpp simuitf.cpp steer.cpp susp.cpp - transmission.cpp wheel.cpp) +SET(_SOURCES SimulationOptions.cpp aero.cpp axle.cpp brake.cpp + car.cpp categories.cpp collide.cpp differential.cpp + engine.cpp simu.cpp steer.cpp susp.cpp + transmission.cpp wheel.cpp + aero.h axle.h brake.h carstruct.h differential.h engine.h + Options.h sim.h steer.h susp.h transmission.h wheel.h + simuv30.cpp simuv30.h) ADD_INTERFACE_INCLUDEDIR() ADD_PLIB_INCLUDEDIR() ADD_SDLIB_INCLUDEDIR(math tgf robottools portability) + INCLUDE_DIRECTORIES(../simuv2.1/SOLID-2.0/include) IF(WIN32) - # Ignore some run-time libs to avoid link time warnings and sometimes even crashes. + # DLL export stuff under Windows (to avoid .def file) + ADD_DEFINITIONS(-DSIMUV30_DLL) + + # Ignore some run-time libs to avoid link time warnings and sometimes even crashes. SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib") ENDIF(WIN32) -IF(WIN32) - ADD_LIBRARY(simuv3 SHARED ${SIMUV3_SOURCES} simuv3.def) -ELSE(WIN32) - ADD_LIBRARY(simuv3 SHARED ${SIMUV3_SOURCES}) -ENDIF(WIN32) +ADD_LIBRARY(simuv3 SHARED ${_SOURCES}) ADD_SDLIB_LIBRARY(simuv3 tgf robottools solid) -SET_TARGET_PROPERTIES(simuv3 PROPERTIES PREFIX "") +IF(UNIX) + SET_TARGET_PROPERTIES(simuv3 PROPERTIES PREFIX "") +ENDIF(UNIX) SD_INSTALL_FILES(LIB modules/simu TARGETS simuv3) diff --git a/src/modules/simu/simuv3/sim.h b/src/modules/simu/simuv3/sim.h index 4bd273f5..447b4b90 100644 --- a/src/modules/simu/simuv3/sim.h +++ b/src/modules/simu/simuv3/sim.h @@ -20,28 +20,31 @@ #ifndef _SIMFCT_H_ #define _SIMFCT_H_ -#include -#include -#include -#ifdef WIN32 -#include -#define isnan _isnan -#endif +#include +#include +#include +#include #include #include #include #include -#include -#include "carstruct.h" #include -extern void SimConfig(tCarElt *carElt, tRmInfo* ReInfo); +#include "carstruct.h" + + +extern void SimConfig(tCarElt *carElt); extern void SimReConfig(tCarElt *carElt); -extern void SimUpdate(tSituation*, double deltaTime, int telemetry); +extern void SimUpdate(tSituation*, double deltaTime); extern void SimInit(int nbcars, tTrack* track); extern void SimShutdown(void); +extern void SimCarTelemetry(int nCarIndex, bool bOn = true); +extern void UpdateSimCarTable(tDynPt DynGCG, int index); +extern void SimUpdateSingleCar(int index, double deltaTime, tSituation *s); +extern tDynPt* GetSimCarTable(int index); + extern void SimAxleConfig(tCar *car, int index); extern void SimAxleUpdate(tCar *car, int index); diff --git a/src/modules/simu/simuv3/simu.cpp b/src/modules/simu/simuv3/simu.cpp index 8216076a..e97a1ff5 100644 --- a/src/modules/simu/simuv3/simu.cpp +++ b/src/modules/simu/simuv3/simu.cpp @@ -29,6 +29,7 @@ #include "sim.h" #include "timeanalysis.h" + extern double timer_coordinate_transform; extern double timer_reaction; extern double timer_angles; @@ -38,11 +39,17 @@ extern double timer_force_calculation; extern double timer_wheel_to_car; extern double access_times; + tCar *SimCarTable = 0; tdble SimDeltaTime; -int SimTelemetry; +int SimTelemetry = -1; + +t3Dd vectStart[16]; +t3Dd vectEnd[16]; + +static tTrack* PTrack = 0; static int SimNbCars = 0; static double simu_total_time = 0.0f; @@ -52,9 +59,6 @@ double SimTicks = 0.0; // Time measurement of CalculateTorque double SimTicks2 = 0.0; // Time measurement of CalculateTorque2 double SimTicksRtTrackSurfaceNormalL = 0.0; // Time measurement of RtTrackSurfaceNormalL -t3Dd vectStart[16]; -t3Dd vectEnd[16]; - #define MEANNB 0 #define MEANW 1 @@ -138,7 +142,7 @@ ctrlCheck(tCar *car) /* Initial configuration */ void -SimConfig(tCarElt *carElt, tRmInfo* ReInfo) +SimConfig(tCarElt *carElt) { RtInitTimer(); @@ -152,7 +156,6 @@ SimConfig(tCarElt *carElt, tRmInfo* ReInfo) car->trkPos = carElt->_trkPos; car->ctrl = &carElt->ctrl; car->params = carElt->_carHandle; -// car->ReInfo = ReInfo; // Not used til now. SimCarConfig(car); SimCarCollideConfig(car); @@ -327,10 +330,14 @@ RemoveCar(tCar *car, tSituation *s) } - +void +SimCarTelemetry(int nCarIndex, bool bOn) +{ + SimTelemetry = bOn ? nCarIndex : -1; +} void -SimUpdate(tSituation *s, double deltaTime, int telemetry) +SimUpdate(tSituation *s, double deltaTime) { int i; int ncar; @@ -341,7 +348,6 @@ SimUpdate(tSituation *s, double deltaTime, int telemetry) double timestamp_start = GfTimeClock(); SimDeltaTime = (float)deltaTime; - SimTelemetry = 0;//telemetry; for (ncar = 0; ncar < s->_ncars; ncar++) { SimCarTable[ncar].collision = 0; SimCarTable[ncar].blocked = 0; @@ -543,6 +549,130 @@ SimShutdown(void) free(SimCarTable); SimCarTable = 0; } - GfOut("#Total Time RtTrackSurfaceNormalL used: %g sec\n",SimTicksRtTrackSurfaceNormalL/1000.0); // Profiling test + + PTrack = 0; + + // Profiling test + GfOut("#Total Time RtTrackSurfaceNormalL used: %g sec\n",SimTicksRtTrackSurfaceNormalL/1000.0); } +/* Used for network games to update client physics */ +void +UpdateSimCarTable(tDynPt DynGCG,int index) +{ + tCar *pCar = SimCarTable; + pCar[index].DynGCg = DynGCG; +} + +/* Used for network games get current physics values*/ +tDynPt * +GetSimCarTable(int index) +{ + tCar *pCar = SimCarTable; + return &pCar[index].DynGCg; +} + + +void +SimUpdateSingleCar(int index, double deltaTime, tSituation *s) +{ + int i; + tCarElt *carElt; + tCar *car; + sgVec3 P; + static const float UPSIDE_DOWN_TIMEOUT = 5.0f; + + SimDeltaTime = (float)deltaTime; + SimCarTable[index].collision = 0; + SimCarTable[index].blocked = 0; + + car = &(SimCarTable[index]); + carElt = car->carElt; + + CHECK(car); + ctrlCheck(car); + CHECK(car); + SimSteerUpdate(car); + CHECK(car); + SimGearboxUpdate(car); + CHECK(car); + SimEngineUpdateTq(car); + CHECK(car); + + SimCarUpdateWheelPos(car); + CHECK(car); + + SimBrakeSystemUpdate(car); + CHECK(car); + SimAeroUpdate(car, s); + CHECK(car); + for (i = 0; i < 2; i++){ + SimWingUpdate(car, i, s); + } + CHECK(car); + for (i = 0; i < 4; i++){ + SimWheelUpdateRide(car, i); + } + CHECK(car); + for (i = 0; i < 2; i++){ + SimAxleUpdate(car, i); + } + CHECK(car); + for (i = 0; i < 4; i++){ + SimWheelUpdateForce(car, i); + } + CHECK(car); + + SimTransmissionUpdate(car); + CHECK(car); + + SimWheelUpdateRotation(car); + CHECK(car); + SimCarUpdate(car, s); + CHECK(car); + + /* copy back the data to carElt */ + + carElt->pub.DynGC = car->DynGC; + carElt->pub.DynGCg = car->DynGCg; +#if 0 + sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z, + RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch)); +#else + sgQuatToMatrix (carElt->pub.posMat, car->posQuat); + carElt->pub.posMat[3][0] = car->DynGCg.pos.x; + carElt->pub.posMat[3][1] = car->DynGCg.pos.y; + carElt->pub.posMat[3][2] = car->DynGCg.pos.z - carElt->_statGC_z; + carElt->pub.posMat[0][3] = SG_ZERO ; + carElt->pub.posMat[1][3] = SG_ZERO ; + carElt->pub.posMat[2][3] = SG_ZERO ; + carElt->pub.posMat[3][3] = SG_ONE ; + + carElt->_yaw = car->DynGC.pos.az; + carElt->_roll = car->DynGC.pos.ax; + carElt->_pitch = car->DynGC.pos.ay; + +#endif + carElt->_trkPos = car->trkPos; + for (i = 0; i < 4; i++) { + carElt->priv.wheel[i].relPos = car->wheel[i].relPos; + //carElt->priv.wheel[i].visible_z = RtTrackHeightL_smooth(&car->wheel[i].trkPos); //- car->DynGCg.pos.z; + carElt->_wheelSeg(i) = car->wheel[i].trkPos.seg; + carElt->_brakeTemp(i) = car->wheel[i].brake.temp; + carElt->pub.corner[i] = car->corner[i].pos; + + } + carElt->_gear = car->transmission.gearbox.gear; + carElt->_enginerpm = car->engine.rads; + carElt->_fuel = car->fuel; + carElt->priv.collision |= car->collision; + carElt->_dammage = car->dammage; + + P[0] = -carElt->_statGC_x; + P[1] = -carElt->_statGC_y; + P[2] = -carElt->_statGC_z; + sgXformPnt3(P, carElt->_posMat); + carElt->_pos_X = P[0]; + carElt->_pos_Y = P[1]; + carElt->_pos_Z = P[2]; +} diff --git a/src/modules/simu/simuv3/simuitf.cpp b/src/modules/simu/simuv3/simuitf.cpp deleted file mode 100644 index 928c36af..00000000 --- a/src/modules/simu/simuv3/simuitf.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/*************************************************************************** - - file : simuitf.cpp - created : Sun Mar 19 00:08:04 CET 2000 - copyright : (C) 2000 by Eric Espie - email : torcs@free.fr - version : $Id$ - - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -#include - -#include - -#include "sim.h" - -#ifdef _WIN32 -BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWORD dwReason, LPVOID Reserved) -{ - return TRUE; -} -#endif - -/* - * Function - * simuInit - * - * Description - * init the simu functions - * - * Parameters - * - * - * Return - * - * - * Remarks - * - */ -static int -simuInit(int /* index */, void *pt) -{ - tSimItf *sim = (tSimItf*)pt; - - sim->init = SimInit; - sim->config = SimConfig; - sim->reconfig = SimReConfig; - sim->update = SimUpdate; - sim->shutdown = SimShutdown; - - return 0; -} - - -/* - * Function - * moduleWelcome - * - * Description - * First function of the module called at load time : - * - the caller gives the module some information about its run-time environment - * - the module gives the caller some information about what he needs - * - * Parameters - * welcomeIn : Run-time info given by the module loader at load time - * welcomeOut : Module run-time information returned to the called - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * MUST be called before moduleInitialize() - */ -extern "C" int moduleWelcome(const tModWelcomeIn* welcomeIn, tModWelcomeOut* welcomeOut) -{ - welcomeOut->maxNbItf = 1; - - return 0; -} - -/* - * Function - * moduleInitialize - * - * Description - * Module entry point - * - * Parameters - * modInfo : Module interfaces info array to fill-in - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * - */ -extern "C" int -moduleInitialize(tModInfo *modInfo) -{ - modInfo->name = "simu"; /* name of the module (short) */ - modInfo->desc = "Simulation Engine V3.0"; /* description of the module (can be long) */ - modInfo->fctInit = simuInit; /* init function */ - modInfo->gfId = SIM_IDENT; /* ident */ - modInfo->index = 0; - return 0; -} - -/* - * Function - * moduleTerminate - * - * Description - * Module exit point - * - * Parameters - * None - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * - */ -extern "C" int -moduleTerminate() -{ - return 0; -} diff --git a/src/modules/simu/simuv3/simuv3.def b/src/modules/simu/simuv3/simuv3.def deleted file mode 100644 index 56d6d15c..00000000 --- a/src/modules/simu/simuv3/simuv3.def +++ /dev/null @@ -1,13 +0,0 @@ -; -; simuv2.def -; - -LIBRARY - -SECTIONS .data READ WRITE - -EXPORTS - moduleWelcome - moduleInitialize - moduleTerminate - diff --git a/src/modules/simu/simuv3/simuv30.cpp b/src/modules/simu/simuv3/simuv30.cpp new file mode 100644 index 00000000..6cd30441 --- /dev/null +++ b/src/modules/simu/simuv3/simuv30.cpp @@ -0,0 +1,114 @@ +/*************************************************************************** + + file : simuv30.cpp + created : Sun Mar 19 00:08:04 CET 2000 + copyright : (C) 2000 by Eric Espie + email : torcs@free.fr + version : $Id$ + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "simuv30.h" + +#include "sim.h" + + +// The Simuv30: singleton. +Simuv30* Simuv30::_pSelf = 0; + +int openGfModule(const char* pszShLibName, void* hShLibHandle) +{ + // Instanciate the (only) module instance. + Simuv30::_pSelf = new Simuv30(pszShLibName, hShLibHandle); + + // Register it to the GfModule module manager if OK. + if (Simuv30::_pSelf) + GfModule::register_(Simuv30::_pSelf); + + // Report about success or error. + return Simuv30::_pSelf ? 0 : 1; +} + +int closeGfModule() +{ + // Unregister it from the GfModule module manager. + if (Simuv30::_pSelf) + GfModule::unregister(Simuv30::_pSelf); + + // Delete the (only) module instance. + delete Simuv30::_pSelf; + Simuv30::_pSelf = 0; + + // Report about success or error. + return 0; +} + +Simuv30& Simuv30::self() +{ + // Pre-condition : 1 successfull openGfModule call. + return *_pSelf; +} + +Simuv30::Simuv30(const std::string& strShLibName, void* hShLibHandle) +: GfModule(strShLibName, hShLibHandle) +{ +} + +Simuv30::~Simuv30() +{ +} + +// Implementation of IPhysicsEngine. +void Simuv30::initialize(int nCars, struct Track* pTrack) +{ + ::SimInit(nCars, pTrack); +} + +void Simuv30::configureCar(struct CarElt* pCar) +{ + ::SimConfig(pCar); +} + +void Simuv30::reconfigureCar(struct CarElt* pCar) +{ + ::SimReConfig(pCar); +} + +void Simuv30::toggleCarTelemetry(int nCarIndex, bool bOn) +{ + ::SimCarTelemetry(nCarIndex, bOn); +} + +void Simuv30::updateSituation(struct Situation *pSituation, double fDeltaTime) +{ + ::SimUpdate(pSituation, fDeltaTime); +} + +void Simuv30::updateCar(struct Situation *pSituation, double fDeltaTime, int nCarIndex) +{ + ::SimUpdateSingleCar(nCarIndex, fDeltaTime, pSituation); +} + +void Simuv30::setCar(const struct DynPt& dynGCG, int nCarIndex) +{ + ::UpdateSimCarTable(dynGCG, nCarIndex); +} + +tDynPt* Simuv30::getCar(int nCarIndex) +{ + return ::GetSimCarTable(nCarIndex); +} + +void Simuv30::shutdown() +{ + ::SimShutdown(); +} diff --git a/src/modules/simu/simuv3/simuv30.h b/src/modules/simu/simuv3/simuv30.h new file mode 100644 index 00000000..cf36b76a --- /dev/null +++ b/src/modules/simu/simuv3/simuv30.h @@ -0,0 +1,85 @@ +/*************************************************************************** + + file : simuv30.h + copyright : (C) 2011 by Jean-Philippe Meuret + email : pouillot@users.sourceforge.net + version : $Id$ + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +/** @file + The "Simu V3.0" physics engine module + @version $Id$ +*/ + +#ifndef _SIMUV30_H_ +#define _SIMUV30_H_ + +#include + +#include + + +// DLL exported symbols declarator for Windows. +#ifdef WIN32 +# ifdef SIMUV30_DLL +# define SIMUV30_API __declspec(dllexport) +# else +# define SIMUV30_API __declspec(dllimport) +# endif +#else +# define SIMUV30_API +#endif + + +// The C interface of the module. +extern "C" int SIMUV30_API openGfModule(const char* pszShLibName, void* hShLibHandle); +extern "C" int SIMUV30_API closeGfModule(); + +// The module main class (Singleton, inherits GfModule, and implements IPhysicsEngine). +class SIMUV30_API Simuv30 : public GfModule, public IPhysicsEngine +{ + public: + + // Implementation of IPhysicsEngine. + virtual void initialize(int nCars, struct Track* pTrack); + virtual void configureCar(struct CarElt* pCar); + virtual void reconfigureCar(struct CarElt* pCar); + virtual void toggleCarTelemetry(int nCarIndex, bool bOn = true); + virtual void updateSituation(struct Situation *pSituation, double fDeltaTime); + virtual void updateCar(struct Situation *pSituation, double fDeltaTime, int nCarIndex); + virtual void setCar(const struct DynPt& dynGCG, int nCarIndex); + virtual struct DynPt* getCar(int nCarIndex); + virtual void shutdown(); + + // Accessor to the singleton. + static Simuv30& self(); + + // Destructor. + virtual ~Simuv30(); + + protected: + + // Protected constructor to avoid instanciation outside (but friends). + Simuv30(const std::string& strShLibName, void* hShLibHandle); + + // Make the C interface functions nearly member functions. + friend int openGfModule(const char* pszShLibName, void* hShLibHandle); + friend int closeGfModule(); + + protected: + + // The singleton. + static Simuv30* _pSelf; +}; + +#endif /* _SIMUV30_H_ */ diff --git a/src/modules/userinterface/legacymenu/legacymenu.cpp b/src/modules/userinterface/legacymenu/legacymenu.cpp index a3f44cc6..a687008c 100644 --- a/src/modules/userinterface/legacymenu/legacymenu.cpp +++ b/src/modules/userinterface/legacymenu/legacymenu.cpp @@ -202,8 +202,11 @@ bool LegacyMenu::initializeGraphics() // Check that it implements IGraphicsEngine. if (pmodGrEngine) _piGraphicsEngine = pmodGrEngine->getInterface(); - if (!_piGraphicsEngine) + if (pmodGrEngine && !_piGraphicsEngine) + { + GfModule::unload(pmodGrEngine); GfLogError("IGraphicsEngine not implemented by %s\n", ossModLibName.str().c_str()); + } return _piGraphicsEngine != 0; }