Fixes #745 Last bits of sound and graphics engine separation

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5095 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
pouillot 2013-01-12 17:57:47 +00:00
parent 845fbec203
commit c0b9fa46f1
19 changed files with 286 additions and 178 deletions

View File

@ -3,7 +3,8 @@ INCLUDE(../../cmake/macros.cmake)
SET(INTERFACES_HEADERS car.h graphic.h playerpref.h raceman.h
replay.h robot.h telemetry.h track.h
iraceengine.h iuserinterface.h igraphicsengine.h
iphysicsengine.h itrackloader.h isoundengine.h)
iphysicsengine.h itrackloader.h isoundengine.h
camera.h)
# Fictive = no-output target, for having source files available in IDEs.
ADD_CUSTOM_TARGET(interfaces SOURCES ${INTERFACES_HEADERS})

33
src/interfaces/camera.h Normal file
View File

@ -0,0 +1,33 @@
/***************************************************************************
camera.h -- A generic camera
created : Sun Jan 6 19:48:14 CEST 2013
copyright : (C) 2013 by Gaëtan André
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 __CAMERA__H__
#define __CAMERA__H__
typedef float sndVec3[3];
struct Camera
{
sndVec3 * Posv;
sndVec3 * Speedv;
sndVec3 * Centerv;
sndVec3 * Upv;
};
#endif // __CAMERA__H__

View File

@ -25,14 +25,6 @@
#define GR_PARAM_FILE "config/graph.xml"
#define GR_SOUND_PARM_CFG "config/sound.xml"
#define GR_SCT_SOUND "Sound Settings"
#define GR_ATT_SOUND_STATE "state"
#define GR_ATT_SOUND_STATE_PLIB "plib"
#define GR_ATT_SOUND_STATE_OPENAL "openal"
#define GR_ATT_SOUND_STATE_DISABLED "disabled"
#define GR_ATT_SOUND_VOLUME "volume"
#define GR_SCT_DISPMODE "Display Mode"
#define GR_ATT_CAM "camera"
#define GR_ATT_CAM_HEAD "camera head list"

View File

@ -21,11 +21,11 @@
@version $Id$
*/
#include "isoundengine.h"
#ifndef __IGRAPHICSENGINE__H__
#define __IGRAPHICSENGINE__H__
#include "camera.h"
class IGraphicsEngine
{
public:
@ -37,7 +37,9 @@ public:
virtual void shutdownView() = 0;
virtual void unloadCars() = 0;
virtual void unloadTrack() = 0;
virtual SoundCam *getCurCam() = 0;
// Return the current (end-user) camera, as a new instance (caller must delete after use).
virtual Camera *getCurCam() = 0;
//virtual void bendCar(int index, sgVec3 poc, sgVec3 force, int count = 0) = 0;
};

View File

@ -20,15 +20,7 @@
#define __ISOUNDENGINE__H__
typedef float sndVec3[3];
struct SoundCam
{
sndVec3 * Posv;
sndVec3 * Speedv;
sndVec3 * Centerv;
sndVec3 * Upv;
};
#include "camera.h"
class ISoundEngine
{
@ -36,8 +28,8 @@ public:
virtual void init(struct Situation* s) = 0;
virtual void shutdown() = 0;
virtual void refresh(struct Situation *s, SoundCam *camera) = 0;
virtual void mute(bool bOn = true) = 0;
virtual void refresh(struct Situation *s, Camera *camera) = 0;
virtual void mute(bool bOn = true) = 0;
};
#endif // __ISOUNDENGINE__H__

43
src/interfaces/sound.h Normal file
View File

@ -0,0 +1,43 @@
/***************************************************************************
file : sound.h
created : Sun Jan 13 10:58:45 CET 2013
copyright : (C) 2013 by Jean-Philippe
web : 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 _SOUND_H_
#define _SOUND_H_
#define SND_PARAM_FILE "config/sound.xml"
#define SND_SCT_SOUND "Sound Settings"
#define SND_ATT_SOUND_STATE "state"
#define SND_ATT_SOUND_STATE_PLIB "plib"
#define SND_ATT_SOUND_STATE_OPENAL "openal"
#define SND_ATT_SOUND_STATE_DISABLED "disabled"
#define SND_ATT_SOUND_VOLUME "volume"
#define MM_SCT_SOUND "Menu Music"
#define MM_ATT_SOUND_ENABLE "enable"
#define MM_VAL_SOUND_ENABLED "enabled"
#define MM_VAL_SOUND_DISABLED "disabled"
#endif /* _SOUND_H_ */

View File

@ -19,10 +19,10 @@
#include "musicplayer.h"
//#include <GL/glut.h>
#include <string.h>
#include <cstring>
#include <tgf.h>
#include "tgfclient.h"
#include <sound.h>
#include <portability.h>
#if MENU_MUSIC
@ -41,7 +41,7 @@ static void playMenuMusic(int /* value */);
#if 0
const int BUFSIZE = 1024;
char buf[BUFSIZE];
snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), MM_SOUND_PARM_CFG);
snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), SND_PARAM_FILE);
bool enabled = false;
void *handle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);

