From f37a5ee5d33c962cfdd754f7b8fb933101df6a64 Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 28 Feb 2020 19:52:54 +0800 Subject: [PATCH] Only use sound and music in main process --- src/audio/music_manager.cpp | 4 ++++ src/audio/sfx_manager.cpp | 21 ++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/audio/music_manager.cpp b/src/audio/music_manager.cpp index 2db4623dc..0ce397c46 100644 --- a/src/audio/music_manager.cpp +++ b/src/audio/music_manager.cpp @@ -38,6 +38,7 @@ #include "audio/sfx_openal.hpp" #include "config/user_config.hpp" #include "io/file_manager.hpp" +#include "utils/stk_process.hpp" #include "utils/string_utils.hpp" MusicManager* music_manager= NULL; @@ -180,6 +181,9 @@ void MusicManager::startMusic() */ void MusicManager::startMusic(MusicInformation* mi, bool start_right_now) { + if (STKProcess::getType() != PT_MAIN) + return; + // If this music is already playing, ignore this call. if (m_current_music != NULL && m_current_music == mi && diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index b42112f55..d2b0f9e57 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -24,6 +24,7 @@ #include "io/file_manager.hpp" #include "modes/world.hpp" #include "race/race_manager.hpp" +#include "utils/stk_process.hpp" #include "utils/profiler.hpp" #include "utils/string_utils.hpp" #include "utils/vs.hpp" @@ -185,7 +186,7 @@ SFXManager::~SFXManager() void SFXManager::queue(SFXCommands command, SFXBase *sfx) { #ifdef ENABLE_SOUND - if (!UserConfigParams::m_enable_sound) + if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN) return; SFXCommand *sfx_command = new SFXCommand(command, sfx); @@ -204,7 +205,7 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx) void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f) { #ifdef ENABLE_SOUND - if (!UserConfigParams::m_enable_sound) + if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN) return; SFXCommand *sfx_command = new SFXCommand(command, sfx, f); @@ -223,7 +224,7 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f) void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p) { #ifdef ENABLE_SOUND - if (!UserConfigParams::m_enable_sound) + if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN) return; SFXCommand *sfx_command = new SFXCommand(command, sfx, p); @@ -236,7 +237,7 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p) void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p, SFXBuffer* buffer) { #ifdef ENABLE_SOUND - if (!UserConfigParams::m_enable_sound) + if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN) return; SFXCommand *sfx_command = new SFXCommand(command, sfx, p); @@ -258,7 +259,7 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f, const Vec3 &p) { #ifdef ENABLE_SOUND - if (!UserConfigParams::m_enable_sound) + if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN) return; SFXCommand *sfx_command = new SFXCommand(command, sfx, f, p); @@ -273,7 +274,7 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f, void SFXManager::queue(SFXCommands command, MusicInformation *mi) { #ifdef ENABLE_SOUND - if (!UserConfigParams::m_enable_sound) + if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN) return; SFXCommand *sfx_command = new SFXCommand(command, mi); @@ -289,7 +290,7 @@ void SFXManager::queue(SFXCommands command, MusicInformation *mi) void SFXManager::queue(SFXCommands command, MusicInformation *mi, float f) { #ifdef ENABLE_SOUND - if (!UserConfigParams::m_enable_sound) + if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN) return; SFXCommand *sfx_command = new SFXCommand(command, mi, f); @@ -305,7 +306,7 @@ void SFXManager::queue(SFXCommands command, MusicInformation *mi, float f) void SFXManager::queueCommand(SFXCommand *command) { #ifdef ENABLE_SOUND - if (!UserConfigParams::m_enable_sound) + if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN) return; m_sfx_commands.lock(); @@ -541,6 +542,8 @@ void SFXManager::toggleSound(const bool on) */ bool SFXManager::sfxAllowed() { + if (STKProcess::getType() != PT_MAIN) + return false; if(!UserConfigParams::m_sfx || !m_initialized) return false; else @@ -705,7 +708,7 @@ SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer, SFXBase* sfx = NULL; #ifdef ENABLE_SOUND - if (UserConfigParams::m_enable_sound) + if (UserConfigParams::m_enable_sound && STKProcess::getType() == PT_MAIN) { //assert( alIsBuffer(buffer->getBufferID()) ); crashes on server sfx = new SFXOpenAL(buffer, positional, buffer->getGain(), owns_buffer);