LostArtefacts / TRX

Open source re-implementation of Tomb Raider I and Tomb Raider II, along with additional enhancements and bugfixes
https://lostartefacts.dev/
GNU General Public License v3.0
594 stars 37 forks source link

music: fix the main music playing at the wrong volume with certain sound options #1544

Closed walkawayy closed 1 month ago

walkawayy commented 1 month ago

Fixed quiet or mute main menu music if a level was exited while underwater and the quiet, full but no ambient, quiet but no ambient, or none underwater music behavior option was set.

Resolves #1540.

Checklist

Description

Fixed the main menu music being quiet or mute if a level was exited while underwater and the quiet, full but no ambient, quiet but no ambient, or none underwater music behavior option was set (regression from 4.4). I tried to apply the fix to the volume in a logical place which is where the other config option to mute main menu music is. M_EnsureEnvironment couldn't be called because Game_DrawScene isn't called when in the title menu inventory soCamera_Apply is never called. Might need to be hotfixed though it's not a game breaking issue, and it should be a rare bug.

rr- commented 1 month ago

Thanks. I think that a more fitting place for both this volume fix and the title level music check would be in Level_Initialise, like so:

diff --git a/src/game/level.c b/src/game/level.c
index 42c50c0f..c60f2143 100644
--- a/src/game/level.c
+++ b/src/game/level.c
@@ -1149,11 +1149,14 @@ bool Level_Initialise(int32_t level_num)
     Overlay_BarSetHealthTimer(100);

     Music_Stop();
+    Music_SetVolume(g_Config.music_volume);
     Sound_ResetEffects();

     Viewport_SetFOV(Viewport_GetUserFOV());

-    if (g_GameFlow.levels[level_num].music) {
+    const bool disable_music = level_num == g_GameFlow.title_level_num
+        && !g_Config.enable_music_in_menu;
+    if (g_GameFlow.levels[level_num].music && !disable_music) {
         Music_PlayLooped(g_GameFlow.levels[level_num].music);
     }

diff --git a/src/game/music.c b/src/game/music.c
index c24810a5..382bf82f 100644
--- a/src/game/music.c
+++ b/src/game/music.c
@@ -131,11 +131,6 @@ bool Music_PlayLooped(MUSIC_TRACK_ID track)
         return false;
     }

-    if (g_CurrentLevel == g_GameFlow.title_level_num
-        && !g_Config.enable_music_in_menu) {
-        return false;
-    }
-
     M_StopActiveStream();

     char *file_path = M_GetTrackFileName(track);
walkawayy commented 1 month ago

Ok done. Amended the issue commit and added a second commit which moves the enable_music_in_menu option check to Level_Initialise. This looks much better. I just didn't want to move it without permission lol.