Limit properly the sound setting at updateSound runtime step (#5753)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 13 May 2017 10:03:11 +0000 (12:03 +0200)
committerGitHub <noreply@github.com>
Sat, 13 May 2017 10:03:11 +0000 (12:03 +0200)
* Limit properly the sound setting at updateSound runtime step

Fix #5026

* Add a comment

src/game.cpp
src/guiVolumeChange.cpp

index ab8eb5c704b321b3ec0a7e0cc226e4ee1fb67554..f237a87aad09ba85bc5e13942b65696f868a9d32 100644 (file)
@@ -3444,7 +3444,15 @@ void Game::updateSound(f32 dtime)
                              v3f(0, 0, 0), // velocity
                              camera->getDirection(),
                              camera->getCameraNode()->getUpVector());
-       sound->setListenerGain(g_settings->getFloat("sound_volume"));
+
+       // Check if volume is in the proper range, else fix it.
+       float old_volume = g_settings->getFloat("sound_volume");
+       float new_volume = rangelim(old_volume, 0.0f, 1.0f);
+       sound->setListenerGain(new_volume);
+
+       if (old_volume != new_volume) {
+               g_settings->setFloat("sound_volume", new_volume);
+       }
 
        LocalPlayer *player = client->getEnv().getLocalPlayer();
 
index 8425bc04f18fbc69ceabc9b9ad7ae1825359cedc..cdb70b4bf77bc15358800a6bf47db2c591177e3d 100644 (file)
@@ -69,7 +69,7 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
                Remove stuff
        */
        removeChildren();
-       
+
        /*
                Calculate new sizes and positions
        */
@@ -79,12 +79,11 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
                        screensize.X/2 + 380/2,
                        screensize.Y/2 + 200/2
        );
-       
+
        DesiredRect = rect;
        recalculateAbsolutePosition(false);
 
        v2s32 size = rect.getSize();
-       v2s32 topleft_client(40, 0);
        int volume = (int)(g_settings->getFloat("sound_volume")*100);
        /*
                Add stuff