diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index 511a050d..32152797 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -57,6 +57,18 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu): leftline-=30; //soundboxes + labelSoundFactory.init(leftLabelStart, leftline); + labelSoundFactory.setText(lang.get("SoundAndMusic")); + listBoxSoundFactory.init(leftColumnStart, leftline, 80); + listBoxSoundFactory.pushBackItem("None"); + listBoxSoundFactory.pushBackItem("OpenAL"); +#ifdef WIN32 + listBoxSoundFactory.pushBackItem("DirectSound8"); +#endif + + listBoxSoundFactory.setSelectedItem(config.getString("FactorySound")); + leftline-=30; + labelVolumeFx.init(leftLabelStart, leftline); labelVolumeFx.setText(lang.get("FxVolume")); listBoxVolumeFx.init(leftColumnStart, leftline, 80); @@ -330,6 +342,7 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){ listBoxTextures3D.mouseClick(x, y); listBoxUnitParticles.mouseClick(x, y); listBoxLights.mouseClick(x, y); + listBoxSoundFactory.mouseClick(x, y); listBoxVolumeFx.mouseClick(x, y); listBoxVolumeAmbient.mouseClick(x, y); listBoxVolumeMusic.mouseClick(x, y); @@ -348,6 +361,7 @@ void MenuStateOptions::mouseMove(int x, int y, const MouseState *ms){ buttonAutoConfig.mouseMove(x, y); buttonVideoInfo.mouseMove(x, y); listBoxLang.mouseMove(x, y); + listBoxSoundFactory.mouseMove(x, y); listBoxVolumeFx.mouseMove(x, y); listBoxVolumeAmbient.mouseMove(x, y); listBoxVolumeMusic.mouseMove(x, y); @@ -409,6 +423,7 @@ void MenuStateOptions::render(){ renderer.renderListBox(&listBoxUnitParticles); renderer.renderListBox(&listBoxLights); renderer.renderListBox(&listBoxFilter); + renderer.renderListBox(&listBoxSoundFactory); renderer.renderListBox(&listBoxVolumeFx); renderer.renderListBox(&listBoxVolumeAmbient); renderer.renderListBox(&listBoxVolumeMusic); @@ -420,6 +435,7 @@ void MenuStateOptions::render(){ renderer.renderLabel(&labelUnitParticles); renderer.renderLabel(&labelLights); renderer.renderLabel(&labelFilter); + renderer.renderLabel(&labelSoundFactory); renderer.renderLabel(&labelVolumeFx); renderer.renderLabel(&labelVolumeAmbient); renderer.renderLabel(&labelVolumeMusic); @@ -460,6 +476,7 @@ void MenuStateOptions::saveConfig(){ config.setBool("Textures3D", listBoxTextures3D.getSelectedItemIndex()); config.setBool("UnitParticles", listBoxUnitParticles.getSelectedItemIndex()); config.setInt("MaxLights", listBoxLights.getSelectedItemIndex()+1); + config.setString("FactorySound", listBoxSoundFactory.getSelectedItem()); config.setString("SoundVolumeFx", listBoxVolumeFx.getSelectedItem()); config.setString("SoundVolumeAmbient", listBoxVolumeAmbient.getSelectedItem()); config.setString("FontSizeAdjustment", listFontSizeAdjustment.getSelectedItem()); @@ -480,8 +497,14 @@ void MenuStateOptions::saveConfig(){ } config.save(); - SoundRenderer::getInstance().loadConfig(); - SoundRenderer::getInstance().setMusicVolume(CoreData::getInstance().getMenuMusic()); + + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + soundRenderer.stopAllSounds(); + bool initOk = soundRenderer.init(program->getWindow()); + soundRenderer.loadConfig(); + soundRenderer.setMusicVolume(CoreData::getInstance().getMenuMusic()); + soundRenderer.playMusic(CoreData::getInstance().getMenuMusic()); + Renderer::getInstance().loadConfig(); } diff --git a/source/glest_game/menu/menu_state_options.h b/source/glest_game/menu/menu_state_options.h index 159035e4..10afd6f3 100644 --- a/source/glest_game/menu/menu_state_options.h +++ b/source/glest_game/menu/menu_state_options.h @@ -33,6 +33,7 @@ private: GraphicLabel labelTextures3D; GraphicLabel labelLights; GraphicLabel labelUnitParticles; + GraphicLabel labelSoundFactory; GraphicLabel labelVolumeFx; GraphicLabel labelVolumeAmbient; GraphicLabel labelVolumeMusic; @@ -42,6 +43,7 @@ private: GraphicListBox listBoxTextures3D; GraphicListBox listBoxLights; GraphicListBox listBoxUnitParticles; + GraphicListBox listBoxSoundFactory; GraphicListBox listBoxVolumeFx; GraphicListBox listBoxVolumeAmbient; GraphicListBox listBoxVolumeMusic; diff --git a/source/glest_game/sound/sound_renderer.cpp b/source/glest_game/sound/sound_renderer.cpp index be9c9720..c3a2d930 100644 --- a/source/glest_game/sound/sound_renderer.cpp +++ b/source/glest_game/sound/sound_renderer.cpp @@ -50,17 +50,18 @@ bool SoundRenderer::init(Window *window) { runThreadSafe = config.getBool("ThreadedSoundStream","false"); //if(soundPlayer == NULL) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); - si.setFactory(fr.getSoundFactory(config.getString("FactorySound"))); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + si.setFactory(fr.getSoundFactory(config.getString("FactorySound"))); - stopAllSounds(); + stopAllSounds(); - soundPlayer= si.newSoundPlayer(); - - SoundPlayerParams soundPlayerParams; - soundPlayerParams.staticBufferCount= config.getInt("SoundStaticBuffers"); - soundPlayerParams.strBufferCount= config.getInt("SoundStreamingBuffers"); - soundPlayer->init(&soundPlayerParams); + soundPlayer= si.newSoundPlayer(); + if(soundPlayer != NULL) { + SoundPlayerParams soundPlayerParams; + soundPlayerParams.staticBufferCount= config.getInt("SoundStaticBuffers"); + soundPlayerParams.strBufferCount= config.getInt("SoundStreamingBuffers"); + soundPlayer->init(&soundPlayerParams); + } //} SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -73,6 +74,13 @@ bool SoundRenderer::wasInitOk() const { if(soundPlayer != NULL) { result = soundPlayer->wasInitOk(); } + else { + Config &config= Config::getInstance(); + if(config.getString("FactorySound") == "" || + config.getString("FactorySound") == "None") { + result = true; + } + } return result; } diff --git a/source/shared_lib/include/platform/sdl/factory_repository.h b/source/shared_lib/include/platform/sdl/factory_repository.h index 89785ba5..fe84c79b 100644 --- a/source/shared_lib/include/platform/sdl/factory_repository.h +++ b/source/shared_lib/include/platform/sdl/factory_repository.h @@ -27,6 +27,7 @@ #endif #include "sound_factory_openal.h" +#include "sound_factory_none.h" using std::string; @@ -42,6 +43,7 @@ using Shared::Sound::Ds8::SoundFactoryDs8; #endif using Shared::Sound::OpenAL::SoundFactoryOpenAL; +using Shared::Sound::SoundFactoryNone; namespace Shared{ namespace Platform{ @@ -66,6 +68,7 @@ private: #endif SoundFactoryOpenAL soundFactoryOpenAL; + SoundFactoryNone soundFactoryNone; public: static FactoryRepository &getInstance(); diff --git a/source/shared_lib/sources/platform/sdl/factory_repository.cpp b/source/shared_lib/sources/platform/sdl/factory_repository.cpp new file mode 100644 index 00000000..39fe114f --- /dev/null +++ b/source/shared_lib/sources/platform/sdl/factory_repository.cpp @@ -0,0 +1,44 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2005 Matthias Braun +// +// You can redistribute this code 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 +// ============================================================== + +#include "factory_repository.h" + +namespace Shared{ namespace Platform{ + +// ===================================================== +// class FactoryRepository +// ===================================================== + +FactoryRepository &FactoryRepository::getInstance() { + static FactoryRepository factoryRepository; + return factoryRepository; +} + +GraphicsFactory *FactoryRepository::getGraphicsFactory(const string &name) { + if(name == "OpenGL") { + return &graphicsFactoryGl; + } + + throw runtime_error("Unknown graphics factory: " + name); +} + +SoundFactory *FactoryRepository::getSoundFactory(const string &name) { + if(name == "OpenAL") { + return &soundFactoryOpenAL; + } + else if(name == "" || name == "None") { + return &soundFactoryNone; + } + + throw runtime_error("Unknown sound factory: " + name); +} + +}}//end namespace diff --git a/source/shared_lib/sources/platform/win32/factory_repository.cpp b/source/shared_lib/sources/platform/win32/factory_repository.cpp index 8f05f14b..494173bb 100644 --- a/source/shared_lib/sources/platform/win32/factory_repository.cpp +++ b/source/shared_lib/sources/platform/win32/factory_repository.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -39,9 +39,12 @@ SoundFactory *FactoryRepository::getSoundFactory(const string &name){ if(name == "DirectSound8"){ return &soundFactoryDs8; } - if(name == "OpenAL") { + else if(name == "OpenAL") { return &soundFactoryOpenAL; } + else if(name == "" || name == "None") { + return &soundFactoryNone; + } throw runtime_error("Unknown sound factory: " + name); }