- Added ability to disable sound for poor users with non-functional sound

This commit is contained in:
Mark Vejvoda 2010-07-16 06:35:22 +00:00
parent 0089cc7d31
commit 1e077512d8
6 changed files with 96 additions and 13 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

View File

@ -0,0 +1,44 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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

View File

@ -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);
}