Re #374 Moved the track module to the new C++ dynamically loadable module scheme

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

Former-commit-id: 67e7ce189904d0c2510e4ab0959baec785175c5d
Former-commit-id: feef5ecd0a3995786a6ecc43081fa2c67ac94e7c
This commit is contained in:
pouillot 2011-04-09 07:36:56 +00:00
parent ac4c5dcc99
commit 40473a15ef
19 changed files with 316 additions and 242 deletions

View file

@ -1,7 +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
iraceengine.h iuserinterface.h igraphicsengine.h)
replay.h robot.h simu.h telemetry.h track.h
iraceengine.h iuserinterface.h igraphicsengine.h
itrackloader.h)
SD_INSTALL_FILES(INCLUDE FILES ${INTERFACES_HEADERS})

46
src/interfaces/itrackloader.h Executable file
View file

@ -0,0 +1,46 @@
/***************************************************************************
itrackloader.h -- Interface for track loaders
created : Wed Mar 31 22:12:01 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 track loaders
@version $Id$
*/
#ifndef __ITRACKLOADER__H__
#define __ITRACKLOADER__H__
#include <track.h>
class ITrackLoader
{
public:
virtual tTrack* load(const char* filename, bool grExts = false) = 0;
virtual void unload() = 0;
// ???? a ITrack interface ??????
//virtual tdble globalHeight(tTrackSeg*, tdble x, tdble y) = 0;
//virtual tdble localHeight(tTrkLocPos* pos) = 0;
//virtual void global2Local(tTrackSeg* seg, tdble x, tdble y, tTrkLocPos* pos, int sides) = 0;
//virtual void local2Global(tTrkLocPos* pos, tdble* x, tdble* y) = 0;
//virtual void sideNormal(tTrackSeg* seg, tdble x, tdble y, int side, t3Dd* norm) = 0;
//virtual void surfaceNormal(tTrkLocPos* pos, t3Dd* norm) = 0;
};
#endif // __ITRACKLOADER__H__

View file

