Re #374 Moved simu V2, v2.1 and V3 to the new C++ module system
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3568 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 2f23de33f4aade122af1af4439d9a83405c731dc Former-commit-id: 5fec400dad40331b3b9d18b77490bded152c8cb2
This commit is contained in:
parent
6b77923bf4
commit
785c73efc4
35 changed files with 1050 additions and 740 deletions
|
@ -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})
|
||||
|
|
62
src/interfaces/iphysicsengine.h
Normal file
62
src/interfaces/iphysicsengine.h
Normal file
|
@ -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__
|
|
@ -30,7 +30,6 @@
|
|||
#include <tgf.h>
|
||||
#include <car.h>
|
||||
#include <track.h>
|
||||
#include <simu.h>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -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 <track.h>
|
||||
#include <raceman.h>
|
||||
|
||||
#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_ */
|
||||
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#ifndef _RACEENGINE_H_
|
||||
#define _RACEENGINE_H_
|
||||
|
||||
#include <iphysicsengine.h>
|
||||
#include <iraceengine.h>
|
||||
|
||||
|
||||
|
@ -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_ */
|
||||
|
|
|
@ -17,14 +17,11 @@
|
|||
***************************************************************************/
|
||||
|
||||
/** @file
|
||||
|
||||
Race initialization routines
|
||||
@author <a href=mailto:eric.espie@torcs.org>Eric Espie</a>
|
||||
@version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/* Race initialization routines */
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
@ -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<ITrackLoader>();
|
||||
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<GfModule*>(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<GfModule*>(&RePhysicsEngine());
|
||||
if (pmodPhysEngine)
|
||||
{
|
||||
GfModule::unload(pmodPhysEngine);
|
||||
RaceEngine::self().setPhysicsEngine(0);
|
||||
}
|
||||
|
||||
GfModule* pmodTrkLoader = dynamic_cast<GfModule*>(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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,7 +22,10 @@
|
|||
@version $Id$
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <portability.h>
|
||||
#include <tgf.hpp>
|
||||
|
||||
#include <robot.h>
|
||||
#include <network.h>
|
||||
|
@ -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<IPhysicsEngine>();
|
||||
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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include <robot.h>
|
||||
#include <raceman.h>
|
||||
|
||||
#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.
|
||||
|
|
|
@ -26,11 +26,6 @@
|
|||
#define __TGF__H__
|
||||
|
||||
#include <cstdio>
|
||||
//#include <cstdlib>
|
||||
//#include <cstdarg>
|
||||
//#include <cstring>
|
||||
//#include <climits>
|
||||
//#include <cmath>
|
||||
|
||||
#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 */
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -20,31 +20,30 @@
|
|||
#ifndef _SIMFCT_H_
|
||||
#define _SIMFCT_H_
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#ifdef WIN32
|
||||
#include <float.h>
|
||||
#define isnan _isnan
|
||||
#endif
|
||||
|
||||
#include <portability.h>
|
||||
#include <tgf.h>
|
||||
#include <track.h>
|
||||
#include <car.h>
|
||||
#include <raceman.h>
|
||||
#include <simu.h>
|
||||
#include "carstruct.h"
|
||||
#include <robottools.h>
|
||||
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <stdlib.h>
|
||||
|
||||
#include <tgf.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
;
|
||||
; simuv2.def
|
||||
;
|
||||
|
||||
LIBRARY
|
||||
|
||||
SECTIONS .data READ WRITE
|
||||
|
||||
EXPORTS
|
||||
moduleWelcome
|
||||
moduleInitialize
|
||||
moduleTerminate
|
||||
UpdateSimCarTable
|
||||
GetSimCarTable
|
||||
SimUpdateSingleCar
|
||||
|
114
src/modules/simu/simuv2.1/simuv21.cpp
Normal file
114
src/modules/simu/simuv2.1/simuv21.cpp
Normal file
|
@ -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();
|
||||
}
|
85
src/modules/simu/simuv2.1/simuv21.h
Normal file
85
src/modules/simu/simuv2.1/simuv21.h
Normal file
|
@ -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 <iphysicsengine.h>
|
||||
|
||||
#include <tgf.hpp>
|
||||
|
||||
|
||||
// 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_ */
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -20,31 +20,30 @@
|
|||
#ifndef _SIMFCT_H_
|
||||
#define _SIMFCT_H_
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#ifdef WIN32
|
||||
#include <float.h>
|
||||
#define isnan _isnan
|
||||
#endif
|
||||
|
||||
#include <portability.h>
|
||||
#include <tgf.h>
|
||||
#include <track.h>
|
||||
#include <car.h>
|
||||
#include <raceman.h>
|
||||
#include <simu.h>
|
||||
#include "carstruct.h"
|
||||
#include <robottools.h>
|
||||
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 <stdlib.h>
|
||||
|
||||
#include <tgf.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
;
|
||||
; simuv2.def
|
||||
;
|
||||
|
||||
LIBRARY
|
||||
|
||||
SECTIONS .data READ WRITE
|
||||
|
||||
EXPORTS
|
||||
moduleWelcome
|
||||
moduleInitialize
|
||||
moduleTerminate
|
||||
UpdateSimCarTable
|
||||
GetSimCarTable
|
||||
SimUpdateSingleCar
|
||||
|
114
src/modules/simu/simuv2/simuv20.cpp
Normal file
114
src/modules/simu/simuv2/simuv20.cpp
Normal file
|
@ -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();
|
||||
}
|
85
src/modules/simu/simuv2/simuv20.h
Normal file
85
src/modules/simu/simuv2/simuv20.h
Normal file
|
@ -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 <iphysicsengine.h>
|
||||
|
||||
#include <tgf.hpp>
|
||||
|
||||
|
||||
// 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_ */
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -20,28 +20,31 @@
|
|||
#ifndef _SIMFCT_H_
|
||||
#define _SIMFCT_H_
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef WIN32
|
||||
#include <float.h>
|
||||
#define isnan _isnan
|
||||
#endif
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <portability.h>
|
||||
#include <tgf.h>
|
||||
#include <track.h>
|
||||
#include <car.h>
|
||||
#include <raceman.h>
|
||||
#include <simu.h>
|
||||
#include "carstruct.h"
|
||||
#include <robottools.h>
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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 <stdlib.h>
|
||||
|
||||
#include <tgf.h>
|
||||
|
||||
#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;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
;
|
||||
; simuv2.def
|
||||
;
|
||||
|
||||
LIBRARY
|
||||
|
||||
SECTIONS .data READ WRITE
|
||||
|
||||
EXPORTS
|
||||
moduleWelcome
|
||||
moduleInitialize
|
||||
moduleTerminate
|
||||
|
114
src/modules/simu/simuv3/simuv30.cpp
Normal file
114
src/modules/simu/simuv3/simuv30.cpp
Normal file
|
@ -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();
|
||||
}
|
85
src/modules/simu/simuv3/simuv30.h
Normal file
85
src/modules/simu/simuv3/simuv30.h
Normal file
|
@ -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 <iphysicsengine.h>
|
||||
|
||||
#include <tgf.hpp>
|
||||
|
||||
|
||||
// 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_ */
|
|
@ -202,8 +202,11 @@ bool LegacyMenu::initializeGraphics()
|
|||
// Check that it implements IGraphicsEngine.
|
||||
if (pmodGrEngine)
|
||||
_piGraphicsEngine = pmodGrEngine->getInterface<IGraphicsEngine>();
|
||||
if (!_piGraphicsEngine)
|
||||
if (pmodGrEngine && !_piGraphicsEngine)
|
||||
{
|
||||
GfModule::unload(pmodGrEngine);
|
||||
GfLogError("IGraphicsEngine not implemented by %s\n", ossModLibName.str().c_str());
|
||||
}
|
||||
|
||||
return _piGraphicsEngine != 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue