mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 03:23:45 +01:00
Get rid of global dummySoundManager
There is no need for this to be globally unique.
This commit is contained in:
parent
b201c03625
commit
1dd13da37d
@ -1,4 +1,4 @@
|
|||||||
set(sound_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/sound.cpp)
|
set(sound_SRCS "")
|
||||||
|
|
||||||
if(USE_SOUND)
|
if(USE_SOUND)
|
||||||
set(sound_SRCS ${sound_SRCS}
|
set(sound_SRCS ${sound_SRCS}
|
||||||
|
@ -936,8 +936,7 @@ private:
|
|||||||
NodeDefManager *nodedef_manager = nullptr;
|
NodeDefManager *nodedef_manager = nullptr;
|
||||||
|
|
||||||
GameOnDemandSoundFetcher soundfetcher; // useful when testing
|
GameOnDemandSoundFetcher soundfetcher; // useful when testing
|
||||||
ISoundManager *sound = nullptr;
|
std::unique_ptr<ISoundManager> sound_manager;
|
||||||
bool sound_is_dummy = false;
|
|
||||||
SoundMaker *soundmaker = nullptr;
|
SoundMaker *soundmaker = nullptr;
|
||||||
|
|
||||||
ChatBackend *chat_backend = nullptr;
|
ChatBackend *chat_backend = nullptr;
|
||||||
@ -1074,8 +1073,7 @@ Game::~Game()
|
|||||||
{
|
{
|
||||||
delete client;
|
delete client;
|
||||||
delete soundmaker;
|
delete soundmaker;
|
||||||
if (!sound_is_dummy)
|
sound_manager.reset();
|
||||||
delete sound;
|
|
||||||
|
|
||||||
delete server; // deleted first to stop all server threads
|
delete server; // deleted first to stop all server threads
|
||||||
|
|
||||||
@ -1380,20 +1378,19 @@ bool Game::initSound()
|
|||||||
#if USE_SOUND
|
#if USE_SOUND
|
||||||
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) {
|
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) {
|
||||||
infostream << "Attempting to use OpenAL audio" << std::endl;
|
infostream << "Attempting to use OpenAL audio" << std::endl;
|
||||||
sound = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher);
|
sound_manager.reset(createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher));
|
||||||
if (!sound)
|
if (!sound_manager)
|
||||||
infostream << "Failed to initialize OpenAL audio" << std::endl;
|
infostream << "Failed to initialize OpenAL audio" << std::endl;
|
||||||
} else
|
} else
|
||||||
infostream << "Sound disabled." << std::endl;
|
infostream << "Sound disabled." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!sound) {
|
if (!sound_manager) {
|
||||||
infostream << "Using dummy audio." << std::endl;
|
infostream << "Using dummy audio." << std::endl;
|
||||||
sound = &dummySoundManager;
|
sound_manager = std::make_unique<DummySoundManager>();
|
||||||
sound_is_dummy = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
soundmaker = new SoundMaker(sound, nodedef_manager);
|
soundmaker = new SoundMaker(sound_manager.get(), nodedef_manager);
|
||||||
if (!soundmaker)
|
if (!soundmaker)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1609,7 +1606,7 @@ bool Game::connectToServer(const GameStartData &start_data,
|
|||||||
client = new Client(start_data.name.c_str(),
|
client = new Client(start_data.name.c_str(),
|
||||||
start_data.password, start_data.address,
|
start_data.password, start_data.address,
|
||||||
*draw_control, texture_src, shader_src,
|
*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(),
|
m_rendering_engine, connect_address.isIPv6(), m_game_ui.get(),
|
||||||
start_data.allow_login_or_register);
|
start_data.allow_login_or_register);
|
||||||
client->migrateModStorage();
|
client->migrateModStorage();
|
||||||
@ -2211,7 +2208,8 @@ void Game::openInventory()
|
|||||||
TextDest *txt_dst = new TextDestPlayerInventory(client);
|
TextDest *txt_dst = new TextDestPlayerInventory(client);
|
||||||
auto *&formspec = m_game_ui->updateFormspec("");
|
auto *&formspec = m_game_ui->updateFormspec("");
|
||||||
GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
|
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);
|
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));
|
auto *&formspec = m_game_ui->updateFormspec(*(event->show_formspec.formname));
|
||||||
GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
|
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;
|
delete event->show_formspec.formspec;
|
||||||
@ -2829,7 +2828,7 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta
|
|||||||
LocalFormspecHandler *txt_dst =
|
LocalFormspecHandler *txt_dst =
|
||||||
new LocalFormspecHandler(*event->show_formspec.formname, client);
|
new LocalFormspecHandler(*event->show_formspec.formname, client);
|
||||||
GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, m_rendering_engine->get_gui_env(),
|
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.formspec;
|
||||||
delete event->show_formspec.formname;
|
delete event->show_formspec.formname;
|
||||||
@ -3164,19 +3163,20 @@ void Game::updateSound(f32 dtime)
|
|||||||
{
|
{
|
||||||
// Update sound listener
|
// Update sound listener
|
||||||
v3s16 camera_offset = camera->getOffset();
|
v3s16 camera_offset = camera->getOffset();
|
||||||
sound->updateListener(camera->getCameraNode()->getPosition() + intToFloat(camera_offset, BS),
|
sound_manager->updateListener(
|
||||||
v3f(0, 0, 0), // velocity
|
camera->getCameraNode()->getPosition() + intToFloat(camera_offset, BS),
|
||||||
camera->getDirection(),
|
v3f(0, 0, 0), // velocity
|
||||||
camera->getCameraNode()->getUpVector());
|
camera->getDirection(),
|
||||||
|
camera->getCameraNode()->getUpVector());
|
||||||
|
|
||||||
bool mute_sound = g_settings->getBool("mute_sound");
|
bool mute_sound = g_settings->getBool("mute_sound");
|
||||||
if (mute_sound) {
|
if (mute_sound) {
|
||||||
sound->setListenerGain(0.0f);
|
sound_manager->setListenerGain(0.0f);
|
||||||
} else {
|
} else {
|
||||||
// Check if volume is in the proper range, else fix it.
|
// Check if volume is in the proper range, else fix it.
|
||||||
float old_volume = g_settings->getFloat("sound_volume");
|
float old_volume = g_settings->getFloat("sound_volume");
|
||||||
float new_volume = rangelim(old_volume, 0.0f, 1.0f);
|
float new_volume = rangelim(old_volume, 0.0f, 1.0f);
|
||||||
sound->setListenerGain(new_volume);
|
sound_manager->setListenerGain(new_volume);
|
||||||
|
|
||||||
if (old_volume != new_volume) {
|
if (old_volume != new_volume) {
|
||||||
g_settings->setFloat("sound_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("");
|
auto *&formspec = m_game_ui->updateFormspec("");
|
||||||
GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
|
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);
|
formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
|
||||||
return false;
|
return false;
|
||||||
@ -4324,7 +4325,8 @@ void Game::showDeathFormspec()
|
|||||||
|
|
||||||
auto *&formspec = m_game_ui->getFormspecGUI();
|
auto *&formspec = m_game_ui->getFormspecGUI();
|
||||||
GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
|
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");
|
formspec->setFocus("btn_respawn");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4460,7 +4462,8 @@ void Game::showPauseMenu()
|
|||||||
|
|
||||||
auto *&formspec = m_game_ui->getFormspecGUI();
|
auto *&formspec = m_game_ui->getFormspecGUI();
|
||||||
GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
|
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");
|
formspec->setFocus("btn_continue");
|
||||||
// game will be paused in next step, if in singleplayer (see m_is_paused)
|
// game will be paused in next step, if in singleplayer (see m_is_paused)
|
||||||
formspec->doPause = true;
|
formspec->doPause = true;
|
||||||
|
@ -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;
|
|
@ -88,6 +88,3 @@ public:
|
|||||||
void step(float dtime) {}
|
void step(float dtime) {}
|
||||||
void fadeSound(int sound, float step, float gain) {}
|
void fadeSound(int sound, float step, float gain) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Global DummySoundManager singleton
|
|
||||||
extern DummySoundManager dummySoundManager;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user