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