From 71c8c543134927be694e777fccefd34c0b94f9db Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 10 Oct 2020 23:42:02 -0700 Subject: [PATCH] Clean up music handling to one place Previously, setting the actual volume of the music was all over the place. Which isn't bad, but when I added being able to press N to mute the music specifically, I should've made it so that there would be a volume variable somewhere that the game looks at if the music is unmuted, and otherwise sets the actual volume to 0 if the game is muted. This resulted in things like #400 and #505 and having to add a bunch of special-cased checks like game.musicmuted and game.completestop. But instead of adding a bunch of special-case code, just make it so there's a central place where Mix_VolumeMusic() actually gets called, and if some piece of code wants to set the music volume, they can set music.musicVolume. But the music handling logic in main.cpp gets the final say on whether to listen to music.musicVolume, or to mute the game entirely. This is how the music handling code should have been from the start (when pressing N to mute the music was added). Fixes #505. --- desktop_version/src/Music.cpp | 4 +--- desktop_version/src/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 61d6712a..ad21990b 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -177,7 +177,7 @@ void musicclass::play(int t, const double position_sec /*= 0.0*/, const int fade t += num_mmmmmm_tracks; } safeToProcessMusic = true; - Mix_VolumeMusic(MIX_MAX_VOLUME); + musicVolume = MIX_MAX_VOLUME; if (currentsong !=t) { if (t != -1) @@ -246,7 +246,6 @@ void musicclass::haltdasmusik() void musicclass::silencedasmusik() { - Mix_VolumeMusic(0) ; musicVolume = 0; } @@ -265,7 +264,6 @@ void musicclass::fadeout() void musicclass::processmusicfadein() { musicVolume += FadeVolAmountPerFrame; - Mix_VolumeMusic(musicVolume); if (musicVolume >= MIX_MAX_VOLUME) { m_doFadeInVol = false; diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 1160c46c..d9410981 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -657,13 +657,13 @@ void inline fixedloop() { Mix_Volume(-1,MIX_MAX_VOLUME); - if (game.musicmuted || game.completestop) + if (game.musicmuted) { Mix_VolumeMusic(0); } else { - Mix_VolumeMusic(MIX_MAX_VOLUME); + Mix_VolumeMusic(music.musicVolume); } }