diff --git a/mk/linux/glest.ini b/mk/linux/glest.ini index ebe86d0f0..13dfc2504 100644 --- a/mk/linux/glest.ini +++ b/mk/linux/glest.ini @@ -96,6 +96,18 @@ VersionURL=http://zetaglest.dreamhosters.com/files/versions/ Windowed=false ; sfx +; These can be over-ridden by adding the variables to your glestuser.ini +; file. +; +; FIXME: There should be a way to use the "DataPath" variable +; here (defined above) PlaySoundAttention=../../../zetaglest-data/data/core/menu/sound/attention.wav PlaySoundHighlight=../../../zetaglest-data/data/core/menu/sound/highlight.wav PlaySoundNewServer=../../../zetaglest-data/data/core/menu/sound/attention.wav +PlaySoundMarker=../../../zetaglest-data/data/core/menu/sound/sonar.wav + +; it's recommended that users not over-ride these. The sounds are just for +; menu clicks and should remain very short in duration. +PlaySoundMenuClickA=../../../zetaglest-data/data/core/menu/sound/click_a.wav +PlaySoundMenuClickB=../../../zetaglest-data/data/core/menu/sound/click_b.wav +PlaySoundMenuClickC=../../../zetaglest-data/data/core/menu/sound/click_c.wav diff --git a/mk/macos/glest.ini b/mk/macos/glest.ini index 7ea7e5e77..975365230 100644 --- a/mk/macos/glest.ini +++ b/mk/macos/glest.ini @@ -94,6 +94,20 @@ VersionURL=http://zetaglest.dreamhosters.com/files/versions/ Windowed=true ; sfx +; These can be over-ridden by adding the variables to your glestuser.ini +; file. +; +; FIXME: There should be a way to use the "DataPath" variable +; here (defined above) PlaySoundAttention=../../../zetaglest-data/data/core/menu/sound/attention.wav PlaySoundHighlight=../../../zetaglest-data/data/core/menu/sound/highlight.wav PlaySoundNewServer=../../../zetaglest-data/data/core/menu/sound/attention.wav +PlaySoundMarker=../../../zetaglest-data/data/core/menu/sound/sonar.wav + +; it's recommended that users not over-ride these. The sounds are just for +; menu clicks and should remain very short in duration. +; it's recommended that users not over-ride these. The sounds are just for +; menu clicks and should remain very short in duration. +PlaySoundMenuClickA=../../../zetaglest-data/data/core/menu/sound/click_a.wav +PlaySoundMenuClickB=../../../zetaglest-data/data/core/menu/sound/click_b.wav +PlaySoundMenuClickC=../../../zetaglest-data/data/core/menu/sound/click_c.wav diff --git a/mk/windows/glest.ini b/mk/windows/glest.ini index f97857603..d383990e6 100644 --- a/mk/windows/glest.ini +++ b/mk/windows/glest.ini @@ -96,6 +96,18 @@ VersionURL=http://zetaglest.dreamhosters.com/files/versions/ Windowed=false ; sfx +; These can be over-ridden by adding the variables to your glestuser.ini +; file. +; +; FIXME: There should be a way to use the "DataPath" variable +; here (defined above) PlaySoundAttention=..\..\..\zetaglest-data\data\core\menu\sound\attention.wav PlaySoundHighlight=..\..\..\zetaglest-data\data\core\menu\sound\highlight.wav PlaySoundNewServer=..\..\..\zetaglest-data\data\core\menu\sound\attention.wav +PlaySoundMarker=..\..\..\zetaglest-data\data\core\menu\sound\sonar.wav + +; it's recommended that users not over-ride these. The sounds are just for +; menu clicks and should remain very short in duration. +PlaySoundMenuClickA=..\..\..\zetaglest-data\data\core\menu\sound\click_a.wav +PlaySoundMenuClickB=..\..\..\zetaglest-data\data\core\menu\sound\click_b.wav +PlaySoundMenuClickC=..\..\..\zetaglest-data\data\core\menu\sound\click_c.wav diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index b7f587ae9..52ca58182 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -1,13 +1,25 @@ -// ============================================================== -// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// chat_manager.cpp: game setup menu as it appears to +// to the host // -// 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 -// ============================================================== +// This file is part of ZetaGlest +// +// Copyright (C) 2018 The ZetaGlest team +// +// ZetaGlest is a fork of MegaGlest +// +// 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 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see #include "chat_manager.h" @@ -778,12 +790,10 @@ namespace if (msg.chatText.find (playerName) != string::npos) { - CoreData & coreData = - CoreData::getInstance (); + static PlaySoundClip snd; SoundRenderer & soundRenderer = SoundRenderer::getInstance (); - soundRenderer.playFx (coreData. - getHighlightSound (), + soundRenderer.playFx (snd.getSound (snd.sfxHighlight), true); } console->addLine (msg.chatText. diff --git a/source/glest_game/game/chat_manager.h b/source/glest_game/game/chat_manager.h index ab702fcf0..1b0b32ee5 100644 --- a/source/glest_game/game/chat_manager.h +++ b/source/glest_game/game/chat_manager.h @@ -1,13 +1,25 @@ -// ============================================================== -// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// chat_manager.h: game setup menu as it appears to +// to the host // -// 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 -// ============================================================== +// This file is part of ZetaGlest +// +// Copyright (C) 2018 The ZetaGlest team +// +// ZetaGlest is a fork of MegaGlest +// +// 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 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see #ifndef _GLEST_GAME_CHATMANAGER_H_ # define _GLEST_GAME_CHATMANAGER_H_ diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 71bca41a0..9e61f00e6 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -4820,7 +4820,8 @@ namespace Glest (faction->getTeam () == getWorld ()->getThisFaction ()->getTeam ())) { - soundRenderer.playFx (coreData.getMarkerSound (), true); + static PlaySoundClip snd; + soundRenderer.playFx (snd.getSound (snd.sfxMarker), true); } } } diff --git a/source/glest_game/game/game_constants.h b/source/glest_game/game/game_constants.h index 36d2c2a51..00ccb5fc5 100644 --- a/source/glest_game/game/game_constants.h +++ b/source/glest_game/game/game_constants.h @@ -1,13 +1,25 @@ -// ============================================================== -// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// game_constants.h: game setup menu as it appears to +// to the host // -// 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 -// ============================================================== +// This file is part of ZetaGlest +// +// Copyright (C) 2018 The ZetaGlest team +// +// ZetaGlest is a fork of MegaGlest +// +// 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 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see #ifndef _GLEST_GAME_GAMECONSTANTS_H_ # define _GLEST_GAME_GAMECONSTANTS_H_ @@ -298,7 +310,6 @@ namespace HUD_SCREEN_FILE; static const char * HUD_SCREEN_FILE_FILTER; - }; enum PathType diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index fbd23b506..70d2a4555 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -63,6 +63,16 @@ namespace Glest static const string CORE_WATER_SOUNDS_PATH = CORE_PATH + "/water_sounds/"; + // Sound effects + // These variables are specified in the ini file + const string PlaySoundClip::sfxAttention = "PlaySoundAttention"; + const string PlaySoundClip::sfxHighlight = "PlaySoundHighlight"; + const string PlaySoundClip::sfxNewServer = "PlaySoundNewServer"; + const string PlaySoundClip::sfxMarker = "PlaySoundMarker"; + const string PlaySoundClip::sfxMenuClickA = "PlaySoundMenuClickA"; + const string PlaySoundClip::sfxMenuClickB = "PlaySoundMenuClickB"; + const string PlaySoundClip::sfxMenuClickC = "PlaySoundMenuClickC"; + CoreData & CoreData::getInstance () { static CoreData coreData; @@ -646,182 +656,20 @@ namespace Glest StaticSound *CoreData::getClickSoundA () { - int loadAttemptLookupKey = tsyst_COUNT + 3; - if (itemLoadAttempted.find (loadAttemptLookupKey) == - itemLoadAttempted.end ()) - { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try - { - string data_path = getDataPath (); - clickSoundA.load (getGameCustomCoreDataPath (data_path, - CORE_MENU_SOUND_PATH + - "click_a.wav")); - } - catch (const megaglest_runtime_error & ex) - { - message (ex.what (), - GlobalStaticFlags::getIsNonGraphicalModeEnabled (), - tempDataLocation); - } - } - return &clickSoundA; + static PlaySoundClip snd; + return snd.getSound (snd.sfxMenuClickA); } StaticSound *CoreData::getClickSoundB () { - int loadAttemptLookupKey = tsyst_COUNT + 4; - if (itemLoadAttempted.find (loadAttemptLookupKey) == - itemLoadAttempted.end ()) - { + static PlaySoundClip snd; + return snd.getSound (snd.sfxMenuClickB); - itemLoadAttempted[loadAttemptLookupKey] = true; - - try - { - string data_path = getDataPath (); - clickSoundB.load (getGameCustomCoreDataPath (data_path, - CORE_MENU_SOUND_PATH + - "click_b.wav")); - } - catch (const megaglest_runtime_error & ex) - { - message (ex.what (), - GlobalStaticFlags::getIsNonGraphicalModeEnabled (), - tempDataLocation); - } - } - - return &clickSoundB; } StaticSound *CoreData::getClickSoundC () { - int loadAttemptLookupKey = tsyst_COUNT + 5; - if (itemLoadAttempted.find (loadAttemptLookupKey) == - itemLoadAttempted.end ()) - { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try - { - string data_path = getDataPath (); - clickSoundC.load (getGameCustomCoreDataPath (data_path, - CORE_MENU_SOUND_PATH + - "click_c.wav")); - } - catch (const megaglest_runtime_error & ex) - { - message (ex.what (), - GlobalStaticFlags::getIsNonGraphicalModeEnabled (), - tempDataLocation); - } - } - - return &clickSoundC; - } - - StaticSound *CoreData::getSound (const std::string& iniPlaySoundVal) - { - int loadAttemptLookupKey = tsyst_COUNT + 6; - if (itemLoadAttempted.find (loadAttemptLookupKey) == - itemLoadAttempted.end ()) - { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try - { - static Config & config = Config::getInstance (); - iniPlaySound.load (config.getString (iniPlaySoundVal, "")); - } - catch (const megaglest_runtime_error & ex) - { - message (ex.what (), - GlobalStaticFlags::getIsNonGraphicalModeEnabled (), - tempDataLocation); - } - } - - return &iniPlaySound; - } - - StaticSound *CoreData::getAttentionSound () - { - int loadAttemptLookupKey = tsyst_COUNT + 6; - if (itemLoadAttempted.find (loadAttemptLookupKey) == - itemLoadAttempted.end ()) - { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try - { - static Config & config = Config::getInstance (); - attentionSound.load (config.getString ("PlaySoundAttention", "")); - } - catch (const megaglest_runtime_error & ex) - { - message (ex.what (), - GlobalStaticFlags::getIsNonGraphicalModeEnabled (), - tempDataLocation); - } - } - - return &attentionSound; - } - - StaticSound *CoreData::getHighlightSound () - { - int loadAttemptLookupKey = tsyst_COUNT + 7; - if (itemLoadAttempted.find (loadAttemptLookupKey) == - itemLoadAttempted.end ()) - { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try - { - static Config & config = Config::getInstance (); - highlightSound.load (config.getString ("PlaySoundHighlight", "")); - } - catch (const megaglest_runtime_error & ex) - { - message (ex.what (), - GlobalStaticFlags::getIsNonGraphicalModeEnabled (), - tempDataLocation); - } - } - - return &highlightSound; - } - StaticSound *CoreData::getMarkerSound () - { - int loadAttemptLookupKey = tsyst_COUNT + 8; - if (itemLoadAttempted.find (loadAttemptLookupKey) == - itemLoadAttempted.end ()) - { - - itemLoadAttempted[loadAttemptLookupKey] = true; - - try - { - string data_path = getDataPath (); - markerSound.load (getGameCustomCoreDataPath (data_path, - CORE_MENU_SOUND_PATH + - "sonar.wav")); - } - catch (const megaglest_runtime_error & ex) - { - message (ex.what (), - GlobalStaticFlags::getIsNonGraphicalModeEnabled (), - tempDataLocation); - } - } - - return &markerSound; + static PlaySoundClip snd; + return snd.getSound (snd.sfxMenuClickC); } void CoreData::loadWaterSoundsIfRequired () @@ -2112,6 +1960,36 @@ namespace Glest return fileWasFound; } + PlaySoundClip::PlaySoundClip (void) {}; + + PlaySoundClip::~PlaySoundClip (void) {}; + + StaticSound *PlaySoundClip::getSound (const std::string& iniPlaySoundVal) + { + CoreData coreData; + int loadAttemptLookupKey = coreData.tsyst_COUNT + 6; + if (coreData.itemLoadAttempted.find (loadAttemptLookupKey) == + coreData.itemLoadAttempted.end ()) + { + + coreData.itemLoadAttempted[loadAttemptLookupKey] = true; + + try + { + static Config & config = Config::getInstance (); + iniPlaySound.load (config.getString (iniPlaySoundVal, "")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + + return &iniPlaySound; + } + // ================== PRIVATE ======================== } diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 65eb729c6..6865f0d4b 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -58,19 +58,12 @@ namespace Glest class CoreData { + friend class PlaySoundClip; private: std::map < int, bool > itemLoadAttempted; StrSound introMusic; StrSound menuMusic; - StaticSound clickSoundA; - StaticSound clickSoundB; - StaticSound clickSoundC; - StaticSound iniPlaySound; - StaticSound attentionSound; - StaticSound newServerSound; - StaticSound highlightSound; - StaticSound markerSound; SoundContainer waterSounds; Texture2D *logoTexture; @@ -210,14 +203,17 @@ namespace Glest StrSound *getIntroMusic (); StrSound *getMenuMusic (); + // When issue #63 was done + // + // and the PlaySoundFile class was created, + // these functions were kept because they were being called from many + // different places in the code base. Rather than trying to change + // all those locations, I made these three into "wrapper" functions. + // -andy5995 2018-02-22 StaticSound *getClickSoundA (); StaticSound *getClickSoundB (); StaticSound *getClickSoundC (); - StaticSound *getSound (const std::string& iniPlaySoundVal); - StaticSound *getAttentionSound (); - StaticSound *getNewServerSound (); - StaticSound *getHighlightSound (); - StaticSound *getMarkerSound (); + StaticSound *getWaterSound (); // Fonts @@ -357,8 +353,27 @@ namespace Glest string fontType, string fontTypeFamily, string fontUniqueKey); + + }; + class PlaySoundClip + { + private: + StaticSound iniPlaySound; + public: + StaticSound *getSound (const std::string& iniPlaySoundVal); + static const string sfxAttention; + static const string sfxHighlight; + static const string sfxNewServer; + static const string sfxMarker; + static const string sfxMenuClickA; + static const string sfxMenuClickB; + static const string sfxMenuClickC; + PlaySoundClip(); + ~PlaySoundClip(); + + }; }} //end namespace #endif diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index de1a69796..b8d45fdc7 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -6343,8 +6343,9 @@ namespace Glest if (currentConnectionCount > soundConnectionCount) { soundConnectionCount = currentConnectionCount; + static PlaySoundClip snd; SoundRenderer::getInstance (). - playFx (CoreData::getInstance ().getAttentionSound ()); + playFx (snd.getSound (snd.sfxAttention)); //switch on music again!! Config & config = Config::getInstance (); float diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 981ce9744..494d712eb 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -4674,8 +4674,9 @@ namespace Glest if (currentConnectionCount > soundConnectionCount) { soundConnectionCount = currentConnectionCount; + static PlaySoundClip snd; SoundRenderer::getInstance (). - playFx (CoreData::getInstance ().getAttentionSound ()); + playFx (snd.getSound (snd.sfxAttention)); //switch on music again!! Config & config = Config::getInstance (); float configVolume = (config.getInt ("SoundVolumeMusic") / 100.f); diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index 9a5e546ec..26d3043e1 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -553,10 +553,9 @@ namespace Glest string helpSTr = szBuf; if (helpSTr.find (currentIrcNick) != string::npos) { - CoreData & coreData = CoreData::getInstance (); SoundRenderer & soundRenderer = SoundRenderer::getInstance (); - - soundRenderer.playFx (coreData.getHighlightSound ()); + static PlaySoundClip snd; + soundRenderer.playFx (snd.getSound (snd.sfxHighlight)); } consoleIRC.addLine (szBuf); } @@ -1216,8 +1215,9 @@ namespace Glest if (playServerFoundSound) { - SoundRenderer::getInstance ().playFx (CoreData::getInstance (). - getSound ("PlaySoundNewServer")); + static PlaySoundClip snd; + SoundRenderer::getInstance ().playFx (snd.getSound (snd.sfxNewServer)); + //switch on music again!! Config & config = Config::getInstance (); float configVolume = (config.getInt ("SoundVolumeMusic") / 100.f); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index e873f0b89..942fd0e01 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -1,13 +1,25 @@ -// ============================================================== -// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// unit_updater.cpp: game setup menu as it appears to +// to the host // -// 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 -// ============================================================== +// This file is part of ZetaGlest +// +// Copyright (C) 2018 The ZetaGlest team +// +// ZetaGlest is a fork of MegaGlest +// +// 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 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see #include "unit_updater.h" @@ -3130,8 +3142,9 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, attackWarnings.push_back(awd); if(world->getAttackWarningsEnabled() == true) { + static PlaySoundClip snd; - SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound(),true); + SoundRenderer::getInstance().playFx(snd.getSound (snd.sfxAttention),true); world->addAttackEffects(enemyUnit); } } diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index b02100aa5..2dee6c004 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -1,13 +1,25 @@ -// ============================================================== -// This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// unit_updater.h: game setup menu as it appears to +// to the host // -// 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 -// ============================================================== +// This file is part of ZetaGlest +// +// Copyright (C) 2018 The ZetaGlest team +// +// ZetaGlest is a fork of MegaGlest +// +// 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 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see #ifndef _GLEST_GAME_UNITUPDATER_H_ #define _GLEST_GAME_UNITUPDATER_H_