- better handling of sound system reset when clicking ok in options menu
This commit is contained in:
parent
5af6de5aec
commit
0f915ae6a6
|
@ -41,6 +41,7 @@ namespace Glest{ namespace Game{
|
||||||
|
|
||||||
const int Program::maxTimes= 10;
|
const int Program::maxTimes= 10;
|
||||||
Program *Program::singleton = NULL;
|
Program *Program::singleton = NULL;
|
||||||
|
const int SOUND_THREAD_UPDATE_MILLISECONDS = 25;
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Program::CrashProgramState
|
// class Program::CrashProgramState
|
||||||
|
@ -178,9 +179,11 @@ Program::~Program(){
|
||||||
restoreDisplaySettings();
|
restoreDisplaySettings();
|
||||||
singleton = NULL;
|
singleton = NULL;
|
||||||
|
|
||||||
BaseThread::shutdownAndWait(soundThreadManager);
|
if(soundThreadManager != NULL) {
|
||||||
delete soundThreadManager;
|
BaseThread::shutdownAndWait(soundThreadManager);
|
||||||
soundThreadManager = NULL;
|
delete soundThreadManager;
|
||||||
|
soundThreadManager = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::keyDown(char key){
|
void Program::keyDown(char key){
|
||||||
|
@ -556,7 +559,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
|
||||||
if(BaseThread::shutdownAndWait(soundThreadManager) == true) {
|
if(BaseThread::shutdownAndWait(soundThreadManager) == true) {
|
||||||
delete soundThreadManager;
|
delete soundThreadManager;
|
||||||
}
|
}
|
||||||
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,10);
|
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,SOUND_THREAD_UPDATE_MILLISECONDS);
|
||||||
soundThreadManager->setUniqueID(__FILE__);
|
soundThreadManager->setUniqueID(__FILE__);
|
||||||
soundThreadManager->start();
|
soundThreadManager->start();
|
||||||
}
|
}
|
||||||
|
@ -668,6 +671,27 @@ void Program::showMessage(const char *msg) {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Program::stopSoundSystem() {
|
||||||
|
if(soundThreadManager != NULL) {
|
||||||
|
BaseThread::shutdownAndWait(soundThreadManager);
|
||||||
|
delete soundThreadManager;
|
||||||
|
soundThreadManager = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Program::startSoundSystem() {
|
||||||
|
stopSoundSystem();
|
||||||
|
if(SoundRenderer::getInstance().runningThreaded() == true) {
|
||||||
|
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,SOUND_THREAD_UPDATE_MILLISECONDS);
|
||||||
|
soundThreadManager->setUniqueID(__FILE__);
|
||||||
|
soundThreadManager->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Program::resetSoundSystem() {
|
||||||
|
startSoundSystem();
|
||||||
|
}
|
||||||
|
|
||||||
void Program::reInitGl() {
|
void Program::reInitGl() {
|
||||||
if(window != NULL) {
|
if(window != NULL) {
|
||||||
Config &config= Config::getInstance();
|
Config &config= Config::getInstance();
|
||||||
|
|
|
@ -168,6 +168,9 @@ public:
|
||||||
bool isInSpecialKeyCaptureEvent() { return programState->isInSpecialKeyCaptureEvent(); }
|
bool isInSpecialKeyCaptureEvent() { return programState->isInSpecialKeyCaptureEvent(); }
|
||||||
|
|
||||||
void reInitGl();
|
void reInitGl();
|
||||||
|
void resetSoundSystem();
|
||||||
|
void stopSoundSystem();
|
||||||
|
void startSoundSystem();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -790,9 +790,12 @@ void MenuStateOptions::saveConfig(){
|
||||||
|
|
||||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
soundRenderer.stopAllSounds();
|
soundRenderer.stopAllSounds();
|
||||||
|
program->stopSoundSystem();
|
||||||
bool initOk = soundRenderer.init(program->getWindow());
|
bool initOk = soundRenderer.init(program->getWindow());
|
||||||
soundRenderer.loadConfig();
|
soundRenderer.loadConfig();
|
||||||
soundRenderer.setMusicVolume(CoreData::getInstance().getMenuMusic());
|
soundRenderer.setMusicVolume(CoreData::getInstance().getMenuMusic());
|
||||||
|
program->startSoundSystem();
|
||||||
|
|
||||||
soundRenderer.playMusic(CoreData::getInstance().getMenuMusic());
|
soundRenderer.playMusic(CoreData::getInstance().getMenuMusic());
|
||||||
|
|
||||||
Renderer::getInstance().loadConfig();
|
Renderer::getInstance().loadConfig();
|
||||||
|
|
|
@ -53,6 +53,7 @@ bool SoundRenderer::init(Window *window) {
|
||||||
Config &config= Config::getInstance();
|
Config &config= Config::getInstance();
|
||||||
si.setFactory(fr.getSoundFactory(config.getString("FactorySound")));
|
si.setFactory(fr.getSoundFactory(config.getString("FactorySound")));
|
||||||
|
|
||||||
|
cleanup();
|
||||||
stopAllSounds();
|
stopAllSounds();
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(NULL,string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutex(NULL,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
@ -74,6 +75,23 @@ bool SoundRenderer::init(Window *window) {
|
||||||
return wasInitOk();
|
return wasInitOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoundRenderer::cleanup() {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
stopAllSounds();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(NULL,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
|
if(runThreadSafe == true) {
|
||||||
|
safeMutex.setMutex(&mutex);
|
||||||
|
}
|
||||||
|
delete soundPlayer;
|
||||||
|
soundPlayer = NULL;
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
bool SoundRenderer::wasInitOk() const {
|
bool SoundRenderer::wasInitOk() const {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if(soundPlayer != NULL) {
|
if(soundPlayer != NULL) {
|
||||||
|
@ -92,16 +110,7 @@ bool SoundRenderer::wasInitOk() const {
|
||||||
SoundRenderer::~SoundRenderer() {
|
SoundRenderer::~SoundRenderer() {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
stopAllSounds();
|
cleanup();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(NULL,string(__FILE__) + "_" + intToStr(__LINE__));
|
|
||||||
if(runThreadSafe == true) {
|
|
||||||
safeMutex.setMutex(&mutex);
|
|
||||||
}
|
|
||||||
delete soundPlayer;
|
|
||||||
soundPlayer = NULL;
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,8 @@ private:
|
||||||
private:
|
private:
|
||||||
SoundRenderer();
|
SoundRenderer();
|
||||||
|
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//misc
|
//misc
|
||||||
~SoundRenderer();
|
~SoundRenderer();
|
||||||
|
|
Loading…
Reference in New Issue