diff --git a/src/interfaces/CMakeLists.txt b/src/interfaces/CMakeLists.txt index de9309a9..25dd6ecd 100644 --- a/src/interfaces/CMakeLists.txt +++ b/src/interfaces/CMakeLists.txt @@ -2,6 +2,6 @@ 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) + iraceengine.h iuserinterface.h igraphicsengine.h) SD_INSTALL_FILES(INCLUDE FILES ${INTERFACES_HEADERS}) diff --git a/src/interfaces/igraphicsengine.h b/src/interfaces/igraphicsengine.h new file mode 100755 index 00000000..85590278 --- /dev/null +++ b/src/interfaces/igraphicsengine.h @@ -0,0 +1,45 @@ +/*************************************************************************** + igraphicsengine.h -- Interface for graphics engines + + created : Mon Mar 28 19:48:14 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 graphics engines + @version $Id$ +*/ + +#ifndef __IGRAPHICSENGINE__H__ +#define __IGRAPHICSENGINE__H__ + +#include + + +class IGraphicsEngine +{ +public: + + virtual bool loadTrack(struct Track* pTrack) = 0; + virtual bool loadCars(struct Situation *pSituation) = 0; + virtual bool setupView(int x, int y, int width, int height, void* pMenuScreen) = 0; + virtual void updateView(struct Situation *pSituation) = 0; + virtual void shutdownView() = 0; + virtual void unloadCars() = 0; + virtual void unloadTrack() = 0; + + //virtual void bendCar(int index, sgVec3 poc, sgVec3 force, int count = 0) = 0; +}; + +#endif // __IGRAPHICSENGINE__H__ diff --git a/src/interfaces/iuserinterface.h b/src/interfaces/iuserinterface.h index ac051c23..8c0d8930 100644 --- a/src/interfaces/iuserinterface.h +++ b/src/interfaces/iuserinterface.h @@ -76,6 +76,16 @@ public: virtual void activateStandingsMenu(void *prevHdle, struct RmInfo *info, int start = 0) = 0; + // Graphics engine control. + virtual bool initializeGraphics() = 0; + virtual bool loadTrackGraphics(struct Track* pTrack) = 0; + virtual bool loadCarsGraphics(struct Situation *pSituation) = 0; + virtual bool setupGraphicsView() = 0; + virtual void updateGraphicsView(struct Situation *pSituation) = 0; + virtual void unloadCarsGraphics() = 0; + virtual void unloadTrackGraphics() = 0; + virtual void shutdownGraphics() = 0; + virtual void setRaceEngine(IRaceEngine& raceEngine) = 0; }; diff --git a/src/interfaces/raceman.h b/src/interfaces/raceman.h index 0bfe7237..ce0e5c83 100755 --- a/src/interfaces/raceman.h +++ b/src/interfaces/raceman.h @@ -30,7 +30,8 @@ #include #include #include -#include +// TODO: Remove (old graphics setup) +//#include #include #define RCM_IDENT 0 @@ -105,7 +106,8 @@ typedef struct Situation { typedef struct { tTrackItf trackItf; - tGraphicItf graphicItf; + // TODO: Remove (old graphics setup) + //tGraphicItf graphicItf; tSimItf simItf; } tRaceModIft; @@ -171,7 +173,8 @@ typedef struct #define _reState raceEngineInfo.state #define _reParam raceEngineInfo.param #define _reTrackItf raceEngineInfo.itf.trackItf -#define _reGraphicItf raceEngineInfo.itf.graphicItf +// TODO: Remove (old graphics setup) +//#define _reGraphicItf raceEngineInfo.itf.graphicItf #define _reSimItf raceEngineInfo.itf.simItf #define _reGameScreen raceEngineInfo.gameScreen #define _reMenuScreen raceEngineInfo.menuScreen diff --git a/src/libs/raceengine/raceinit.cpp b/src/libs/raceengine/raceinit.cpp index 36309ee8..4f799598 100644 --- a/src/libs/raceengine/raceinit.cpp +++ b/src/libs/raceengine/raceinit.cpp @@ -157,9 +157,9 @@ void ReShutdown(void) /* Free previous situation */ ReInfo->_reTrackItf.trkShutdown(); + // Unload modules. GfModUnloadList(&reEventModList); - - memset( &ReInfo->_reGraphicItf, 0, sizeof(tGraphicItf) ); + RaceEngine::self().userInterface().shutdownGraphics(); if (ReInfo->results) { @@ -866,43 +866,35 @@ ReInitCars(void) /** * This function initializes the graphics. - * This function must be called after the cars are loaded and the track is loaded. + * It must be called after the cars are loaded and the track is loaded. * The track will be unloaded if the event ends. The graphics module is kept open * if more than one race is driven. */ void ReInitGraphics() { - char const *dllname; - char key[256]; + // Initialize the graphics engine. + if (RaceEngine::self().userInterface().initializeGraphics()) + { + // Initialize the track graphics. + RaceEngine::self().userInterface().loadTrackGraphics(ReInfo->track); - /* Check if the module is already loaded */ - if (ReInfo->_reGraphicItf.refresh) - return; /* Module is already loaded: don't load again */ - - /* Load the graphic module */ - GfLogInfo("Loading Graphic Engine...\n"); - dllname = GfParmGetStr(ReInfo->_reParam, "Modules", "graphic", ""); - snprintf(key, sizeof(key), "%smodules/graphic/%s.%s", GfLibDir(), dllname, DLLEXT); - if (GfModLoad(0, key, &reEventModList)) - return; - reEventModList->modInfo->fctInit(reEventModList->modInfo->index, &ReInfo->_reGraphicItf); - - ReInfo->_reGraphicItf.inittrack(ReInfo->track); + // Initialize the graphics view. + RaceEngine::self().userInterface().setupGraphicsView(); + } } void ReRaceCleanup(void) { ReInfo->_reGameScreen = RaceEngine::self().userInterface().createRaceEventLoopHook(); + ReInfo->_reSimItf.shutdown(); + if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL) - { - if (ReInfo->_reGraphicItf.shutdowncars) - ReInfo->_reGraphicItf.shutdowncars(); - else - GfLogError("WARNING: normal race display but graphical module not loaded !\n" ); - } + RaceEngine::self().userInterface().unloadCarsGraphics(); + ReStoreRaceResults(ReInfo->_reRaceName); + ReRaceCleanDrivers(); } diff --git a/src/libs/raceengine/racemain.cpp b/src/libs/raceengine/racemain.cpp index 84995750..1e517cdd 100644 --- a/src/libs/raceengine/racemain.cpp +++ b/src/libs/raceengine/racemain.cpp @@ -27,8 +27,6 @@ #include #include -#include // TODO: Remove when GfScrGetSize no more needed. - #include "raceengine.h" #include "raceutil.h" // RmGetFeaturesList @@ -82,13 +80,14 @@ void ReRaceAbort() ReShutdownUpdaters(); ReInfo->_reSimItf.shutdown(); - if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL) { - if (ReInfo->_reGraphicItf.shutdowncars) - ReInfo->_reGraphicItf.shutdowncars(); - } - if (ReInfo->_reGraphicItf.shutdowntrack) - ReInfo->_reGraphicItf.shutdowntrack(); + // TODO: Move these 2 unloadXXGrahics calls to the user interface module ? + if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL) + RaceEngine::self().userInterface().unloadCarsGraphics(); + + // TODO: only if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL) ? + RaceEngine::self().userInterface().unloadTrackGraphics(); + ReRaceCleanDrivers(); if (GetNetwork()) @@ -255,7 +254,6 @@ int ReRaceRealStart(void) { int i, j; - int sw, sh, vw, vh; tRobotItf *robot; tReCarInfo *carInfo; const char *dllname; @@ -294,7 +292,6 @@ ReRaceRealStart(void) /* Blind mode or not */ ReInfo->_displayMode = RM_DISP_MODE_NORMAL; ReInfo->_reGameScreen = RaceEngine::self().userInterface().createRaceScreen(); - //foundHuman = 0; //Check if there is a human in the current race for (i = 0; i < s->_ncars; i++) { @@ -345,11 +342,12 @@ ReRaceRealStart(void) carInfo = ReInfo->_reCarInfo; RtTeamManagerStart(); - /* Initialize graphical module */ + // Initialize graphics engine if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL || ReInfo->_displayMode == RM_DISP_MODE_CAPTURE) ReInitGraphics(); + // Initialize physics engine ReInfo->_reSimItf.update(s, RCM_MAX_DT_SIMU, -1); for (i = 0; i < s->_ncars; i++) { carInfo[i].prevTrkPos = s->cars[i]->_trkPos; @@ -386,10 +384,6 @@ ReRaceRealStart(void) ReInfo->s->deltaTime = RCM_MAX_DT_SIMU; ReInfo->s->_raceState = RM_RACE_STARTING; - GfScrGetSize(&sw, &sh, &vw, &vh); // Last tgfclient dependency. - if (ReInfo->_reGraphicItf.initview) - ReInfo->_reGraphicItf.initview((sw-vw)/2, (sh-vh)/2, vw, vh, GR_VIEW_STD, ReInfo->_reGameScreen); - ReInfo->_reInPitMenuCar = 0; ReInfo->_reMessage = 0; ReInfo->_reMessageEnd = 0.0; @@ -397,10 +391,11 @@ ReRaceRealStart(void) ReInfo->_reBigMessageEnd = 0.0; ReInitUpdaters(); - + + // Initalize cars graphics. if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL) { RaceEngine::self().userInterface().addLoadingMessage("Loading cars ..."); - ReInitCarGraphics(); + RaceEngine::self().userInterface().loadCarsGraphics(ReInfo->s); } if (GetNetwork()) diff --git a/src/libs/raceengine/racenetwork.cpp b/src/libs/raceengine/racenetwork.cpp index f63acf9b..8d1868b8 100644 --- a/src/libs/raceengine/racenetwork.cpp +++ b/src/libs/raceengine/racenetwork.cpp @@ -224,7 +224,7 @@ ReNetworkWaitReady() ReInfo->_refreshDisplay = 1; RaceEngine::self().userInterface().update(); - ReInfo->_reGraphicItf.refresh(ReInfo->s); + RaceEngine::self().userInterface().updateGraphicsView(ReInfo->s); } return mode; diff --git a/src/libs/raceengine/racesituation.cpp b/src/libs/raceengine/racesituation.cpp index bf336caa..dec8f3f7 100644 --- a/src/libs/raceengine/racesituation.cpp +++ b/src/libs/raceengine/racesituation.cpp @@ -89,7 +89,8 @@ 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. - pTarget->_reGraphicItf = pSource->_reGraphicItf; // 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. diff --git a/src/libs/raceengine/racetrack.cpp b/src/libs/raceengine/racetrack.cpp index 7fd9f240..97d3b8a6 100644 --- a/src/libs/raceengine/racetrack.cpp +++ b/src/libs/raceengine/racetrack.cpp @@ -79,9 +79,10 @@ ReTrackInit(void) reTrackDump(ReInfo->track, 0); + // TODO: Remove (old graphics setup, and anyway : not needed ?) // Make the graphics engine aware of the possibly changed track. - if (ReInfo->_reGraphicItf.inittrack) - ReInfo->_reGraphicItf.inittrack(ReInfo->track); + // if (ReInfo->_reGraphicItf.inittrack) + // ReInfo->_reGraphicItf.inittrack(ReInfo->track); return 0; }//ReTrackInit @@ -415,8 +416,10 @@ reTrackUpdatePhysics(void) int ReTrackShutdown(void) { - if (ReInfo->_reGraphicItf.shutdowntrack) - ReInfo->_reGraphicItf.shutdowntrack(); + // TODO: Remove (old graphics setup) + // if (ReInfo->_reGraphicItf.shutdowntrack) + // ReInfo->_reGraphicItf.shutdowntrack(); + RaceEngine::self().userInterface().unloadTrackGraphics(); return 0; } diff --git a/src/libs/raceengine/raceupdate.cpp b/src/libs/raceengine/raceupdate.cpp index 8e73198c..8f42c770 100644 --- a/src/libs/raceengine/raceupdate.cpp +++ b/src/libs/raceengine/raceupdate.cpp @@ -612,9 +612,6 @@ public: //! Constructor. reMainUpdater(reSituationUpdater* pSituUpdater); - //! Initialize the graphics engine about cars. - void initCarGraphics(void); - //! Return from pit menu void onBackFromPitMenu(tCarElt *car); @@ -671,11 +668,6 @@ reMainUpdater::reMainUpdater(reSituationUpdater* pSituUpdater) #endif } -void reMainUpdater::initCarGraphics(void) -{ - _pReInfo->_reGraphicItf.initcars(_pReInfo->s); -} - void reMainUpdater::captureScreen(void) { char filename[256]; @@ -740,7 +732,7 @@ int reMainUpdater::operator()(void) // Do the frame capture if specified. // Moved here, right before situationUpdater->getPreviousStep, - // as we can only capture the already displayed time, + // as we can only capture the already displayed frame, // (because the one generated by _reGraphicItf.refresh will be displayed // _after_ ReUpdate returns : see guieventloop.cpp::GfefPostReDisplay) if (ReInfo->_displayMode == RM_DISP_MODE_CAPTURE) @@ -770,7 +762,7 @@ int reMainUpdater::operator()(void) { // Update the graphics (display the current frame). GfSchedBeginEvent("raceupdate", "graphics"); - _pReInfo->_reGraphicItf.refresh(_pReInfo->s); + userItf.updateGraphicsView(_pReInfo->s); GfSchedEndEvent("raceupdate", "graphics"); // Update on-screen racing messages for the user. @@ -835,11 +827,6 @@ void ReInitUpdaters() GfSchedConfigureEventLog("raceupdate", "physics", 10000, 0.0); } -void ReInitCarGraphics(void) -{ - mainUpdater->initCarGraphics(); -} - void ReAccelerateTime(double fMultFactor) { ReInfo->_reTimeMult *= fMultFactor; diff --git a/src/libs/raceengine/raceupdate.h b/src/libs/raceengine/raceupdate.h index 297a8adb..4cc775c3 100644 --- a/src/libs/raceengine/raceupdate.h +++ b/src/libs/raceengine/raceupdate.h @@ -27,7 +27,8 @@ #define _RACEUPDATE_H_ extern void ReInitUpdaters(); -extern void ReInitCarGraphics(); +// TODO: Remove (old graphics setup): code moved into ReRaceRealStart +//extern void ReInitCarGraphics(); extern void ReShutdownUpdaters(); extern void ReAccelerateTime(double fMultFactor); diff --git a/src/modules/graphic/ssggraph/CMakeLists.txt b/src/modules/graphic/ssggraph/CMakeLists.txt index 739bc4c5..1ba5a5c0 100644 --- a/src/modules/graphic/ssggraph/CMakeLists.txt +++ b/src/modules/graphic/ssggraph/CMakeLists.txt @@ -8,12 +8,14 @@ SET(SSGGRAPH_SOURCES CarSoundData.cpp CarSoundData.h grboard.cpp grboard.h grcam.cpp grcam.h grcar.cpp grcar.h grcarlight.cpp grcarlight.h grmain.cpp grmain.h grmultitexstate.cpp grmultitexstate.h grloadac.cpp grloadac.h grssgext.h - grscene.cpp grscene.h grbackground.cpp grbackground.h grscreen.cpp grscreen.h + grscene.cpp grscene.h grbackground.cpp grbackground.h + grscreen.cpp grscreen.h grshadow.cpp grshadow.h grskidmarks.cpp grskidmarks.h grsmoke.cpp grsmoke.h grtexture.cpp grtexture.h loadsgi.h grsound.cpp grsound.h grtracklight.cpp grtracklight.h grtrackmap.cpp grtrackmap.h grutil.cpp grutil.h - grvtxtable.cpp grvtxtable.h grrain.cpp grrain.h ssggraph.cpp) + grvtxtable.cpp grvtxtable.h grrain.cpp grrain.h + ssggraph.cpp ssggraph.h) ADD_INTERFACE_INCLUDEDIR() ADD_SDLIB_INCLUDEDIR(portability math tgf tgfclient robottools) @@ -29,13 +31,7 @@ IF(WIN32) SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib") ENDIF(WIN32) -IF(UNIX) - ADD_LIBRARY(ssggraph SHARED ${SSGGRAPH_SOURCES}) -ENDIF(UNIX) - -IF(WIN32) - ADD_LIBRARY(ssggraph SHARED ${SSGGRAPH_SOURCES} ssggraph.def) -ENDIF(WIN32) +ADD_LIBRARY(ssggraph SHARED ${SSGGRAPH_SOURCES}) IF(UNIX) SET_TARGET_PROPERTIES(ssggraph PROPERTIES PREFIX "") diff --git a/src/modules/graphic/ssggraph/grmain.cpp b/src/modules/graphic/ssggraph/grmain.cpp index 85070d77..f8bd50a5 100644 --- a/src/modules/graphic/ssggraph/grmain.cpp +++ b/src/modules/graphic/ssggraph/grmain.cpp @@ -26,6 +26,7 @@ #include #include // GfglFeatures #include //ROB_SECT_ARBITRARY +#include #include "grmain.h" #include "grshadow.h" @@ -358,8 +359,6 @@ grSwitchMirror(void * /* dummy */) grGetCurrentScreen()->switchMirror(); } -//bool -//SsgGraph::initView(int x, int y, int width, int height, void* pMenuScreen) int initView(int x, int y, int width, int height, int /* flag */, void *screen) { @@ -391,7 +390,9 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen) grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); } + // Create the screens and initialize each board. for (i = 0; i < GR_NB_MAX_SCREEN; i++) { + grScreens[i] = new cGrScreen(i); grScreens[i]->initBoard (); } @@ -440,8 +441,6 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen) } -//void -//SsgGraph::updateView(tSituation* s) int refresh(tSituation *s) { @@ -493,8 +492,6 @@ refresh(tSituation *s) return 0; } -//bool -//SsgGraph::initCars(tSituation* s) int initCars(tSituation *s) { @@ -585,8 +582,6 @@ initCars(tSituation *s) return 0; // true; } -//void -//SsgGraph::shutdownCars() void shutdownCars(void) { @@ -628,8 +623,6 @@ shutdownCars(void) (double)frameInfo.nTotalFrames/((double)nFPSTotalSeconds + GfTimeClock() - fFPSPrevInstTime)); } -//bool -//SsgGraph::initTrack(tTrack* pTrack) int initTrack(tTrack *track) { @@ -641,16 +634,10 @@ initTrack(tTrack *track) if (grNbActiveScreens > 0) grLoadScene(track); - for (int i = 0; i < GR_NB_MAX_SCREEN; i++) { - grScreens[i] = new cGrScreen(i); - } - - return 0; // true; + return 0; } -//void -//SsgGraph::shutdownTrack() void shutdownTrack(void) { diff --git a/src/modules/graphic/ssggraph/grmain.h b/src/modules/graphic/ssggraph/grmain.h index c62dfe40..f70e5d36 100644 --- a/src/modules/graphic/ssggraph/grmain.h +++ b/src/modules/graphic/ssggraph/grmain.h @@ -21,7 +21,6 @@ #define _GRMAIN_H_ #include //ssgContect -#include //tSituation #ifdef WIN32 #include @@ -29,6 +28,9 @@ #include #endif +#include +#include //tSituation + #ifdef WIN32 // Multi-texturing functions : Under Windows, not present in gl.h or any other ; diff --git a/src/modules/graphic/ssggraph/ssggraph.cpp b/src/modules/graphic/ssggraph/ssggraph.cpp index 5b4b4bec..1ca8d70f 100644 --- a/src/modules/graphic/ssggraph/ssggraph.cpp +++ b/src/modules/graphic/ssggraph/ssggraph.cpp @@ -17,130 +17,105 @@ * * ***************************************************************************/ -#ifdef WIN32 -#include -#endif - -#if defined(__APPLE__) -#include -#else -#include -#endif +#include "ssggraph.h" #include "grmain.h" #include "grtexture.h" -#ifdef DMALLOC -#include "dmalloc.h" -#endif -// Default SSG loader options for ssgInit (workaround try for ssggraph crash at re-load time). -static ssgLoaderOptions* DefaultSSGLoaderOptions = 0; +// The SsgGraph: singleton. +SsgGraph* SsgGraph::_pSelf = 0; - -static int -graphInit(int /* idx */, void *pt) +int openGfModule(const char* pszShLibName, void* hShLibHandle) { - tGraphicItf *itf = (tGraphicItf*)pt; - - itf->inittrack = initTrack; - itf->initcars = initCars; - itf->initview = initView; - itf->refresh = refresh; - itf->shutdowncars = shutdownCars; - itf->shutdowntrack = shutdownTrack; - //itf->bendcar = bendCar; - return 0; + // Instanciate the (only) module instance. + SsgGraph::_pSelf = new SsgGraph(pszShLibName, hShLibHandle); + + // Register it to the GfModule module manager if OK. + if (SsgGraph::_pSelf) + GfModule::register_(SsgGraph::_pSelf); + + // Report about success or error. + return SsgGraph::_pSelf ? 0 : 1; } -/* - * 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) - +int closeGfModule() { - welcomeOut->maxNbItf = 1; + // Unregister it from the GfModule module manager. + if (SsgGraph::_pSelf) + GfModule::unregister(SsgGraph::_pSelf); + + // Delete the (only) module instance. + delete SsgGraph::_pSelf; + SsgGraph::_pSelf = 0; - return 0; + // Report about success or error. + 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) +SsgGraph& SsgGraph::self() { - modInfo->name = "ssggraph"; /* name of the module (short) */ - modInfo->desc = "The graphics module built on top of PLib ssg"; /* description of the module (can be long) */ - modInfo->fctInit = graphInit; /* init function */ - modInfo->gfId = 1; /* v 1 */ - modInfo->index = 0; + // Pre-condition : 1 successfull openGfModule call. + return *_pSelf; +} - // Override default SSG loader option with ours +SsgGraph::SsgGraph(const std::string& strShLibName, void* hShLibHandle) +: GfModule(strShLibName, hShLibHandle) +{ + // Override the default SSG loader options object with our's // (workaround try for ssggraph crash at re-load time). - DefaultSSGLoaderOptions = new ssgLoaderOptions; - ssgSetCurrentOptions(DefaultSSGLoaderOptions); + _pDefaultSSGLoaderOptions = new ssgLoaderOptions; + ssgSetCurrentOptions(_pDefaultSSGLoaderOptions); - // Initialize PLib SSG layer. + // Initialize the PLib SSG layer. ssgInit(); //Setup image loaders grRegisterCustomSGILoader(); - - return 0; } -/* - * Function - * moduleTerminate - * - * Description - * Module exit point - * - * Parameters - * None - * - * Return - * 0, if no error occured - * non 0, otherwise - * - * Remarks - * - */ -extern "C" int moduleTerminate() +SsgGraph::~SsgGraph() { - delete DefaultSSGLoaderOptions; - - return 0; + // Terminate the PLib SSG layer. + delete _pDefaultSSGLoaderOptions; } +// Implementation of IGraphicsEngine **************************************** +bool SsgGraph::loadTrack(tTrack* pTrack) +{ + return ::initTrack(pTrack) == 0; +} + +bool SsgGraph::loadCars(tSituation* pSituation) +{ + return ::initCars(pSituation) == 0; +} + +bool SsgGraph::setupView(int x, int y, int width, int height, void* pMenuScreen) +{ + return ::initView(x, y, width, height, GR_VIEW_STD, pMenuScreen) == 0; +} + +void SsgGraph::updateView(tSituation* pSituation) +{ + ::refresh(pSituation); +} + +void SsgGraph::shutdownView() +{ +} + +void SsgGraph::unloadCars() +{ + ::shutdownCars(); +} + +void SsgGraph::unloadTrack() +{ + ::shutdownTrack(); +} + +// void SsgGraph::bendCar(int index, sgVec3 poc, sgVec3 force, int count) +// { +// ::bendCar(index, poc, force, count); +// } diff --git a/src/modules/graphic/ssggraph/ssggraph.def b/src/modules/graphic/ssggraph/ssggraph.def deleted file mode 100644 index f72e4bfc..00000000 --- a/src/modules/graphic/ssggraph/ssggraph.def +++ /dev/null @@ -1,12 +0,0 @@ -; -; ssggraph.def -; - -LIBRARY - -SECTIONS .data READ WRITE - -EXPORTS - moduleWelcome - moduleInitialize - moduleTerminate diff --git a/src/modules/graphic/ssggraph/ssggraph.h b/src/modules/graphic/ssggraph/ssggraph.h new file mode 100755 index 00000000..5b1e5a3c --- /dev/null +++ b/src/modules/graphic/ssggraph/ssggraph.h @@ -0,0 +1,90 @@ +/*************************************************************************** + + file : ssggraph.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 "ssggraph" graphics engine module + @version $Id$ +*/ + +#ifndef _SSGGRAPH_H_ +#define _SSGGRAPH_H_ + +#include + +#include + +class ssgLoaderOptions; + + +// DLL exported symbols declarator for Windows. +#ifdef WIN32 +# ifdef ssggraph_EXPORTS +# define SSGGRAPH_API __declspec(dllexport) +# else +# define SSGGRAPH_API __declspec(dllimport) +# endif +#else +# define SSGGRAPH_API +#endif + + +// The C interface of the module. +extern "C" int SSGGRAPH_API openGfModule(const char* pszShLibName, void* hShLibHandle); +extern "C" int SSGGRAPH_API closeGfModule(); + +// The module main class (Singleton, inherits GfModule, and implements IGraphicsEngine). +class SSGGRAPH_API SsgGraph : public GfModule, public IGraphicsEngine +{ + public: + + // Implementation of IGraphicsEngine. + virtual bool loadTrack(struct Track* pTrack); + virtual bool loadCars(struct Situation *pSituation); + virtual bool setupView(int x, int y, int width, int height, void* pMenuScreen); + virtual void updateView(struct Situation *pSituation); + virtual void shutdownView(); + virtual void unloadCars(); + virtual void unloadTrack(); + + //virtual void bendCar(int index, sgVec3 poc, sgVec3 force, int count = 0); + + // Accessor to the singleton. + static SsgGraph& self(); + + // Destructor. + virtual ~SsgGraph(); + + protected: + + // Protected constructor to avoid instanciation outside (but friends). + SsgGraph(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 SsgGraph* _pSelf; + + // The default SSGLoaderOptions instance. + ssgLoaderOptions* _pDefaultSSGLoaderOptions; +}; + +#endif /* _SSGGRAPH_H_ */ diff --git a/src/modules/networking/network.cpp b/src/modules/networking/network.cpp index cc4223f7..9cb2beee 100644 --- a/src/modules/networking/network.cpp +++ b/src/modules/networking/network.cpp @@ -39,6 +39,8 @@ based on the server values. #include #include +#include + #include "network.h" diff --git a/src/modules/userinterface/legacymenu/confscreens/playerconfig.cpp b/src/modules/userinterface/legacymenu/confscreens/playerconfig.cpp index e8268d78..8b5530a7 100644 --- a/src/modules/userinterface/legacymenu/confscreens/playerconfig.cpp +++ b/src/modules/userinterface/legacymenu/confscreens/playerconfig.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "controlconfig.h" diff --git a/src/modules/userinterface/legacymenu/legacymenu.cpp b/src/modules/userinterface/legacymenu/legacymenu.cpp index 109cf4ca..6a53b897 100644 --- a/src/modules/userinterface/legacymenu/legacymenu.cpp +++ b/src/modules/userinterface/legacymenu/legacymenu.cpp @@ -16,7 +16,11 @@ * * ***************************************************************************/ +#include +#include + #include +#include #include @@ -64,7 +68,7 @@ LegacyMenu& LegacyMenu::self() } LegacyMenu::LegacyMenu(const std::string& strShLibName, void* hShLibHandle) -: GfModule(strShLibName, hShLibHandle), _piRaceEngine(0) +: GfModule(strShLibName, hShLibHandle), _piRaceEngine(0), _piGraphicsEngine(0) { } @@ -219,6 +223,85 @@ void LegacyMenu::activateStandingsMenu(void *prevHdle, tRmInfo *reInfo, int star ::RmShowStandings(prevHdle, reInfo, start); } +// Graphics engine control. +bool LegacyMenu::initializeGraphics() +{ + // Check if the module is already loaded, and do nothing more if so. + if (_piGraphicsEngine) + return true; + + // Load the graphics module + std::ostringstream ossModLibName; + ossModLibName << GfLibDir() << "modules/graphic/" + << GfParmGetStr(_piRaceEngine->data()->_reParam, "Modules", "graphic", "") + << '.' << DLLEXT; + GfModule* pmodGrEngine = GfModule::load(ossModLibName.str()); + + // Check that it implements IGraphicsEngine. + if (pmodGrEngine) + _piGraphicsEngine = pmodGrEngine->getInterface(); + if (!_piGraphicsEngine) + GfLogError("IGraphicsEngine not implemented by %s\n", ossModLibName.str().c_str()); + + return _piGraphicsEngine != 0; +} + +bool LegacyMenu::loadTrackGraphics(struct Track* pTrack) +{ + return _piGraphicsEngine ? _piGraphicsEngine->loadTrack(pTrack) : false; +} + +bool LegacyMenu::loadCarsGraphics(struct Situation *pSituation) +{ + return _piGraphicsEngine ? _piGraphicsEngine->loadCars(pSituation) : false; +} + +bool LegacyMenu::setupGraphicsView() +{ + // Initialize the graphics view. + if (!_piGraphicsEngine) + return false; + + // Retrieve the screen dimensions. + int sw, sh, vw, vh; + GfScrGetSize(&sw, &sh, &vw, &vh); + + // Setup the graphics view. + return _piGraphicsEngine->setupView((sw-vw)/2, (sh-vh)/2, vw, vh, + _piRaceEngine->data()->_reGameScreen); +} +void LegacyMenu::updateGraphicsView(struct Situation *pSituation) +{ + if (_piGraphicsEngine) + _piGraphicsEngine->updateView(pSituation); +} + +void LegacyMenu::unloadCarsGraphics() +{ + if (_piGraphicsEngine) + _piGraphicsEngine->unloadCars(); +} + +void LegacyMenu::unloadTrackGraphics() +{ + if (_piGraphicsEngine) + _piGraphicsEngine->unloadTrack(); +} + +void LegacyMenu::shutdownGraphics() +{ + // Do nothing if the module has already been unloaded. + if (!_piGraphicsEngine) + return; + + // Unload the graphics module. + GfModule* pmodGrEngine = dynamic_cast(_piGraphicsEngine); + GfModule::unload(pmodGrEngine); + + // And remember it was. + _piGraphicsEngine = 0; +} + void LegacyMenu::setRaceEngine(IRaceEngine& raceEngine) { _piRaceEngine = &raceEngine; diff --git a/src/modules/userinterface/legacymenu/legacymenu.h b/src/modules/userinterface/legacymenu/legacymenu.h index 85d72814..f79200d6 100644 --- a/src/modules/userinterface/legacymenu/legacymenu.h +++ b/src/modules/userinterface/legacymenu/legacymenu.h @@ -28,6 +28,7 @@ #include +class IGraphicsEngine; // DLL exported symbols declarator for Windows. #ifdef WIN32 @@ -93,6 +94,15 @@ public: virtual void activateStandingsMenu(void *prevHdle, struct RmInfo *info, int start = 0); + // Graphics engine control. + virtual bool initializeGraphics(); + virtual bool loadTrackGraphics(struct Track* pTrack); + virtual bool loadCarsGraphics(struct Situation *pSituation); + virtual bool setupGraphicsView(); + virtual void updateGraphicsView(struct Situation *pSituation); + virtual void unloadCarsGraphics(); + virtual void unloadTrackGraphics(); + virtual void shutdownGraphics(); virtual void setRaceEngine(IRaceEngine& raceEngine); // Accessor to the singleton. @@ -114,6 +124,9 @@ protected: // The race engine. IRaceEngine* _piRaceEngine; + // The graphics engine. + IGraphicsEngine* _piGraphicsEngine; + // Make the C interface functions nearly member functions. friend int openGfModule(const char* pszShLibName, void* hShLibHandle); friend int closeGfModule();