Re #374 (migrated the ssggraph module to the new module scheme) and re #378 (removed the direct dependency of the race engine to the graphics engine)

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

Former-commit-id: c34ed849a4756eddea78f5f54018f4d2f70a7cb5
Former-commit-id: d6c4224637985f264cba5c20dd53ad5477bb52dc
This commit is contained in:
pouillot 2011-04-05 21:02:08 +00:00
parent 0e2f745a95
commit 7770116d7f
21 changed files with 382 additions and 208 deletions

View file

@ -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})

View file

@ -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 <graphic.h>
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__

View file

@ -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;
};

View file

@ -30,7 +30,8 @@
#include <tgf.h>
#include <car.h>
#include <track.h>
#include <graphic.h>
// TODO: Remove (old graphics setup)
//#include <graphic.h>
#include <simu.h>
#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

View file

@ -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();
}

View file

@ -27,8 +27,6 @@
#include <robot.h>
#include <network.h>
#include <tgfclient.h> // 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;
@ -398,9 +392,10 @@ ReRaceRealStart(void)
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())

View file

@ -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;

View file

@ -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.

View file

@ -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;
}

View file

@ -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;

View file

@ -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);

View file

@ -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)
IF(UNIX)
SET_TARGET_PROPERTIES(ssggraph PROPERTIES PREFIX "")

View file

@ -26,6 +26,7 @@
#include <plib/ssg.h>
#include <glfeatures.h> // GfglFeatures
#include <robot.h> //ROB_SECT_ARBITRARY
#include <graphic.h>
#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)
{

View file

@ -21,7 +21,6 @@
#define _GRMAIN_H_
#include <plib/ssg.h> //ssgContect
#include <raceman.h> //tSituation
#ifdef WIN32
#include <windows.h>
@ -29,6 +28,9 @@
#include <GL/glext.h>
#endif
#include <graphic.h>
#include <raceman.h> //tSituation
#ifdef WIN32
// Multi-texturing functions : Under Windows, not present in gl.h or any other ;

View file

@ -17,130 +17,105 @@
* *
***************************************************************************/
#ifdef WIN32
#include <windows.h>
#endif
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#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;
// Instanciate the (only) module instance.
SsgGraph::_pSelf = new SsgGraph(pszShLibName, hShLibHandle);
itf->inittrack = initTrack;
itf->initcars = initCars;
itf->initview = initView;
itf->refresh = refresh;
itf->shutdowncars = shutdownCars;
itf->shutdowntrack = shutdownTrack;
//itf->bendcar = bendCar;
// 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;
}
int closeGfModule()
{
// 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;
// Report about success or error.
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)
SsgGraph& SsgGraph::self()
{
welcomeOut->maxNbItf = 1;
return 0;
// Pre-condition : 1 successfull openGfModule call.
return *_pSelf;
}
/*
* 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(const std::string& strShLibName, void* hShLibHandle)
: GfModule(strShLibName, hShLibHandle)
{
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;
// Override default SSG loader option with ours
// 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);
// }

View file

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

View file

@ -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 <igraphicsengine.h>
#include <tgf.hpp>
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_ */

View file

@ -39,6 +39,8 @@ based on the server values.
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include <graphic.h>
#include "network.h"

View file

@ -26,6 +26,7 @@
#include <tgfclient.h>
#include <robot.h>
#include <playerpref.h>
#include <graphic.h>
#include <gui.h>
#include "controlconfig.h"

View file

@ -16,7 +16,11 @@
* *
***************************************************************************/
#include <string>
#include <sstream>
#include <iraceengine.h>
#include <igraphicsengine.h>
#include <tgfclient.h>
@ -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<IGraphicsEngine>();
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<GfModule*>(_piGraphicsEngine);
GfModule::unload(pmodGrEngine);
// And remember it was.
_piGraphicsEngine = 0;
}
void LegacyMenu::setRaceEngine(IRaceEngine& raceEngine)
{
_piRaceEngine = &raceEngine;

View file

@ -28,6 +28,7 @@
#include <tgf.hpp>
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();