Browse Source

Clean up `effects_play_sound`, `gfnSoundFunction`

pull/5015/head
Gleb Mazovetskiy 4 years ago
parent
commit
f9f6949af2
  1. 7
      Source/DiabloUI/diabloui.cpp
  2. 3
      Source/DiabloUI/diabloui.h
  3. 8
      Source/DiabloUI/mainmenu.cpp
  4. 12
      Source/effects.cpp
  5. 2
      Source/effects.h
  6. 2
      Source/effects_stubs.cpp
  7. 2
      Source/menu.cpp
  8. 2
      Source/movie.cpp

7
Source/DiabloUI/diabloui.cpp

@ -54,7 +54,6 @@ std::optional<OwnedPcxSprite> ArtBackgroundWidescreen;
std::optional<OwnedPcxSpriteSheet> 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 {

3
Source/DiabloUI/diabloui.h

@ -68,7 +68,6 @@ extern std::optional<OwnedPcxSprite> ArtBackgroundWidescreen;
extern std::optional<OwnedPcxSpriteSheet> 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);

8
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<UiListItem>(_("Single Player"), MAINMENU_SINGLE_PLAYER));
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Multi Player"), MAINMENU_MULTIPLAYER));
vecMenuItems.push_back(std::make_unique<UiListItem>(_("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

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

2
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

2
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

2
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) {

2
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);

Loading…
Cancel
Save