From f9f6949af2b305ebb158f28727ee2e4352eef5a9 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 16 Jul 2022 09:24:24 +0100 Subject: [PATCH] Clean up `effects_play_sound`, `gfnSoundFunction` --- Source/DiabloUI/diabloui.cpp | 7 ++----- Source/DiabloUI/diabloui.h | 3 +-- Source/DiabloUI/mainmenu.cpp | 8 +++----- Source/effects.cpp | 12 ++++-------- Source/effects.h | 2 +- Source/effects_stubs.cpp | 2 +- Source/menu.cpp | 2 +- Source/movie.cpp | 2 +- 8 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index bf7681a1b..27d8bca8a 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -54,7 +54,6 @@ std::optional ArtBackgroundWidescreen; std::optional ArtBackground; Art ArtCursor; -void (*gfnSoundFunction)(const char *file); bool textInputActive = true; std::size_t SelectedItem = 0; @@ -184,14 +183,12 @@ void UiInitList_clear() void UiPlayMoveSound() { - if (gfnSoundFunction != nullptr) - gfnSoundFunction("Sfx\\Items\\Titlemov.wav"); + effects_play_sound(IS_TITLEMOV); } void UiPlaySelectSound() { - if (gfnSoundFunction != nullptr) - gfnSoundFunction("Sfx\\Items\\Titlslct.wav"); + effects_play_sound(IS_TITLSLCT); } namespace { diff --git a/Source/DiabloUI/diabloui.h b/Source/DiabloUI/diabloui.h index 5bb9c94dd..c68651eb6 100644 --- a/Source/DiabloUI/diabloui.h +++ b/Source/DiabloUI/diabloui.h @@ -68,7 +68,6 @@ extern std::optional ArtBackgroundWidescreen; extern std::optional ArtBackground; extern Art ArtCursor; -extern void (*gfnSoundFunction)(const char *file); extern bool (*gfnHeroInfo)(bool (*fninfofunc)(_uiheroinfo *)); inline SDL_Surface *DiabloUiSurface() @@ -85,7 +84,7 @@ void UiSelHeroMultDialog(bool (*fninfo)(bool (*fninfofunc)(_uiheroinfo *)), bool void UiSelHeroSingDialog(bool (*fninfo)(bool (*fninfofunc)(_uiheroinfo *)), bool (*fncreate)(_uiheroinfo *), bool (*fnremove)(_uiheroinfo *), void (*fnstats)(unsigned int, _uidefaultstats *), _selhero_selections *dlgresult, uint32_t *saveNumber, _difficulty *difficulty); bool UiCreditsDialog(); bool UiSupportDialog(); -bool UiMainMenuDialog(const char *name, _mainmenu_selections *pdwResult, void (*fnSound)(const char *file), int attractTimeOut); +bool UiMainMenuDialog(const char *name, _mainmenu_selections *pdwResult, int attractTimeOut); bool UiProgressDialog(int (*fnfunc)()); bool UiSelectGame(GameData *gameData, int *playerId); bool UiSelectProvider(GameData *gameData); diff --git a/Source/DiabloUI/mainmenu.cpp b/Source/DiabloUI/mainmenu.cpp index 28c32d8f1..5b4905742 100644 --- a/Source/DiabloUI/mainmenu.cpp +++ b/Source/DiabloUI/mainmenu.cpp @@ -32,10 +32,8 @@ void MainmenuEsc() } #endif -void MainmenuLoad(const char *name, void (*fnSound)(const char *file)) +void MainmenuLoad(const char *name) { - gfnSoundFunction = fnSound; - vecMenuItems.push_back(std::make_unique(_("Single Player"), MAINMENU_SINGLE_PLAYER)); vecMenuItems.push_back(std::make_unique(_("Multi Player"), MAINMENU_MULTIPLAYER)); vecMenuItems.push_back(std::make_unique(_("Settings"), MAINMENU_SETTINGS)); @@ -92,12 +90,12 @@ void mainmenu_restart_repintro() dwAttractTicks = SDL_GetTicks() + mainmenu_attract_time_out * 1000; } -bool UiMainMenuDialog(const char *name, _mainmenu_selections *pdwResult, void (*fnSound)(const char *file), int attractTimeOut) +bool UiMainMenuDialog(const char *name, _mainmenu_selections *pdwResult, int attractTimeOut) { MainMenuResult = MAINMENU_NONE; while (MainMenuResult == MAINMENU_NONE) { mainmenu_attract_time_out = attractTimeOut; - MainmenuLoad(name, fnSound); + MainmenuLoad(name); mainmenu_restart_repintro(); // for automatic starts diff --git a/Source/effects.cpp b/Source/effects.cpp index e37b79070..7951370e0 100644 --- a/Source/effects.cpp +++ b/Source/effects.cpp @@ -1310,19 +1310,15 @@ void ui_sound_init() PrivSoundInit(sfx_UI); } -void effects_play_sound(const char *sndFile) +void effects_play_sound(_sfx_id id) { if (!gbSndInited || !gbSoundOn) { return; } - for (TSFX &sfx : sgSFX) { - if (sfx.pSnd != nullptr && string_view(sfx.pszName) == sndFile) { - if (!sfx.pSnd->isPlaying()) - snd_play_snd(sfx.pSnd.get(), 0, 0); - - return; - } + TSFX &sfx = sgSFX[id]; + if (sfx.pSnd != nullptr && !sfx.pSnd->isPlaying()) { + snd_play_snd(sfx.pSnd.get(), 0, 0); } } diff --git a/Source/effects.h b/Source/effects.h index 06ec44007..d3d25a411 100644 --- a/Source/effects.h +++ b/Source/effects.h @@ -1185,7 +1185,7 @@ void sound_update(); void effects_cleanup_sfx(); void sound_init(); void ui_sound_init(); -void effects_play_sound(const char *sndFile); +void effects_play_sound(_sfx_id); int GetSFXLength(int nSFX); } // namespace devilution diff --git a/Source/effects_stubs.cpp b/Source/effects_stubs.cpp index 9dac30b1b..650f90c39 100644 --- a/Source/effects_stubs.cpp +++ b/Source/effects_stubs.cpp @@ -50,7 +50,7 @@ void sound_update() { } void effects_cleanup_sfx() { } void sound_init() { } void ui_sound_init() { } -void effects_play_sound(const char *snd_file) { } +void effects_play_sound(_sfx_id id) { } int GetSFXLength(int nSFX) { return 0; } // clang-format off diff --git a/Source/menu.cpp b/Source/menu.cpp index bc2a750b0..002ec2c4b 100644 --- a/Source/menu.cpp +++ b/Source/menu.cpp @@ -150,7 +150,7 @@ void mainmenu_loop() _mainmenu_selections menu = MAINMENU_NONE; if (demo::IsRunning()) menu = MAINMENU_SINGLE_PLAYER; - else if (!UiMainMenuDialog(gszProductName, &menu, effects_play_sound, 30)) + else if (!UiMainMenuDialog(gszProductName, &menu, 30)) app_fatal(_("Unable to display mainmenu")); switch (menu) { diff --git a/Source/movie.cpp b/Source/movie.cpp index 106b4db02..09cf61e1f 100644 --- a/Source/movie.cpp +++ b/Source/movie.cpp @@ -30,7 +30,7 @@ void play_movie(const char *pszMovie, bool userCanClose) sound_disable_music(true); stream_stop(); - effects_play_sound("Sfx\\Misc\\blank.wav"); + effects_play_sound(SFX_SILENCE); if (IsHardwareCursorEnabled() && ControlDevice == ControlTypes::KeyboardAndMouse) { SetHardwareCursorVisible(false);