Re #374 Fixed crash when entering and immediately exiting the Race Select menu + restored unloading the physics engine at the end of each race (not sure useful though)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3578 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 846ca1128fcf5a7765913d9d2637b633d25a20f7 Former-commit-id: 785a781e5f77eaa6d872967f850e4847374ee908
This commit is contained in:
parent
b8b3d8e53c
commit
70301b3866
4 changed files with 113 additions and 79 deletions
|
@ -21,8 +21,16 @@
|
|||
@version $Id$
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <tgf.hpp>
|
||||
|
||||
#include <itrackloader.h>
|
||||
#include <iphysicsengine.h>
|
||||
#include <car.h> // tCarPitCmd.
|
||||
|
||||
#include <tracks.h>
|
||||
|
||||
#include "racesituation.h"
|
||||
#include "racemain.h"
|
||||
#include "raceinit.h"
|
||||
|
@ -44,18 +52,80 @@ RaceEngine& RaceEngine::self()
|
|||
}
|
||||
|
||||
RaceEngine::RaceEngine()
|
||||
: _piUserItf(0)
|
||||
: _piUserItf(0), _piPhysEngine(0)
|
||||
{
|
||||
}
|
||||
|
||||
// Implementation of IRaceEngine.
|
||||
void RaceEngine::initialize(void)
|
||||
{
|
||||
GfLogInfo("Initializing race engine.\n");
|
||||
|
||||
// Cleanup everything in case no yet done.
|
||||
shutdown();
|
||||
|
||||
// Internal init.
|
||||
::ReInit();
|
||||
|
||||
// Load and initialize the track loader module.
|
||||
GfLogInfo("Loading Track Loader ...\n");
|
||||
std::ostringstream ossModLibName;
|
||||
const char* pszModName =
|
||||
GfParmGetStr(ReSituation::self().data()->_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 (pmodTrkLoader && !piTrkLoader)
|
||||
{
|
||||
GfModule::unload(pmodTrkLoader);
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize GfTracks' track module interface (needed for some track infos).
|
||||
GfTracks::self()->setTrackLoader(piTrkLoader);
|
||||
}
|
||||
|
||||
void RaceEngine::shutdown(void)
|
||||
{
|
||||
GfLogInfo("Terminating race engine.\n");
|
||||
|
||||
// Internal cleanup.
|
||||
::ReShutdown();
|
||||
|
||||
// Unload the track if not already done.
|
||||
ITrackLoader* piTrkLoader = GfTracks::self()->getTrackLoader();
|
||||
if (piTrkLoader)
|
||||
piTrkLoader->unload();
|
||||
|
||||
// Unload the Track loader module if not already done.
|
||||
if (piTrkLoader)
|
||||
{
|
||||
GfModule* pmodTrkLoader = dynamic_cast<GfModule*>(piTrkLoader);
|
||||
if (pmodTrkLoader)
|
||||
{
|
||||
GfModule::unload(pmodTrkLoader);
|
||||
GfTracks::self()->setTrackLoader(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Unload the Physics engine module if not already done.
|
||||
if (_piPhysEngine)
|
||||
{
|
||||
GfModule* pmodPhysEngine = dynamic_cast<GfModule*>(_piPhysEngine);
|
||||
if (pmodPhysEngine)
|
||||
{
|
||||
GfModule::unload(pmodPhysEngine);
|
||||
_piPhysEngine = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown the Graphics modules if not already done.
|
||||
if (_piUserItf)
|
||||
_piUserItf->shutdownGraphics(); // => onRaceEngineShutdown ?
|
||||
}
|
||||
|
||||
void RaceEngine::setUserInterface(IUserInterface& userItf)
|
||||
|
@ -171,10 +241,41 @@ IUserInterface& RaceEngine::userInterface()
|
|||
return *_piUserItf;
|
||||
}
|
||||
|
||||
// Set the physics engine.
|
||||
void RaceEngine::setPhysicsEngine(IPhysicsEngine* piPhysEngine)
|
||||
// Physics engine management.
|
||||
bool RaceEngine::loadPhysicsEngine()
|
||||
{
|
||||
_piPhysEngine = piPhysEngine;
|
||||
// Load the Physics engine module if not already done.
|
||||
if (_piPhysEngine)
|
||||
return true;
|
||||
|
||||
const char* pszModName =
|
||||
GfParmGetStr(ReSituation::self().data()->_reParam, "Modules", "simu", "");
|
||||
std::ostringstream ossLoadMsg;
|
||||
ossLoadMsg << "Loading physics engine (" << pszModName<< ") ...";
|
||||
if (_piUserItf)
|
||||
_piUserItf->addLoadingMessage(ossLoadMsg.str().c_str());
|
||||
|
||||
std::ostringstream ossModLibName;
|
||||
ossModLibName << GfLibDir() << "modules/simu/" << pszModName << '.' << DLLEXT;
|
||||
GfModule* pmodPhysEngine = GfModule::load(ossModLibName.str());
|
||||
if (pmodPhysEngine)
|
||||
_piPhysEngine = pmodPhysEngine->getInterface<IPhysicsEngine>();
|
||||
if (pmodPhysEngine && !_piPhysEngine)
|
||||
GfModule::unload(pmodPhysEngine);
|
||||
|
||||
return _piPhysEngine ? true : false;
|
||||
}
|
||||
|
||||
void RaceEngine::unloadPhysicsEngine()
|
||||
{
|
||||
// Unload the Physics engine module if not already done.
|
||||
if (!_piPhysEngine)
|
||||
return;
|
||||
|
||||
GfModule* pmodPhysEngine = dynamic_cast<GfModule*>(_piPhysEngine);
|
||||
if (pmodPhysEngine)
|
||||
GfModule::unload(pmodPhysEngine);
|
||||
_piPhysEngine = 0;
|
||||
}
|
||||
|
||||
// Accessor to the physics engine.
|
||||
|
|
|
@ -93,8 +93,9 @@ public:
|
|||
// Accessor to the user interface.
|
||||
IUserInterface& userInterface();
|
||||
|
||||
// Set the physics engine.
|
||||
void setPhysicsEngine(IPhysicsEngine* piPhysEngine);
|
||||
// Physics engine management.
|
||||
bool loadPhysicsEngine();
|
||||
void unloadPhysicsEngine();
|
||||
|
||||
// Accessor to the physics engine.
|
||||
IPhysicsEngine& physicsEngine();
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <sstream>
|
||||
#include <map>
|
||||
|
||||
#include <itrackloader.h>
|
||||
#include <raceman.h>
|
||||
#include <robot.h>
|
||||
#include <teammanager.h>
|
||||
|
@ -37,7 +36,6 @@
|
|||
#include <portability.h>
|
||||
#include <tgf.hpp>
|
||||
|
||||
#include <tracks.h>
|
||||
#include <racemanagers.h>
|
||||
#include <race.h>
|
||||
|
||||
|
@ -75,15 +73,10 @@ GfRace* ReGetRace()
|
|||
void
|
||||
ReInit(void)
|
||||
{
|
||||
GfLogInfo("Initializing race engine.\n");
|
||||
|
||||
// If not already done, instanciate the race object.
|
||||
if (!PReRace)
|
||||
PReRace = new GfRace();
|
||||
|
||||
// Shutdown the previous race engine if any.
|
||||
ReShutdown();
|
||||
|
||||
// Allocate race engine info structures.
|
||||
ReInfo = ReSituation::self().data();
|
||||
ReInfo->robModList = &ReRacingRobotsModList;
|
||||
|
@ -91,29 +84,8 @@ ReInit(void)
|
|||
// Load Race engine params.
|
||||
char buf[256];
|
||||
snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), RACE_ENG_CFG);
|
||||
|
||||
ReInfo->_reParam = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
|
||||
|
||||
// Load and initialize the track loader module.
|
||||
GfLogInfo("Loading Track Loader ...\n");
|
||||
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 (pmodTrkLoader && !piTrkLoader)
|
||||
{
|
||||
GfModule::unload(pmodTrkLoader);
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize GfTracks' track module interface (needed for some track infos).
|
||||
GfTracks::self()->setTrackLoader(piTrkLoader);
|
||||
|
||||
// Set ReStateManage as the event loop "display" call-back when the race will actually start
|
||||
// (will be actually used after something like GfuiScreenActivate(ReInfo->_reGameScreen)).
|
||||
ReInfo->_reGameScreen = ReUI().createRaceEventLoopHook();
|
||||
|
@ -126,7 +98,7 @@ ReExit(void)
|
|||
{
|
||||
// Stop and shutdown the race engine.
|
||||
ReStop();
|
||||
ReShutdown();
|
||||
RaceEngine::self().shutdown();
|
||||
|
||||
// Notify the user interface.
|
||||
ReUI().quit();
|
||||
|
@ -140,29 +112,6 @@ void ReShutdown(void)
|
|||
if (!ReInfo)
|
||||
return;
|
||||
|
||||
GfLogInfo("Terminating race engine.\n");
|
||||
|
||||
// Unload the track.
|
||||
ITrackLoader* piTrkLoader = GfTracks::self()->getTrackLoader();
|
||||
piTrkLoader->unload();
|
||||
|
||||
// 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.
|
||||
ReSituation::terminate();
|
||||
ReInfo = 0;
|
||||
|
@ -861,6 +810,7 @@ ReRaceCleanup(void)
|
|||
ReInfo->_reGameScreen = ReUI().createRaceEventLoopHook();
|
||||
|
||||
RePhysicsEngine().shutdown();
|
||||
RaceEngine::self().unloadPhysicsEngine();
|
||||
|
||||
if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <sstream>
|
||||
|
||||
#include <portability.h>
|
||||
#include <tgf.hpp>
|
||||
|
||||
#include <robot.h>
|
||||
#include <network.h>
|
||||
|
@ -83,6 +82,7 @@ void ReRaceAbort()
|
|||
ReShutdownUpdaters();
|
||||
|
||||
RePhysicsEngine().shutdown();
|
||||
RaceEngine::self().unloadPhysicsEngine();
|
||||
|
||||
// TODO: Move these 3 XXGraphicsYY calls to the user interface module ?
|
||||
if (ReInfo->_displayMode == RM_DISP_MODE_NORMAL)
|
||||
|
@ -269,27 +269,9 @@ ReRaceRealStart(void)
|
|||
void* carHdle;
|
||||
|
||||
// Load the physics engine
|
||||
const char* pszModName = GfParmGetStr(ReInfo->_reParam, "Modules", "simu", "");
|
||||
snprintf(buf, sizeof(buf), "Loading physics engine (%s) ...", pszModName);
|
||||
ReUI().addLoadingMessage(buf);
|
||||
|
||||
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)
|
||||
if (!RaceEngine::self().loadPhysicsEngine())
|
||||
return RM_ERROR;
|
||||
|
||||
|
||||
// Check if there is a human in the driver list
|
||||
foundHuman = ReHumanInGroup() ? 2 : 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue