From 7cb73a6717f84499de65e8a832f2b309dfeffee1 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 30 Aug 2021 08:30:45 +0200 Subject: [PATCH] Minimize impact of NOSOUND --- Source/DiabloUI/diabloui.cpp | 2 -- Source/diablo.cpp | 14 +------------- Source/effects.h | 3 --- Source/effects_stubs.cpp | 1 + Source/gamemenu.cpp | 14 ++------------ Source/monster.cpp | 2 -- Source/monster.h | 7 +------ Source/movie.cpp | 9 +-------- Source/sound.cpp | 2 -- Source/sound.h | 10 ++++++++-- Source/sound_stubs.cpp | 5 +++++ 11 files changed, 19 insertions(+), 50 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index d2d91cd50..2294698c0 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -401,12 +401,10 @@ void UiHandleEvents(SDL_Event *event) gbActive = false; } else if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { ReinitializeHardwareCursor(); -#ifndef NOSOUND } else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST) { music_mute(); } else if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { music_unmute(); -#endif } } #endif diff --git a/Source/diablo.cpp b/Source/diablo.cpp index f05d0a32e..2893eaf7d 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -53,6 +53,7 @@ #include "qol/itemlabels.h" #include "restrict.h" #include "setmaps.h" +#include "sound.h" #include "stores.h" #include "storm/storm.h" #include "themes.h" @@ -64,9 +65,6 @@ #include "utils/language.h" #include "utils/paths.h" -#ifndef NOSOUND -#include "sound.h" -#endif #ifdef GPERF_HEAP_FIRST_GAME_ITERATION #include #endif @@ -963,10 +961,8 @@ void DiabloInit() DiabloInitScreen(); -#ifndef NOSOUND snd_init(); was_snd_init = true; -#endif ui_sound_init(); @@ -1001,9 +997,7 @@ void DiabloDeinit() SaveOptions(); if (was_snd_init) effects_cleanup_sfx(); -#ifndef NOSOUND snd_deinit(); -#endif if (was_ui_init) UiDestroy(); if (was_archives_init) @@ -1700,9 +1694,7 @@ void diablo_focus_pause() LastMouseButtonAction = MouseActionType::None; } -#ifndef NOSOUND music_mute(); -#endif MinimizePaused = true; } @@ -1717,9 +1709,7 @@ void diablo_focus_unpause() PauseMode = 0; } -#ifndef NOSOUND music_unmute(); -#endif MinimizePaused = false; } @@ -2049,9 +2039,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir) music_start(leveltype); if (MinimizePaused) { -#ifndef NOSOUND music_mute(); -#endif } while (!IncProgress()) diff --git a/Source/effects.h b/Source/effects.h index c7d724f22..2d7c5d8ae 100644 --- a/Source/effects.h +++ b/Source/effects.h @@ -1186,9 +1186,6 @@ void effects_cleanup_sfx(); void sound_init(); void ui_sound_init(); void effects_play_sound(const char *sndFile); - -#ifndef NOSOUND int GetSFXLength(int nSFX); -#endif } // namespace devilution diff --git a/Source/effects_stubs.cpp b/Source/effects_stubs.cpp index 2c68ebbc8..14d8ebbab 100644 --- a/Source/effects_stubs.cpp +++ b/Source/effects_stubs.cpp @@ -53,6 +53,7 @@ void effects_cleanup_sfx() { } void sound_init() { } void ui_sound_init() { } void effects_play_sound(const char *snd_file) { } +int GetSFXLength(int nSFX) { return 0; } // clang-format off } // namespace devilution diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index 3eeae294f..cc9cb5dec 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -12,11 +12,8 @@ #include "loadsave.h" #include "options.h" #include "pfile.h" -#include "utils/language.h" - -#ifndef NOSOUND #include "sound.h" -#endif +#include "utils/language.h" namespace devilution { namespace { @@ -117,7 +114,6 @@ void GamemenuRestartTown(bool /*bActivate*/) void GamemenuSoundMusicToggle(const char *const *names, TMenuItem *menuItem, int volume) { -#ifndef NOSOUND if (gbSndInited) { menuItem->dwFlags |= GMENU_ENABLED | GMENU_SLIDER; menuItem->pszStr = names[0]; @@ -125,18 +121,15 @@ void GamemenuSoundMusicToggle(const char *const *names, TMenuItem *menuItem, int gmenu_slider_set(menuItem, VOLUME_MIN, VOLUME_MAX, volume); return; } -#endif menuItem->dwFlags &= ~(GMENU_ENABLED | GMENU_SLIDER); menuItem->pszStr = names[1]; } -#ifndef NOSOUND int GamemenuSliderMusicSound(TMenuItem *menuItem) { return gmenu_slider_get(menuItem, VOLUME_MIN, VOLUME_MAX); } -#endif void GamemenuGetMusic() { @@ -192,7 +185,6 @@ void GamemenuOptions(bool /*bActivate*/) void GamemenuMusicVolume(bool bActivate) { -#ifndef NOSOUND if (bActivate) { if (gbMusicOn) { gbMusicOn = false; @@ -232,13 +224,12 @@ void GamemenuMusicVolume(bool bActivate) music_start(lt); } } -#endif + GamemenuGetMusic(); } void GamemenuSoundVolume(bool bActivate) { -#ifndef NOSOUND if (bActivate) { if (gbSoundOn) { gbSoundOn = false; @@ -262,7 +253,6 @@ void GamemenuSoundVolume(bool bActivate) } PlaySFX(IS_TITLEMOV); GamemenuGetSound(); -#endif } void GamemenuGamma(bool bActivate) diff --git a/Source/monster.cpp b/Source/monster.cpp index 6a484732e..534abab3f 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -4740,7 +4740,6 @@ void PlayEffect(MonsterStruct &monster, int mode) } int sndIdx = GenerateRnd(2); -#ifndef NOSOUND if (!gbSndInited || !gbSoundOn || gbBufferMsgs != 0) { return; } @@ -4757,7 +4756,6 @@ void PlayEffect(MonsterStruct &monster, int mode) return; snd_play_snd(snd, lVolume, lPan); -#endif } void MissToMonst(MissileStruct &missile, Point position) diff --git a/Source/monster.h b/Source/monster.h index f48555614..4d706924e 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -16,13 +16,10 @@ #include "miniwin/miniwin.h" #include "utils/stdcompat/optional.hpp" #include "monstdat.h" +#include "sound.h" #include "spelldat.h" #include "textdat.h" -#ifndef NOSOUND -#include "sound.h" -#endif - namespace devilution { struct MissileStruct; @@ -152,9 +149,7 @@ struct CMonster { { return Anims[static_cast(graphic)]; } -#ifndef NOSOUND std::unique_ptr Snds[4][2]; -#endif uint16_t mMinHP; uint16_t mMaxHP; uint8_t mAFNum; diff --git a/Source/movie.cpp b/Source/movie.cpp index 842ea37dc..6c2958595 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -8,13 +8,10 @@ #include "effects.h" #include "engine/demomode.h" #include "hwcursor.hpp" +#include "sound.h" #include "storm/storm_svid.h" #include "utils/display.h" -#ifndef NOSOUND -#include "sound.h" -#endif - namespace devilution { /** Should the movie continue playing. */ @@ -34,11 +31,9 @@ void play_movie(const char *pszMovie, bool userCanClose) movie_playing = true; -#ifndef NOSOUND sound_disable_music(true); stream_stop(); effects_play_sound("Sfx\\Misc\\blank.wav"); -#endif if (IsHardwareCursorEnabled()) { SetHardwareCursorVisible(false); @@ -66,9 +61,7 @@ void play_movie(const char *pszMovie, bool userCanClose) SVidPlayEnd(); } -#ifndef NOSOUND sound_disable_music(false); -#endif movie_playing = false; diff --git a/Source/sound.cpp b/Source/sound.cpp index f82ca24f3..4538c648b 100644 --- a/Source/sound.cpp +++ b/Source/sound.cpp @@ -184,13 +184,11 @@ std::unique_ptr sound_file_load(const char *path, bool stream) return snd; } -#ifndef NOSOUND TSnd::~TSnd() { DSB.Stop(); DSB.Release(); } -#endif void snd_init() { diff --git a/Source/sound.h b/Source/sound.h index edb6212a4..c5cd786b5 100644 --- a/Source/sound.h +++ b/Source/sound.h @@ -40,17 +40,23 @@ enum _music_id : uint8_t { }; struct TSnd { + uint32_t start_tc; + #ifndef NOSOUND SoundSample DSB; - Uint32 start_tc; bool isPlaying() { return DSB.IsPlaying(); } +#else + bool isPlaying() + { + return false; + } +#endif ~TSnd(); -#endif }; extern bool gbSndInited; diff --git a/Source/sound_stubs.cpp b/Source/sound_stubs.cpp index 43454e686..9e11a0f8b 100644 --- a/Source/sound_stubs.cpp +++ b/Source/sound_stubs.cpp @@ -13,6 +13,9 @@ bool gbSoundOn; void ClearDuplicateSounds() { } void snd_play_snd(TSnd *pSnd, int lVolume, int lPan) { } std::unique_ptr sound_file_load(const char *path, bool stream) { return nullptr; } +TSnd::~TSnd() +{ +} void snd_init() { } void snd_deinit() { } void music_stop() { } @@ -20,6 +23,8 @@ void music_start(uint8_t nTrack) { } void sound_disable_music(bool disable) { } int sound_get_or_set_music_volume(int volume) { return 0; } int sound_get_or_set_sound_volume(int volume) { return 0; } +void music_mute() { } +void music_unmute() { } // clang-format on } // namespace devilution