Browse Source

Minimize impact of NOSOUND

pull/2756/head
Anders Jenbo 5 years ago
parent
commit
7cb73a6717
  1. 2
      Source/DiabloUI/diabloui.cpp
  2. 14
      Source/diablo.cpp
  3. 3
      Source/effects.h
  4. 1
      Source/effects_stubs.cpp
  5. 14
      Source/gamemenu.cpp
  6. 2
      Source/monster.cpp
  7. 7
      Source/monster.h
  8. 9
      Source/movie.cpp
  9. 2
      Source/sound.cpp
  10. 10
      Source/sound.h
  11. 5
      Source/sound_stubs.cpp

2
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

14
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 <gperftools/heap-profiler.h>
#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())

3
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

1
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

14
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)

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

7
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<int>(graphic)];
}
#ifndef NOSOUND
std::unique_ptr<TSnd> Snds[4][2];
#endif
uint16_t mMinHP;
uint16_t mMaxHP;
uint8_t mAFNum;

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

2
Source/sound.cpp

@ -184,13 +184,11 @@ std::unique_ptr<TSnd> sound_file_load(const char *path, bool stream)
return snd;
}
#ifndef NOSOUND
TSnd::~TSnd()
{
DSB.Stop();
DSB.Release();
}
#endif
void snd_init()
{

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

5
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<TSnd> 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

Loading…
Cancel
Save