View File

@ -20,12 +20,6 @@
* *
***************************************************************************/
#define MM_SOUND_PARM_CFG "config/sound.xml"
#define MM_SCT_SOUND "Menu Music"
#define MM_ATT_SOUND_ENABLE "enable"
#define MM_VAL_SOUND_ENABLED "enabled"
#define MM_VAL_SOUND_DISABLED "disabled"
// DLL exported symbols declarator for Windows.
#ifdef WIN32
# ifdef TGFCLIENT_DLL
@ -42,4 +36,4 @@ TGFCLIENT_API void stopMenuMusic();
TGFCLIENT_API void pauseMenuMusic();
TGFCLIENT_API void resumeMenuMusic(int sourceId);
#endif //__musicplayer_h__
#endif //__musicplayer_h__

View File

@ -36,7 +36,6 @@
//#include "grskidmarks.h"
//#include "grsmoke.h"
//#include "grscreen.h"
//#include "grsound.h"
//#include "grloadac.h"
//#include "grutil.h"
//#include "grcarlight.h"
@ -622,10 +621,6 @@ refresh(tSituation *s)
TRACE_GL("refresh: start");
GfProfStartProfile("grRefreshSound*");
grRefreshSound(s, grGetCurrentScreen()->getCurCamera());
GfProfStopProfile("grRefreshSound*");
// Moved car collision damage propagation from grcar::grDrawCar.
// Because it has to be done only once per graphics update, whereas grDrawCar
// is called once for each car and for each screen.
@ -758,7 +753,6 @@ initCars(tSituation *s)
// Initialize other stuff.
/*grInitSmoke(s->_ncars);
grInitSound(s, s->_ncars);
grTrackLightInit();
// Setup the screens (= OpenGL viewports) inside the physical game window.
@ -773,7 +767,6 @@ shutdownCars(void)
/* int i;
GfOut("-- shutdownCars\n");
grShutdownSound(grNbCars);
if (grNbCars) {
grShutdownBoardCar();
grShutdownSkidmarks();

View File

@ -20,7 +20,6 @@
#include "osggraph.h"
#include "OsgMain.h"
//#include "grsound.h"
//#include "grtexture.h"
@ -129,10 +128,9 @@ void OsgGraph::shutdownView()
//::shutdownView();
}
// Implementation of ISoundEngine ****************************************
SoundCam * OsgGraph::getCurCam()
Camera* OsgGraph::getCurCam()
{
/*SoundCam *cam = new SoundCam;
Camera *cam = 0; /*new Camera;
osgCamera *gcam = osgGetCurCamera();
cam->Centerv = gcam->getCenterv();
@ -140,5 +138,5 @@ SoundCam * OsgGraph::getCurCam()
cam->Speedv = gcam->getSpeedv();
cam->Posv = gcam->getPosv();*/
return 0; //return cam;
return cam;
}

View File

