]> git.lizzy.rs Git - minetest.git/commitdiff
Get rid of global dummySoundManager
authorDesour <ds.desour@proton.me>
Mon, 10 Apr 2023 16:59:01 +0000 (18:59 +0200)
committerDS <ds.desour@proton.me>
Tue, 11 Apr 2023 18:06:15 +0000 (20:06 +0200)
There is no need for this to be globally unique.

src/client/CMakeLists.txt
src/client/game.cpp
src/client/sound.cpp [deleted file]
src/client/sound.h

index 7aa43d19884a05eebe7d0f07603682894ae57403..7b910d0279fbc8fbfdc6f2c1544349b4fc78491e 100644 (file)
@@ -1,4 +1,4 @@
-set(sound_SRCS  ${CMAKE_CURRENT_SOURCE_DIR}/sound.cpp)
+set(sound_SRCS "")
 
 if(USE_SOUND)
        set(sound_SRCS ${sound_SRCS}
index 426fbc453efc9a670a45d5ccffade3d6bd56ca35..ac87fc9c70da220e1516cf2d22c2fb6f2557bfbe 100644 (file)
@@ -936,8 +936,7 @@ class Game {
        NodeDefManager *nodedef_manager = nullptr;
 
        GameOnDemandSoundFetcher soundfetcher; // useful when testing
-       ISoundManager *sound = nullptr;
-       bool sound_is_dummy = false;
+       std::unique_ptr<ISoundManager> sound_manager;
        SoundMaker *soundmaker = nullptr;
 
        ChatBackend *chat_backend = nullptr;
@@ -1074,8 +1073,7 @@ Game::~Game()
 {
        delete client;
        delete soundmaker;
-       if (!sound_is_dummy)
-               delete sound;
+       sound_manager.reset();
 
        delete server; // deleted first to stop all server threads
 
@@ -1380,20 +1378,19 @@ bool Game::initSound()
 #if USE_SOUND
        if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) {
                infostream << "Attempting to use OpenAL audio" << std::endl;
-               sound = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher);
-               if (!sound)
+               sound_manager.reset(createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher));
+               if (!sound_manager)
                        infostream << "Failed to initialize OpenAL audio" << std::endl;
        } else
                infostream << "Sound disabled." << std::endl;
 #endif
 
-       if (!sound) {
+       if (!sound_manager) {
                infostream << "Using dummy audio." << std::endl;
-               sound = &dummySoundManager;
-               sound_is_dummy = true;
+               sound_manager = std::make_unique<DummySoundManager>();
        }
 
-       soundmaker = new SoundMaker(sound, nodedef_manager);
+       soundmaker = new SoundMaker(sound_manager.get(), nodedef_manager);
        if (!soundmaker)
                return false;
 
@@ -1609,7 +1606,7 @@ bool Game::connectToServer(const GameStartData &start_data,
                client = new Client(start_data.name.c_str(),
                                start_data.password, start_data.address,
                                *draw_control, texture_src, shader_src,
-                               itemdef_manager, nodedef_manager, sound, eventmgr,
+                               itemdef_manager, nodedef_manager, sound_manager.get(), eventmgr,
                                m_rendering_engine, connect_address.isIPv6(), m_game_ui.get(),
                                start_data.allow_login_or_register);
                client->migrateModStorage();
@@ -2211,7 +2208,8 @@ void Game::openInventory()
        TextDest *txt_dst = new TextDestPlayerInventory(client);
        auto *&formspec = m_game_ui->updateFormspec("");
        GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
-               &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
+               &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(),
+               sound_manager.get());
 
        formspec->setFormSpec(fs_src->getForm(), inventoryloc);
 }
@@ -2816,7 +2814,8 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation
 
                auto *&formspec = m_game_ui->updateFormspec(*(event->show_formspec.formname));
                GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
-                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
+                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(),
+                       sound_manager.get());
        }
 
        delete event->show_formspec.formspec;
@@ -2829,7 +2828,7 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta
        LocalFormspecHandler *txt_dst =
                new LocalFormspecHandler(*event->show_formspec.formname, client);
        GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, m_rendering_engine->get_gui_env(),
-                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
+                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound_manager.get());
 
        delete event->show_formspec.formspec;
        delete event->show_formspec.formname;
@@ -3164,19 +3163,20 @@ void Game::updateSound(f32 dtime)
 {
        // Update sound listener
        v3s16 camera_offset = camera->getOffset();
-       sound->updateListener(camera->getCameraNode()->getPosition() + intToFloat(camera_offset, BS),
-                             v3f(0, 0, 0), // velocity
-                             camera->getDirection(),
-                             camera->getCameraNode()->getUpVector());
+       sound_manager->updateListener(
+                       camera->getCameraNode()->getPosition() + intToFloat(camera_offset, BS),
+                       v3f(0, 0, 0), // velocity
+                       camera->getDirection(),
+                       camera->getCameraNode()->getUpVector());
 
        bool mute_sound = g_settings->getBool("mute_sound");
        if (mute_sound) {
-               sound->setListenerGain(0.0f);
+               sound_manager->setListenerGain(0.0f);
        } else {
                // 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);
+               sound_manager->setListenerGain(new_volume);
 
                if (old_volume != new_volume) {
                        g_settings->setFloat("sound_volume", new_volume);
@@ -3548,7 +3548,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
 
                auto *&formspec = m_game_ui->updateFormspec("");
                GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
-                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
+                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(),
+                       sound_manager.get());
 
                formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
                return false;
@@ -4324,7 +4325,8 @@ void Game::showDeathFormspec()
 
        auto *&formspec = m_game_ui->getFormspecGUI();
        GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
-               &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
+               &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(),
+               sound_manager.get());
        formspec->setFocus("btn_respawn");
 }
 
@@ -4460,7 +4462,8 @@ void Game::showPauseMenu()
 
        auto *&formspec = m_game_ui->getFormspecGUI();
        GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
-                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
+                       &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(),
+                       sound_manager.get());
        formspec->setFocus("btn_continue");
        // game will be paused in next step, if in singleplayer (see m_is_paused)
        formspec->doPause = true;
diff --git a/src/client/sound.cpp b/src/client/sound.cpp
deleted file mode 100644 (file)
index 44a96dd..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
-Minetest
-Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "sound.h"
-
-// Global DummySoundManager singleton
-DummySoundManager dummySoundManager;
index 213d208316e6aed1940b01ccb4017420aff379db..4de63ec65faf1bbabb179ac36b28ab8b5c6b11bc 100644 (file)
@@ -88,6 +88,3 @@ class DummySoundManager : public ISoundManager
        void step(float dtime) {}
        void fadeSound(int sound, float step, float gain) {}
 };
-
-// Global DummySoundManager singleton
-extern DummySoundManager dummySoundManager;