@ -105,9 +105,6 @@ typedef struct Situation {
/** Race Engine */
typedef struct
{
tTrackItf trackItf;
// TODO: Remove (old graphics setup)
//tGraphicItf graphicItf;
tSimItf simItf;
} tRaceModIft;
@ -172,9 +169,6 @@ typedef struct
#define _reState raceEngineInfo.state
#define _reParam raceEngineInfo.param
#define _reTrackItf raceEngineInfo.itf.trackItf
// TODO: Remove (old graphics setup)
//#define _reGraphicItf raceEngineInfo.itf.graphicItf
#define _reSimItf raceEngineInfo.itf.simItf
#define _reGameScreen raceEngineInfo.gameScreen
#define _reMenuScreen raceEngineInfo.menuScreen

View file

@ -274,7 +274,8 @@ typedef struct SegExt
/** Surface */
typedef struct trackSurface {
typedef struct trackSurface
{
struct trackSurface *next; /**< Next surface in list */
const char *material; /**< Type of material used */
@ -292,7 +293,8 @@ typedef struct trackSurface {
/** Barrier */
typedef struct trackBarrier {
typedef struct trackBarrier
{
int style; /**< Barrier style */
tdble width; /**< Barrier width */
tdble height; /**< Barrier height */
@ -309,7 +311,8 @@ typedef struct trackBarrier {
The reference angle is the orientation of the first segment of the track.
@ingroup trackstruct
*/
typedef struct trackSeg {
typedef struct trackSeg
{
char *name; /**< Segment name */
int id; /**< Segment number */
@ -451,7 +454,7 @@ typedef struct trackSeg {
#define TR_TOLEFT 2
/** Location on the track in local coordinates */
typedef struct
typedef struct TrkLocPos
{
tTrackSeg *seg; /**< Track segment */
int type; /**< Type of description:
@ -486,7 +489,7 @@ typedef struct TrackOwnPit
} tTrackOwnPit;
/** Pits Info Structure */
typedef struct
typedef struct tTrackPitInfo
{
int type; /**< Type of Pit:
- TR_PIT_NONE
@ -517,7 +520,7 @@ typedef struct
int driversPitsNb; /**< Number of drivers */
} tTrackPitInfo;
typedef struct
typedef struct TurnMarksInfo
{
tdble height;
tdble width;
@ -550,7 +553,7 @@ typedef struct GraphicLightInfo
tdble blue;
} tGraphicLightInfo;
typedef struct
typedef struct TrackGraphicInfo
{
const char *model3d; /**< Name of the track 3D model file (.ac/.acc) */
const char *background; /**< Name of the background image file (.png) */
@ -634,31 +637,6 @@ typedef struct Track
tTrackLocalInfo local; /**< Local info (weather, timeof day ...) */
} tTrack;
typedef tTrack*(*tfTrackBuild)(const char*);
typedef tdble(*tfTrackHeightG)(tTrackSeg*, tdble, tdble);
typedef tdble(*tfTrackHeightL)(tTrkLocPos*);
typedef void(*tfTrackGlobal2Local)(tTrackSeg* /*seg*/, tdble /*X*/, tdble /*Y*/, tTrkLocPos* /*pos*/, int /*sides*/);
typedef void(*tfTrackLocal2Global)(tTrkLocPos*, tdble *, tdble *);
typedef void(*tfTrackSideNormal)(tTrackSeg*, tdble, tdble, int, t3Dd*);
typedef void(*tfTrackSurfaceNormal)(tTrkLocPos *, t3Dd*);
typedef void(*tfTrackShutdown)(void);
typedef struct TrackItf
{
tfTrackBuild trkBuild; /* build track structure for simu */
tfTrackBuild trkBuildEx; /* build with graphic extensions */
tfTrackHeightG trkHeightG;
tfTrackHeightL trkHeightL;
tfTrackGlobal2Local trkGlobal2Local;
tfTrackLocal2Global trkLocal2Global;
tfTrackSideNormal trkSideNormal;
tfTrackSurfaceNormal trkSurfaceNormal;
tfTrackShutdown trkShutdown;
} tTrackItf;
/* For Type 3 tracks (now obsolete) */
#define TRK_LST_SURF "List"

View file

@ -28,14 +28,18 @@
#include <cstdlib>
#include <cstdio>
#include <string>
#include <sstream>
#include <map>
#include <portability.h>
#include <itrackloader.h>
#include <raceman.h>
#include <robot.h>
#include <teammanager.h>
#include <robottools.h>
#include <portability.h>
#include <tgf.hpp>
#include <tracks.h>
#include <racemanagers.h>
#include <race.h>
@ -93,14 +97,20 @@ ReInit(void)
// Load and initialize the track loader module.
GfLogInfo("Loading Track Loader ...\n");
const char* dllname = GfParmGetStr(ReInfo->_reParam, "Modules", "track", "");
snprintf(buf, sizeof(buf), "%smodules/track/%s.%s", GfLibDir(), dllname, DLLEXT);
if (GfModLoad(0, buf, &reEventModList))
std::ostringstream ossModLibName;
const char* pszModName = GfParmGetStr(ReInfo->_reParam, "Modules", "track", "");
ossModLibName << GfLibDir() << "modules/track/" << pszModName << '.' << DLLEXT;
GfModule* pmodTrkLoader = GfModule::load(ossModLibName.str());
// Check that it implements ITrackLoader.
ITrackLoader* piTrkLoader = 0;
if (pmodTrkLoader)
piTrkLoader = pmodTrkLoader->getInterface<ITrackLoader>();
if (!piTrkLoader)
return;
reEventModList->modInfo->fctInit(reEventModList->modInfo->index, &ReInfo->_reTrackItf);
// Initialize GfTracks' track module interface (needed for some track infos).
GfTracks::self()->setTrackInterface(&ReInfo->_reTrackItf);
GfTracks::self()->setTrackLoader(piTrkLoader);
// Initialize the movie capture system.
tRmMovieCapture *capture = &(ReInfo->movieCapture);
@ -151,16 +161,23 @@ ReExit(void)
/* Race Engine clean shutdown */
void ReShutdown(void)
{
if (!ReInfo)
return;
if (!ReInfo)
return;
/* Free previous situation */
ReInfo->_reTrackItf.trkShutdown();
// Unload the track.
ITrackLoader* piTrkLoader = GfTracks::self()->getTrackLoader();
piTrkLoader->unload();
// Unload modules.
// Unload the Simu, Track loader and Graphics modules.
GfModUnloadList(&reEventModList);
RaceEngine::self().userInterface().shutdownGraphics();
GfModule* pmodTrkLoader = dynamic_cast<GfModule*>(piTrkLoader);
GfModule::unload(pmodTrkLoader);
GfTracks::self()->setTrackLoader(0);
RaceEngine::self().userInterface().shutdownGraphics();
// Free ReInfo memory.
if (ReInfo->results)
{
if (ReInfo->mainResults != ReInfo->results)

View file

@ -88,9 +88,6 @@ tRmInfo* ReSituationAllocInit(const tRmInfo* pSource)
// Assign level 2 constants in raceEngineInfo field.
pTarget->_reParam = pSource->_reParam; // Not used / written by updater.
pTarget->_reTrackItf = pSource->_reTrackItf; // Not used / written by updater.
// TODO : Remove (old graphics setup)
// pTarget->_reGraphicItf = pSource->_reGraphicItf; // 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.

View file

@ -32,6 +32,8 @@
#include <raceman.h>
#include <track.h>
#include <tracks.h>
#include "raceengine.h"
#include "racesituation.h"
@ -69,7 +71,7 @@ ReTrackInit(void)
return -1;
snprintf(buf, sizeof(buf), "tracks/%s/%s/%s.%s", catName, trackName, trackName, TRKEXT);
ReInfo->track = ReInfo->_reTrackItf.trkBuild(buf);
ReInfo->track = GfTracks::self()->getTrackLoader()->load(buf);
snprintf(buf, sizeof(buf), "Loading track %s", ReInfo->track->name);
RaceEngine::self().userInterface().addLoadingMessage(buf);

View file

@ -22,7 +22,7 @@
#include <algorithm>
#include <tgf.h>
#include <track.h>
#include <itrackloader.h>
#include "tracks.h"
@ -32,7 +32,7 @@ class GfTracks::Private
{
public:
Private() : pTrackItf(0) {};
Private() : piTrackLoader(0) {}
public:
@ -49,7 +49,7 @@ public:
std::vector<std::string> vecCatNames;
// Track module interface (needed to get some tracks properties).
tTrackItf* pTrackItf;
ITrackLoader* piTrackLoader;
};
@ -172,14 +172,14 @@ GfTracks::GfTracks()
print(false); // No verbose here, otherwise infinite recursion.
}
tTrackItf* GfTracks::getTrackInterface() const
ITrackLoader* GfTracks::getTrackLoader() const
{
return _pPrivate->pTrackItf;
return _pPrivate->piTrackLoader;
}
void GfTracks::setTrackInterface(tTrackItf* pTrackItf)
void GfTracks::setTrackLoader(ITrackLoader* piTrackLoader)
{
_pPrivate->pTrackItf = pTrackItf;
_pPrivate->piTrackLoader = piTrackLoader;
}
const std::vector<std::string>& GfTracks::getCategoryIds() const
@ -576,15 +576,15 @@ void GfTrack::setMaxNumOfPitSlots(int nPitSlots)
bool GfTrack::load() const
{
// Check if the track loader is ready.
tTrackItf* pTrackItf = GfTracks::self()->getTrackInterface();
if (!pTrackItf)
ITrackLoader* piTrackLoader = GfTracks::self()->getTrackLoader();
if (!piTrackLoader)
{
GfLogError("Track loader not yet initialized ; failed to load any track\n");
return false;
}
// Load track data from the XML file.
tTrack* pTrack = pTrackItf->trkBuild(_strDescFile.c_str());
tTrack* pTrack = piTrackLoader->load(_strDescFile.c_str());
if (!pTrack)
{
GfLogWarning("Unusable track %s : failed to build track data from %s\n",
@ -612,7 +612,7 @@ bool GfTrack::load() const
_nMaxPitSlots = pTrack->pits.nMaxPits;
// Unload track data.
pTrackItf->trkShutdown();
piTrackLoader->unload();
// Now, the track seems usable (hm ... OK, we didn't check the 3D file contents ...).
_bUsable = true;

View file

@ -29,9 +29,9 @@
#include <string>
#include <vector>
#include "tgfdata.h"
#include <itrackloader.h>
struct TrackItf;
#include "tgfdata.h"
// Information on one track.
@ -100,8 +100,8 @@ public:
// Accessor to the unique instance of the singleton.
static GfTracks* self();
struct TrackItf* getTrackInterface() const;
void setTrackInterface(struct TrackItf* pTrackItf);
ITrackLoader* getTrackLoader() const;
void setTrackLoader(ITrackLoader* piTrackLoader);
const std::vector<std::string>& getCategoryIds() const;
const std::vector<std::string>& getCategoryNames() const;

View file

@ -1,24 +1,21 @@
INCLUDE(../../../cmake/macros.cmake)
SET(TRACK_SOURCES track.cpp track3.cpp track4.cpp trackitf.cpp trackutil.cpp)
SET(TRACK_SOURCES track.cpp track3.cpp track4.cpp trackitf.cpp trackutil.cpp
trackitf.h trackinc.h)
ADD_INTERFACE_INCLUDEDIR()
ADD_PLIB_INCLUDEDIR()
ADD_SDLIB_INCLUDEDIR(math tgf robottools)
IF(WIN32)
# Ignore some run-time libs to avoid link time warnings and sometimes even crashes.
# 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(track SHARED ${TRACK_SOURCES} track.def)
ELSE(WIN32)
ADD_LIBRARY(track SHARED ${TRACK_SOURCES})
ENDIF(WIN32)
ADD_LIBRARY(track SHARED ${TRACK_SOURCES})
IF(UNIX)
SET_TARGET_PROPERTIES(track PROPERTIES PREFIX "")
SET_TARGET_PROPERTIES(track PROPERTIES PREFIX "")
ENDIF(UNIX)
ADD_PLIB_LIBRARY(track ul sg)

View file

@ -17,7 +17,6 @@
* *
***************************************************************************/
#include <cstdlib>
#include <cstdio>
#include <cstring>
@ -25,10 +24,10 @@
#include <cmath>
#include <raceman.h>
#include <tgf.h>
#include <track.h>
#include "trackinc.h"
static const tdble DEGPRAD = (tdble)(180.0 / PI); /* degrees per radian */
static tTrack *theTrack = NULL;

View file

@ -1,12 +0,0 @@
;
; track.def
;
LIBRARY
SECTIONS .data READ WRITE
EXPORTS
moduleWelcome
moduleInitialize
moduleTerminate

View file

@ -16,25 +16,27 @@
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef _TRACKINC_H__
#define _TRACKINC_H__
extern void TrackShutdown(void);
extern void ReadTrack3(tTrack *theTrack, void *TrackHandle, tRoadCam **camList, int ext);
extern void ReadTrack4(tTrack *theTrack, void *TrackHandle, tRoadCam **camList, int ext);
#include <track.h>
extern tTrack *TrackBuildv1(const char *trackfile);
extern tTrack *TrackBuildEx(const char *trackfile);
extern void TrackShutdown(void);
extern void ReadTrack3(tTrack *theTrack, void *TrackHandle, tRoadCam **camList, int ext);
extern void ReadTrack4(tTrack *theTrack, void *TrackHandle, tRoadCam **camList, int ext);
extern tRoadCam *TrackGetCamList(void);
extern tdble TrackHeightG(tTrackSeg *seg, tdble x, tdble y);
extern tdble TrackHeightL(tTrkLocPos *p);
extern void TrackGlobal2Local(tTrackSeg *segment, tdble X, tdble Y, tTrkLocPos *p, int sides);
extern void TrackLocal2Global(tTrkLocPos *p, tdble *X, tdble *Y);
extern void TrackSideNormal(tTrackSeg*, tdble, tdble, int, t3Dd*);
extern void TrackSurfaceNormal(tTrkLocPos *p, t3Dd *norm);
extern tRoadCam *TrackGetCamList(void);
extern tdble TrackSpline(tdble p0, tdble p1, tdble t0, tdble t1, tdble t);

View file

@ -17,134 +17,94 @@
* *
***************************************************************************/
#include <cstdlib>
#ifdef _WIN32
#include <windows.h>
#endif
#include <tgf.h>
#include <track.h>
#include "trackitf.h"
#include "trackinc.h"
#ifdef _WIN32
BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWORD dwReason, LPVOID Reserved)
{
return TRUE;
}
#endif
// The TrackModule singleton.
TrackModule* TrackModule::_pSelf = 0;
/*
* Function
* trackInit
*
* Description
* init the menus
*
* Parameters
*
*
* Return
*
*
* Remarks
*
*/
static int
trackInit(int /* index */, void *pt)
int openGfModule(const char* pszShLibName, void* hShLibHandle)
{
tTrackItf *ptf = (tTrackItf*)pt;
ptf->trkBuild = TrackBuildv1;
ptf->trkBuildEx = TrackBuildEx;
ptf->trkHeightG = TrackHeightG;
ptf->trkHeightL = TrackHeightL;
ptf->trkGlobal2Local = TrackGlobal2Local;
ptf->trkLocal2Global = TrackLocal2Global;
ptf->trkSideNormal = TrackSideNormal;
ptf->trkSurfaceNormal = TrackSurfaceNormal;
ptf->trkShutdown = TrackShutdown;
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 = "trackv1"; /* name of the module (short) */
modInfo->desc = "Track V1.0"; /* description of the module (can be long) */
modInfo->fctInit = trackInit; /* init function */
modInfo->gfId = TRK_IDENT; /* always loaded */
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;
// Instanciate the (only) module instance.
TrackModule::_pSelf = new TrackModule(pszShLibName, hShLibHandle);
// Register it to the GfModule module manager if OK.
if (TrackModule::_pSelf)
GfModule::register_(TrackModule::_pSelf);
// Report about success or error.
return TrackModule::_pSelf ? 0 : 1;
}
int closeGfModule()
{
// Unregister it from the GfModule module manager.
if (TrackModule::_pSelf)
GfModule::unregister(TrackModule::_pSelf);
// Delete the (only) module instance.
delete TrackModule::_pSelf;
TrackModule::_pSelf = 0;
// Report about success or error.
return 0;
}
TrackModule& TrackModule::self()
{
// Pre-condition : 1 successfull openGfModule call.
return *_pSelf;
}
TrackModule::TrackModule(const std::string& strShLibName, void* hShLibHandle)
: GfModule(strShLibName, hShLibHandle)
{
}
TrackModule::~TrackModule()
{
}
// Implementation of ITrackLoader***********************************
struct Track* TrackModule::load(const char* filename, bool grExts)
{
return grExts ? ::TrackBuildEx(filename) : ::TrackBuildv1(filename);
}
void TrackModule::unload()
{
::TrackShutdown();
}
// Implementation of ITrack ****************************************
//tdble TrackModule::globalHeight(tTrackSeg* seg, tdble x, tdble y)
//{
// return TrackHeightG(seg, x, y);
//}
//
//tdble TrackModule::localHeight(tTrkLocPos* pos)
//{
// return TrackHeightL(pos);
//}
//
//void TrackModule::global2Local(tTrackSeg* seg, tdble x, tdble y, tTrkLocPos* pos, int sides)
//{
// TrackGlobal2Local(seg, x, y, pos, sides);
//}
//
//void TrackModule::local2Global(tTrkLocPos* pos, tdble* x, tdble* y)
//{
// TrackLocal2Global(pos, x, y);
//}
//
//void TrackModule::sideNormal(tTrackSeg* seg, tdble x, tdble y, int side, t3Dd* norm)
//{
// TrackSideNormal(seg, x, y, side, norm);
//}
//
//void TrackModule::surfaceNormal(tTrkLocPos* pos, t3Dd* norm)
//{
// TrackSurfaceNormal(pos, norm);
//}

86
src/modules/track/trackitf.h Executable file
View file

@ -0,0 +1,86 @@
/***************************************************************************
file : trackitf.h
created : Wed Mar 31 22:12:01 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. *
* *
***************************************************************************/
#ifndef _TRACKITF_H__
#define _TRACKITF_H__
//#include <itrack.h>
#include <itrackloader.h>
#include <tgf.hpp>
// DLL exported symbols declarator for Windows.
#ifdef WIN32
# ifdef track_EXPORTS
# define TRACK_API __declspec(dllexport)
# else
# define TRACK_API __declspec(dllimport)
# endif
#else
# define TRACK_API
#endif
// The C interface of the module.
extern "C" int TRACK_API openGfModule(const char* pszShLibName, void* hShLibHandle);
extern "C" int TRACK_API closeGfModule();
// The module main class (Singleton, inherits GfModule, and implements IGraphicsEngine).
class TRACK_API TrackModule : public GfModule, public ITrackLoader //, public ITrack
{
public:
// Implementation of ITrackLoader.
virtual tTrack* load(const char* filename, bool grExts = false);
virtual void unload();
// Implementation of ITrack ?
//virtual tdble globalHeight(tTrackSeg*, tdble x, tdble y);
//virtual tdble localHeight(tTrkLocPos* pos);
//virtual void global2Local(tTrackSeg* seg, tdble x, tdble y, tTrkLocPos* pos, int sides);
//virtual void local2Global(tTrkLocPos* pos, tdble* x, tdble* y);
//virtual void sideNormal(tTrackSeg* seg, tdble x, tdble y, int side, t3Dd* norm);
//virtual void surfaceNormal(tTrkLocPos* pos, t3Dd* norm);
// Accessor to the singleton.
static TrackModule& self();
// Destructor.
virtual ~TrackModule();
protected:
// Protected constructor to avoid instanciation outside (but friends).
TrackModule(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 TrackModule* _pSelf;
};
#endif /* _TRACKINC_H__ */

View file

@ -17,8 +17,8 @@
* *
***************************************************************************/
#include <stdlib.h>
#include <math.h>
#include <cstdlib>
#include <cmath>
#include <tgf.h>
#include <track.h>

View file

@ -32,6 +32,7 @@
#include <raceman.h>
#include <race.h>
#include <tracks.h>
#include "legacymenu.h"
#include "racescreens.h"
@ -143,7 +144,7 @@ RmConfigRunState(bool bStart)
ts.prevScreen = rmConfigBackHookInit();
}
ts.pRace = LegacyMenu::self().raceEngine().race();
ts.trackItf = reInfo->_reTrackItf;
ts.piTrackLoader = GfTracks::self()->getTrackLoader();
RmTrackSelect(&ts);
} else if (!strcmp(conf, RM_VAL_DRVSEL)) {

View file

@ -27,6 +27,8 @@
#include <raceman.h>
#include <itrackloader.h>
#include <tgfclient.h> // tfuiCallback
@ -37,7 +39,7 @@ typedef struct RmTrackSelect
GfRace *pRace; /* The race to update */
void *prevScreen; /* Race manager screen to go back */
void *nextScreen; /* Race manager screen to go after select */
tTrackItf trackItf; /* Track module interface */
ITrackLoader *piTrackLoader; /* Track loader */
} tRmTrackSelect;
typedef struct RmDriverSelect

View file

@ -26,6 +26,9 @@
#include <cstdlib>
#include <ctype.h>
#include <cstring>
#include <cmath>
#include <sstream>
#ifndef WIN32
#include <unistd.h>
@ -39,15 +42,14 @@
#include <getopt.h>
#endif
#include <cmath>
#include <plib/ul.h>
#include <plib/ssg.h>
#include <SDL/SDL.h>
#include <config.h>
#include <tgf.hpp>
#include <tgfclient.h>
#include <track.h>
#include <itrackloader.h>
#include "ac3d.h"
#include "easymesh.h"
@ -74,7 +76,7 @@ void *TrackHandle;
void *CfgHandle;
tTrack *Track;
tTrackItf TrackItf;
ITrackLoader* PiTrackLoader;
int TrackOnly;
int JustCalculate;
@ -334,7 +336,6 @@ main(int argc, char **argv)
static void
Generate(void)
{
const char *trackdllname;
const char *extName;
const char *libdir = GfLibDir();
const char *datadir = GfDataDir();
@ -352,15 +353,18 @@ Generate(void)
sprintf(buf, "%s", CFG_FILE);
CfgHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
trackdllname = GfParmGetStr(CfgHandle, "Modules", "track", "track");
sprintf(buf, "%smodules/track/%s.%s", libdir, trackdllname, DLLEXT);
if (GfModLoad(TRK_IDENT, buf, &modlist) < 0) {
GfFatal("Failed to find the track module %s", buf);
}
// Load and initialize the track loader module.
GfLogInfo("Loading Track Loader ...\n");
std::ostringstream ossModLibName;
ossModLibName << GfLibDir() << "modules/track/" << "track" << '.' << DLLEXT;
GfModule* pmodTrkLoader = GfModule::load(ossModLibName.str());
if (modlist->modInfo->fctInit(modlist->modInfo->index, &TrackItf)) {
GfFatal("Failed to init the track module %s", buf);
}
// Check that it implements ITrackLoader.
ITrackLoader* PiTrackLoader = 0;
if (pmodTrkLoader)
PiTrackLoader = pmodTrkLoader->getInterface<ITrackLoader>();
if (!PiTrackLoader)
return;
// This is the track definition.
sprintf(trackdef, "%stracks/%s/%s/%s.xml", datadir, TrackCategory, TrackName, TrackName);
@ -371,7 +375,7 @@ Generate(void)
}
// Build the track structure with graphic extensions.
Track = TrackItf.trkBuildEx(trackdef);
Track = PiTrackLoader->load(trackdef, true);
if (!JustCalculate) {
// Get the output file radix.