@ -25,7 +25,6 @@
#define _OSGGRAPH_H_
#include <igraphicsengine.h>
#include <isoundengine.h>
#include <tgf.hpp>
@ -49,7 +48,7 @@ extern "C" int OSGGRAPH_API openGfModule(const char* pszShLibName, void* hShLibH
extern "C" int OSGGRAPH_API closeGfModule();
// The module main class
// (Singleton, inherits GfModule, and implements IGraphicsEngine and ISoundEngine).
// (Singleton, inherits GfModule, and implements IGraphicsEngine).
class OSGGRAPH_API OsgGraph : public GfModule, public IGraphicsEngine
{
public:
@ -63,7 +62,7 @@ class OSGGRAPH_API OsgGraph : public GfModule, public IGraphicsEngine
virtual void shutdownView();
virtual void unloadCars();
virtual void unloadTrack();
virtual SoundCam *getCurCam();
virtual Camera *getCurCam();
// Accessor to the singleton.
static OsgGraph& self();

View File

@ -28,7 +28,8 @@
// The SsgGraph: singleton.
SsgGraph* SsgGraph::_pSelf = 0;
int openGfModule(const char* pszShLibName, void* hShLibHandle) {
int openGfModule(const char* pszShLibName, void* hShLibHandle)
{
// Instanciate the (only) module instance.
SsgGraph::_pSelf = new SsgGraph(pszShLibName, hShLibHandle);
@ -40,7 +41,8 @@ int openGfModule(const char* pszShLibName, void* hShLibHandle) {
return SsgGraph::_pSelf ? 0 : 1;
}
int closeGfModule() {
int closeGfModule()
{
// Unregister it from the GfModule module manager.
if (SsgGraph::_pSelf)
GfModule::unregister(SsgGraph::_pSelf);
@ -53,13 +55,15 @@ int closeGfModule() {
return 0;
}
SsgGraph& SsgGraph::self() {
SsgGraph& SsgGraph::self()
{
// Pre-condition : 1 successfull openGfModule call.
return *_pSelf;
}
SsgGraph::SsgGraph(const std::string& strShLibName, void* hShLibHandle)
: GfModule(strShLibName, hShLibHandle) {
: GfModule(strShLibName, hShLibHandle)
{
// Override the default SSG loader options object with our's
// (workaround try for ssggraph crash at re-load time).
_pDefaultSSGLoaderOptions = new ssgLoaderOptions;
@ -72,29 +76,34 @@ SsgGraph::SsgGraph(const std::string& strShLibName, void* hShLibHandle)
grRegisterCustomSGILoader();
}
SsgGraph::~SsgGraph() {
SsgGraph::~SsgGraph()
{
// Terminate the PLib SSG layer.
delete _pDefaultSSGLoaderOptions;
}
// Implementation of IGraphicsEngine ****************************************
bool SsgGraph::loadTrack(tTrack* pTrack) {
bool SsgGraph::loadTrack(tTrack* pTrack)
{
//GfLogDebug("SsgGraph::loadTrack\n");
return ::initTrack(pTrack) == 0;
}
bool SsgGraph::loadCars(tSituation* pSituation) {
bool SsgGraph::loadCars(tSituation* pSituation)
{
//GfLogDebug("SsgGraph::loadCars\n");
return ::initCars(pSituation) == 0;
}
bool SsgGraph::setupView(int x, int y, int width, int height, void* pMenuScreen) {
bool SsgGraph::setupView(int x, int y, int width, int height, void* pMenuScreen)
{
//GfLogDebug("SsgGraph::setupView\n");
return ::initView(x, y, width, height, GR_VIEW_STD, pMenuScreen) == 0;
}
void SsgGraph::redrawView(tSituation* pSituation) {
void SsgGraph::redrawView(tSituation* pSituation)
{
::refresh(pSituation);
}
@ -103,32 +112,34 @@ void SsgGraph::redrawView(tSituation* pSituation) {
// ::bendCar(index, poc, force, count);
// }
void SsgGraph::unloadCars() {
void SsgGraph::unloadCars()
{
//GfLogDebug("SsgGraph::unloadCars\n");
::shutdownCars();
}
void SsgGraph::unloadTrack() {
void SsgGraph::unloadTrack()
{
//GfLogDebug("SsgGraph::unloadTrack\n");
::shutdownTrack();
}
void SsgGraph::shutdownView() {
void SsgGraph::shutdownView()
{
//GfLogDebug("SsgGraph::shutdownView\n");
::shutdownView();
}
SoundCam * SsgGraph::getCurCam() {
SoundCam *cam = new SoundCam;
Camera* SsgGraph::getCurCam()
{
Camera *cam = new Camera;
cGrCamera *gcam = grGetCurCamera();
cam->Centerv = gcam->getCenterv();
cam->Upv = gcam->getUpv();
cam->Speedv = gcam->getSpeedv();
cam->Posv = gcam->getPosv();
return cam;
}

View File

@ -62,7 +62,7 @@ class SSGGRAPH_API SsgGraph : public GfModule, public IGraphicsEngine
virtual void shutdownView();
virtual void unloadCars();
virtual void unloadTrack();
virtual SoundCam *getCurCam();
virtual Camera* getCurCam();

View File

@ -19,10 +19,11 @@
#include "grsound.h"
#include <sound.h>
#include "OpenalSoundInterface.h"
#include "PlibSoundInterface.h"
#include "CarSoundData.h"
#include <graphic.h>
static int soundInitialized = 0;
@ -33,9 +34,9 @@ enum SoundMode {DISABLED, OPENAL_MODE, PLIB_MODE};
static enum SoundMode sound_mode = OPENAL_MODE;
static const char *soundDisabledStr = GR_ATT_SOUND_STATE_DISABLED;
static const char *soundOpenALStr = GR_ATT_SOUND_STATE_OPENAL;
static const char *soundPlibStr = GR_ATT_SOUND_STATE_PLIB;
static const char *soundDisabledStr = SND_ATT_SOUND_STATE_DISABLED;
static const char *soundOpenALStr = SND_ATT_SOUND_STATE_OPENAL;
static const char *soundPlibStr = SND_ATT_SOUND_STATE_PLIB;
void grInitSound(tSituation* s, int ncars)
{
@ -43,10 +44,10 @@ void grInitSound(tSituation* s, int ncars)
// Check if we want sound (sound.xml).
char fnbuf[1024];
sprintf(fnbuf, "%s%s", GfLocalDir(), GR_SOUND_PARM_CFG);
sprintf(fnbuf, "%s%s", GfLocalDir(), SND_PARAM_FILE);
void *paramHandle = GfParmReadFile(fnbuf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
const char *optionName = GfParmGetStr(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_STATE, soundOpenALStr);
float global_volume = GfParmGetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", 100.0f);
const char *optionName = GfParmGetStr(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_STATE, soundOpenALStr);
float global_volume = GfParmGetNum(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_VOLUME, "%", 100.0f);
if (!strcmp(optionName, soundDisabledStr)) {
sound_mode = DISABLED;
} else if (!strcmp(optionName, soundOpenALStr)) {
@ -178,7 +179,7 @@ grShutdownSound()
void
grRefreshSound(tSituation *s, SoundCam *camera)
grRefreshSound(tSituation *s, Camera* camera)
{
if (sound_mode == DISABLED) {
return;
@ -210,7 +211,6 @@ grRefreshSound(tSituation *s, SoundCam *camera)
sound_interface->update (car_sound_data, s->_ncars,
*p_camera, *u_camera, c_camera, *a_camera);
free(camera); //ssggraph use the variables pointed by camera, we do not want do free them.
}
}

View File

@ -21,13 +21,12 @@
#ifndef _GRSOUND_H_
#define _GRSOUND_H_
#include<isoundengine.h>
#include <isoundengine.h>
#include <raceman.h> //tSituation
class cGrCamera; //Declared in ""grcam.h"
extern void grInitSound(tSituation* s, int ncars);
extern void grShutdownSound();
extern void grRefreshSound(tSituation *s, SoundCam *camera);
extern void grRefreshSound(tSituation *s, Camera *camera);
extern void grMuteSound(bool bOn = true);
#endif /* _GRSOUND_H_ */

View File

@ -1,6 +1,6 @@
/***************************************************************************
file : ssggraph.cpp
file : snddefault.cpp
created : Thu Aug 17 23:19:19 CEST 2000
copyright : (C) 2000 by Eric Espie
email : torcs@free.fr
@ -20,48 +20,48 @@
#include "snddefault.h"
#include "grsound.h"
// The SsgGraph: singleton.
sndDefault* sndDefault::_pSelf = 0;
// The SndDefault singleton.
SndDefault* SndDefault::_pSelf = 0;
int openGfModule(const char* pszShLibName, void* hShLibHandle)
{
// Instanciate the (only) module instance.
sndDefault::_pSelf = new sndDefault(pszShLibName, hShLibHandle);
SndDefault::_pSelf = new SndDefault(pszShLibName, hShLibHandle);
// Register it to the GfModule module manager if OK.
if (sndDefault::_pSelf)
GfModule::register_(sndDefault::_pSelf);
if (SndDefault::_pSelf)
GfModule::register_(SndDefault::_pSelf);
// Report about success or error.
return sndDefault::_pSelf ? 0 : 1;
return SndDefault::_pSelf ? 0 : 1;
}
int closeGfModule()
{
// Unregister it from the GfModule module manager.
if (sndDefault::_pSelf)
GfModule::unregister(sndDefault::_pSelf);
if (SndDefault::_pSelf)
GfModule::unregister(SndDefault::_pSelf);
// Delete the (only) module instance.
delete sndDefault::_pSelf;
sndDefault::_pSelf = 0;
delete SndDefault::_pSelf;
SndDefault::_pSelf = 0;
// Report about success or error.
return 0;
}
sndDefault& sndDefault::self()
SndDefault& SndDefault::self()
{
// Pre-condition : 1 successfull openGfModule call.
return *_pSelf;
}
sndDefault::sndDefault(const std::string& strShLibName, void* hShLibHandle)
SndDefault::SndDefault(const std::string& strShLibName, void* hShLibHandle)
: GfModule(strShLibName, hShLibHandle)
{
}
sndDefault::~sndDefault()
SndDefault::~SndDefault()
{
// Terminate the PLib SSG layer.
//delete _pDefaultSSGLoaderOptions;
@ -69,17 +69,17 @@ sndDefault::~sndDefault()
// Implementation of ISoundEngine ****************************************
void sndDefault::init(Situation* s){
void SndDefault::init(Situation* s){
grInitSound(s,s->_ncars);
}
void sndDefault::shutdown(){
void SndDefault::shutdown(){
grShutdownSound();
}
void sndDefault::refresh(Situation *s, SoundCam *camera){
void SndDefault::refresh(Situation *s, Camera *camera){
grRefreshSound(s, camera);
}
void sndDefault::mute(bool bOn)
void SndDefault::mute(bool bOn)
{
::grMuteSound(bOn);
}

View File

@ -1,6 +1,6 @@
/***************************************************************************
file : ssggraph.h
file : snddefault.h
copyright : (C) 2011 by Jean-Philippe Meuret
email : pouillot@users.sourceforge.net
version : $Id$
@ -17,20 +17,17 @@
***************************************************************************/
/** @file
The "ssggraph" graphics engine module
The "snddefault" sound engine module
@version $Id$
*/
#ifndef _SNDDEFAULT_H_
#define _SNDDEFAULT_H_
#include <igraphicsengine.h>
#include <isoundengine.h>
#include <tgf.hpp>
class ssgLoaderOptions;
// DLL exported symbols declarator for Windows.
#ifdef WIN32
@ -50,25 +47,25 @@ extern "C" int SNDDEFAULT_API closeGfModule();
// The module main class
// (Singleton, inherits GfModule, and implements IGraphicsEngine and ISoundEngine).
class SNDDEFAULT_API sndDefault : public GfModule, public ISoundEngine
class SNDDEFAULT_API SndDefault : public GfModule, public ISoundEngine
{
public:
virtual void init(Situation* s);
virtual void shutdown();
virtual void refresh(Situation *s, SoundCam*camera);
virtual void refresh(Situation* s, Camera* camera);
virtual void mute(bool bOn = true);
// Accessor to the singleton.
static sndDefault& self();
static SndDefault& self();
// Destructor.
virtual ~sndDefault();
virtual ~SndDefault();
protected:
// Protected constructor to avoid instanciation outside (but friends).
sndDefault(const std::string& strShLibName, void* hShLibHandle);
SndDefault(const std::string& strShLibName, void* hShLibHandle);
// Make the C interface functions nearly member functions.
friend int openGfModule(const char* pszShLibName, void* hShLibHandle);
@ -77,10 +74,7 @@ class SNDDEFAULT_API sndDefault : public GfModule, public ISoundEngine
protected:
// The singleton.
static sndDefault* _pSelf;
// The default SSGLoaderOptions instance.
//ssgLoaderOptions* _pDefaultSSGLoaderOptions;
static SndDefault* _pSelf;
};
#endif /* _SNDDEFAULT_H_ */

View File

@ -27,16 +27,15 @@
#include <cstring>
#include <tgfclient.h>
#include <graphic.h>
#include <sound.h>
#include "soundconfig.h"
#include "gui.h"
// list of options.
static const char *soundOptionList[] = {GR_ATT_SOUND_STATE_OPENAL,
GR_ATT_SOUND_STATE_PLIB,
GR_ATT_SOUND_STATE_DISABLED};
static const char *soundOptionList[] = {SND_ATT_SOUND_STATE_OPENAL,
SND_ATT_SOUND_STATE_PLIB,
SND_ATT_SOUND_STATE_DISABLED};
static const int nbOptions = sizeof(soundOptionList) / sizeof(soundOptionList[0]);
static int curOption = 0;
@ -60,9 +59,9 @@ static void readSoundCfg(void)
char buf[1024];
// Sound interface.
sprintf(buf, "%s%s", GfLocalDir(), GR_SOUND_PARM_CFG);
sprintf(buf, "%s%s", GfLocalDir(), SND_PARAM_FILE);
void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
optionName = GfParmGetStr(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_STATE, soundOptionList[0]);
optionName = GfParmGetStr(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_STATE, soundOptionList[0]);
for (i = 0; i < nbOptions; i++) {
if (strcmp(optionName, soundOptionList[i]) == 0) {
@ -74,7 +73,7 @@ static void readSoundCfg(void)
GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]);
// Sound volume.
VolumeValue = GfParmGetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", 100.0f);
VolumeValue = GfParmGetNum(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_VOLUME, "%", 100.0f);
if (VolumeValue>100.0f) {
VolumeValue = 100.0f;
}
@ -96,16 +95,15 @@ static void saveSoundOption(void *)
GfuiUnSelectCurrent();
char buf[1024];
sprintf(buf, "%s%s", GfLocalDir(), GR_SOUND_PARM_CFG);
sprintf(buf, "%s%s", GfLocalDir(), SND_PARAM_FILE);
void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
GfParmSetStr(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_STATE, soundOptionList[curOption]);
GfParmSetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", VolumeValue);
GfParmSetStr(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_STATE, soundOptionList[curOption]);
GfParmSetNum(paramHandle, SND_SCT_SOUND, SND_ATT_SOUND_VOLUME, "%", VolumeValue);
GfParmWriteFile(NULL, paramHandle, "sound");
GfParmReleaseHandle(paramHandle);
// Return to previous screen.
GfuiScreenActivate(prevHandle);
return;
}
@ -114,7 +112,7 @@ static void changeSoundState(void *vp)
{
curOption = (curOption + (int)(long)vp + nbOptions) % nbOptions;
GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]);
GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]);
}
// Volume

View File

@ -44,7 +44,8 @@
// The LegacyMenu singleton.
LegacyMenu* LegacyMenu::_pSelf = 0;
int openGfModule(const char* pszShLibName, void* hShLibHandle) {
int openGfModule(const char* pszShLibName, void* hShLibHandle)
{
// Instanciate the (only) module instance.
LegacyMenu::_pSelf = new LegacyMenu(pszShLibName, hShLibHandle);
@ -56,7 +57,8 @@ int openGfModule(const char* pszShLibName, void* hShLibHandle) {
return LegacyMenu::_pSelf ? 0 : 1;
}
int closeGfModule() {
int closeGfModule()
{
// Unregister it from the GfModule module manager.
if (LegacyMenu::_pSelf)
GfModule::unregister(LegacyMenu::_pSelf);
@ -69,7 +71,8 @@ int closeGfModule() {
return 0;
}
LegacyMenu& LegacyMenu::self() {
LegacyMenu& LegacyMenu::self()
{
// Pre-condition : 1 successfull openGfModule call.
return *_pSelf;
}
@ -79,7 +82,8 @@ LegacyMenu::LegacyMenu(const std::string& strShLibName, void* hShLibHandle)
_hscrReUpdateStateHook(0), _hscrGame(0), _bfGraphicsState(0) {
}
bool LegacyMenu::backLoad() {
bool LegacyMenu::backLoad()
{
GfLogTrace("Pre-loading menu and game data ...\n");
// Pre-load the main and race select menus
@ -96,11 +100,13 @@ bool LegacyMenu::backLoad() {
return true;
}
bool LegacyMenu::activateMainMenu() {
bool LegacyMenu::activateMainMenu()
{
return MainMenuRun() == 0;
}
bool LegacyMenu::startRace() {
bool LegacyMenu::startRace()
{
// Get the race to start.
std::string strRaceToStart;
if (!GfApp().hasOption("startrace", strRaceToStart))
@ -132,7 +138,8 @@ bool LegacyMenu::startRace() {
// Implementation of IUserInterface ****************************************
bool LegacyMenu::activate() {
bool LegacyMenu::activate()
{
bool (*fnSplashBackWork)(void) = LegacyMenu::backLoad;
bool (*fnOnSplashClosed)(void) = 0;
bool bInteractive = true;
@ -155,12 +162,14 @@ bool LegacyMenu::activate() {
return SplashScreen(fnSplashBackWork, fnOnSplashClosed, bInteractive);
}
void LegacyMenu::quit() {
void LegacyMenu::quit()
{
// Quit the event loop next time.
GfuiApp().eventLoop().postQuit();
}
void LegacyMenu::shutdown() {
void LegacyMenu::shutdown()
{
// Shutdown graphics in case relevant and not already done.
if (_piRaceEngine->inData()->_displayMode == RM_DISP_MODE_NORMAL) {
shutdownSound();
@ -176,7 +185,8 @@ void LegacyMenu::shutdown() {
::RmShutdownReUpdateStateHook();
}
void LegacyMenu::activateLoadingScreen() {
void LegacyMenu::activateLoadingScreen()
{
tRmInfo* pReInfo = _piRaceEngine->inData();
char pszTitle[128];
@ -189,23 +199,28 @@ void LegacyMenu::activateLoadingScreen() {
::RmLoadingScreenStart(pszTitle, "data/img/splash-raceload.jpg");
}
void LegacyMenu::addLoadingMessage(const char* pszText) {
void LegacyMenu::addLoadingMessage(const char* pszText)
{
::RmLoadingScreenSetText(pszText);
}
void LegacyMenu::shutdownLoadingScreen() {
void LegacyMenu::shutdownLoadingScreen()
{
::RmLoadingScreenShutdown();
}
void LegacyMenu::onRaceConfiguring() {
void LegacyMenu::onRaceConfiguring()
{
::RmRacemanMenu();
}
void LegacyMenu::onRaceEventInitializing() {
void LegacyMenu::onRaceEventInitializing()
{
activateLoadingScreen();
}
bool LegacyMenu::onRaceEventStarting(bool careerNonHumanGroup) {
bool LegacyMenu::onRaceEventStarting(bool careerNonHumanGroup)
{
tRmInfo* pReInfo = _piRaceEngine->inData();
if (GfParmGetEltNb(pReInfo->params, RM_SECT_TRACKS) > 1) {
if (!careerNonHumanGroup) {
@ -223,7 +238,8 @@ bool LegacyMenu::onRaceEventStarting(bool careerNonHumanGroup) {
return true; // Tell the race engine state automaton to go on looping.
}
void LegacyMenu::onRaceInitializing() {
void LegacyMenu::onRaceInitializing()
{
// Activate the loading screen at the start of sessions,
// that is at race session and timed practice or qualifying sessions,
// and for the first car in non-timed practice or qualifying sessions.
@ -240,7 +256,8 @@ void LegacyMenu::onRaceInitializing() {
}
}
bool LegacyMenu::onRaceStarting() {
bool LegacyMenu::onRaceStarting()
{
// Switch to Start Race menu only if required (no loading screen in this case).
tRmInfo* pReInfo = _piRaceEngine->inData();
const bool bNeedStartMenu =
@ -258,7 +275,8 @@ bool LegacyMenu::onRaceStarting() {
return bNeedStartMenu ? false : true;
}
void LegacyMenu::onRaceLoadingDrivers() {
void LegacyMenu::onRaceLoadingDrivers()
{
// Create the game screen according to the actual display mode.
if (_piRaceEngine->inData()->_displayMode == RM_DISP_MODE_NORMAL)
_hscrGame = ::RmScreenInit();
@ -274,7 +292,8 @@ void LegacyMenu::onRaceLoadingDrivers() {
}
}
void LegacyMenu::onRaceDriversLoaded() {
void LegacyMenu::onRaceDriversLoaded()
{
if (_piRaceEngine->inData()->_displayMode == RM_DISP_MODE_NORMAL) {
// It must be done after the cars are loaded and the track is loaded.
// The track will be unloaded if the event ends.
@ -293,7 +312,8 @@ void LegacyMenu::onRaceDriversLoaded() {
}
}
void LegacyMenu::onRaceSimulationReady() {
void LegacyMenu::onRaceSimulationReady()
{
if (_piRaceEngine->inData()->_displayMode == RM_DISP_MODE_NORMAL) {
// Initialize the graphics view.
setupGraphicsView();
@ -308,7 +328,8 @@ void LegacyMenu::onRaceSimulationReady() {
}
}
void LegacyMenu::onRaceStarted() {
void LegacyMenu::onRaceStarted()
{
// Shutdown the loading screen if not already done.
shutdownLoadingScreen();
@ -316,12 +337,15 @@ void LegacyMenu::onRaceStarted() {
GfuiScreenActivate(_hscrGame);
}
void LegacyMenu::onRaceResuming() {
void LegacyMenu::onRaceResuming()
{
// Start the standings menu.
showStandings();
}
void LegacyMenu::onLapCompleted(int nLapIndex) {
void LegacyMenu::onLapCompleted(int nLapIndex)
{
if (nLapIndex <= 0)
return;
@ -332,7 +356,8 @@ void LegacyMenu::onRaceInterrupted() {
::RmStopRaceMenu();
}
void LegacyMenu::onRaceFinishing() {
void LegacyMenu::onRaceFinishing()
{
if (_piRaceEngine->inData()->_displayMode == RM_DISP_MODE_NORMAL) {
shutdownSound();
resumeMenuMusic(1);
@ -345,7 +370,8 @@ void LegacyMenu::onRaceFinishing() {
}
}
bool LegacyMenu::onRaceFinished(bool bEndOfSession) {
bool LegacyMenu::onRaceFinished(bool bEndOfSession)
{
tRmInfo* pReInfo = _piRaceEngine->inData();
// Display the results of the session for all the competitors
@ -373,7 +399,8 @@ bool LegacyMenu::onRaceFinished(bool bEndOfSession) {
return true;
}
void LegacyMenu::onRaceEventFinishing() {
void LegacyMenu::onRaceEventFinishing()
{
if (_piRaceEngine->inData()->_displayMode == RM_DISP_MODE_NORMAL) {
unloadTrackGraphics();
@ -381,7 +408,8 @@ void LegacyMenu::onRaceEventFinishing() {
}
}
void LegacyMenu::showStandings() {
void LegacyMenu::showStandings()
{
// Create the "Race Engine update state" hook if not already done.
if (!_hscrReUpdateStateHook)
_hscrReUpdateStateHook = ::RmInitReUpdateStateHook();
@ -393,7 +421,8 @@ void LegacyMenu::showStandings() {
::RmShowStandings(_hscrGame, _piRaceEngine->inData(), 0);
}
bool LegacyMenu::onRaceEventFinished(bool bMultiEvent, bool careerNonHumanGroup) {
bool LegacyMenu::onRaceEventFinished(bool bMultiEvent, bool careerNonHumanGroup)
{
// Only display the standings if both:
// * there are multiple races for this championship
// * the results are relevant for the user (do not display in Career mode in non-human groups)
@ -412,41 +441,50 @@ bool LegacyMenu::onRaceEventFinished(bool bMultiEvent, bool careerNonHumanGroup)
return true;
}
void LegacyMenu::setResultsTableTitles(const char* pszTitle, const char* pszSubTitle) {
void LegacyMenu::setResultsTableTitles(const char* pszTitle, const char* pszSubTitle)
{
::RmResScreenSetTitles(pszTitle, pszSubTitle);
}
void LegacyMenu::setResultsTableHeader(const char* pszHeader) {
void LegacyMenu::setResultsTableHeader(const char* pszHeader)
{
::RmResScreenSetHeader(pszHeader);
}
void LegacyMenu::addResultsTableRow(const char* pszText) {
void LegacyMenu::addResultsTableRow(const char* pszText)
{
::RmResScreenAddText(pszText);
}
void LegacyMenu::setResultsTableRow(int nIndex, const char* pszText, bool bHighlight) {
void LegacyMenu::setResultsTableRow(int nIndex, const char* pszText, bool bHighlight)
{
::RmResScreenSetText(pszText, nIndex, bHighlight ? 1 : 0);
}
void LegacyMenu::removeResultsTableRow(int nIndex) {
void LegacyMenu::removeResultsTableRow(int nIndex)
{
::RmResScreenRemoveText(nIndex);
}
int LegacyMenu::getResultsTableRowCount() const {
int LegacyMenu::getResultsTableRowCount() const
{
return ::RmResGetRows();
}
void LegacyMenu::eraseResultsTable() {
void LegacyMenu::eraseResultsTable()
{
::RmResEraseScreen();
}
void LegacyMenu::activateGameScreen() {
void LegacyMenu::activateGameScreen()
{
GfuiScreenActivate(_hscrGame);
}
// Graphics&Sound engine control =====================================================
bool LegacyMenu::initializeGraphics() {
bool LegacyMenu::initializeGraphics()
{
// Check if the module is already loaded, and do nothing more if so.
if (_piGraphicsEngine)
return true;
@ -471,7 +509,8 @@ bool LegacyMenu::initializeGraphics() {
return _piGraphicsEngine != 0;
}
bool LegacyMenu::initializeSound(){
bool LegacyMenu::initializeSound()
{
// Check if the module is already loaded, and do nothing more if so.
if (_piSoundEngine)
return true;
@ -494,7 +533,8 @@ bool LegacyMenu::initializeSound(){
return _piSoundEngine != 0;
}
bool LegacyMenu::loadTrackGraphics(struct Track* pTrack) {
bool LegacyMenu::loadTrackGraphics(struct Track* pTrack)
{
if (!_piGraphicsEngine)
return false;
@ -503,7 +543,8 @@ bool LegacyMenu::loadTrackGraphics(struct Track* pTrack) {
return _piGraphicsEngine->loadTrack(pTrack);
}
bool LegacyMenu::loadCarsGraphics(struct Situation* pSituation) {
bool LegacyMenu::loadCarsGraphics(struct Situation* pSituation)
{
if (!_piGraphicsEngine)
return false;
@ -514,7 +555,8 @@ bool LegacyMenu::loadCarsGraphics(struct Situation* pSituation) {
return _piGraphicsEngine ? _piGraphicsEngine->loadCars(pSituation) : false;
}
bool LegacyMenu::setupGraphicsView() {
bool LegacyMenu::setupGraphicsView()
{
// Initialize the graphics view.
if (!_piGraphicsEngine)
return false;
@ -529,45 +571,57 @@ bool LegacyMenu::setupGraphicsView() {
return _piGraphicsEngine->setupView((sw - vw) / 2, (sh - vh) / 2, vw, vh, _hscrGame);
}
void LegacyMenu::redrawGraphicsView(struct Situation* pSituation) {
void LegacyMenu::redrawGraphicsView(struct Situation* pSituation)
{
if (!_piGraphicsEngine)
return;
// Update graphics view.
_piGraphicsEngine->redrawView(pSituation);
_piSoundEngine->refresh(pSituation,_piGraphicsEngine->getCurCam());
// Update sound "view".
Camera* pCam = _piGraphicsEngine->getCurCam();
_piSoundEngine->refresh(pSituation, pCam);
delete pCam;
}
void LegacyMenu::shutdownSound() {
void LegacyMenu::shutdownSound()
{
if (!_piSoundEngine)
return;
if (_bfGraphicsState & eCarsLoaded) {
if (_bfGraphicsState & eCarsLoaded)
{
_piSoundEngine->shutdown();
}
}
void LegacyMenu::unloadCarsGraphics() {
void LegacyMenu::unloadCarsGraphics()
{
if (!_piGraphicsEngine)
return;
if (_bfGraphicsState & eCarsLoaded) {
if (_bfGraphicsState & eCarsLoaded)
{
_piGraphicsEngine->unloadCars();
_bfGraphicsState &= ~eCarsLoaded;
}
}
void LegacyMenu::unloadTrackGraphics() {
void LegacyMenu::unloadTrackGraphics()
{
if (!_piGraphicsEngine)
return;
if (_bfGraphicsState & eTrackLoaded) {
if (_bfGraphicsState & eTrackLoaded)
{
_piGraphicsEngine->unloadTrack();
_bfGraphicsState &= ~eTrackLoaded;
}
}
void LegacyMenu::shutdownGraphicsView() {
void LegacyMenu::shutdownGraphicsView()
{
if (!_piGraphicsEngine)
return;
@ -577,7 +631,8 @@ void LegacyMenu::shutdownGraphicsView() {
}
}
void LegacyMenu::shutdownGraphics(bool bUnloadModule) {
void LegacyMenu::shutdownGraphics(bool bUnloadModule)
{
// Do nothing if the module has already been unloaded.
if (!_piGraphicsEngine)
return;
@ -602,24 +657,28 @@ void LegacyMenu::shutdownGraphics(bool bUnloadModule) {
//=========================================================================
void LegacyMenu::setRaceEngine(IRaceEngine& raceEngine) {
void LegacyMenu::setRaceEngine(IRaceEngine& raceEngine)
{
_piRaceEngine = &raceEngine;
}
// Accessor to the race engine.
IRaceEngine& LegacyMenu::raceEngine() {
IRaceEngine& LegacyMenu::raceEngine()
{
return *_piRaceEngine;
}
// Accessor to the graphics engine.
IGraphicsEngine* LegacyMenu::graphicsEngine() {
IGraphicsEngine* LegacyMenu::graphicsEngine()
{
return _piGraphicsEngine;
}
// Accessor to the sound engine.
ISoundEngine* LegacyMenu::soundEngine() {
ISoundEngine* LegacyMenu::soundEngine()
{
return _piSoundEngine;
}