Only use sound and music in main process

This commit is contained in:
Benau 2020-02-28 19:52:54 +08:00
parent 885aec8020
commit f37a5ee5d3
2 changed files with 16 additions and 9 deletions

View File

@ -38,6 +38,7 @@
#include "audio/sfx_openal.hpp" #include "audio/sfx_openal.hpp"
#include "config/user_config.hpp" #include "config/user_config.hpp"
#include "io/file_manager.hpp" #include "io/file_manager.hpp"
#include "utils/stk_process.hpp"
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"
MusicManager* music_manager= NULL; MusicManager* music_manager= NULL;
@ -180,6 +181,9 @@ void MusicManager::startMusic()
*/ */
void MusicManager::startMusic(MusicInformation* mi, bool start_right_now) 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 this music is already playing, ignore this call.
if (m_current_music != NULL && if (m_current_music != NULL &&
m_current_music == mi && m_current_music == mi &&

View File

@ -24,6 +24,7 @@
#include "io/file_manager.hpp" #include "io/file_manager.hpp"
#include "modes/world.hpp" #include "modes/world.hpp"
#include "race/race_manager.hpp" #include "race/race_manager.hpp"
#include "utils/stk_process.hpp"
#include "utils/profiler.hpp" #include "utils/profiler.hpp"
#include "utils/string_utils.hpp" #include "utils/string_utils.hpp"
#include "utils/vs.hpp" #include "utils/vs.hpp"
@ -185,7 +186,7 @@ SFXManager::~SFXManager()
void SFXManager::queue(SFXCommands command, SFXBase *sfx) void SFXManager::queue(SFXCommands command, SFXBase *sfx)
{ {
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (!UserConfigParams::m_enable_sound) if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN)
return; return;
SFXCommand *sfx_command = new SFXCommand(command, sfx); 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) void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f)
{ {
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (!UserConfigParams::m_enable_sound) if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN)
return; return;
SFXCommand *sfx_command = new SFXCommand(command, sfx, f); 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) void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p)
{ {
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (!UserConfigParams::m_enable_sound) if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN)
return; return;
SFXCommand *sfx_command = new SFXCommand(command, sfx, p); 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) void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p, SFXBuffer* buffer)
{ {
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (!UserConfigParams::m_enable_sound) if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN)
return; return;
SFXCommand *sfx_command = new SFXCommand(command, sfx, p); SFXCommand *sfx_command = new SFXCommand(command, sfx, p);
@ -258,7 +259,7 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, float f,
const Vec3 &p) const Vec3 &p)
{ {
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (!UserConfigParams::m_enable_sound) if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN)
return; return;
SFXCommand *sfx_command = new SFXCommand(command, sfx, f, p); 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) void SFXManager::queue(SFXCommands command, MusicInformation *mi)
{ {
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (!UserConfigParams::m_enable_sound) if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN)
return; return;
SFXCommand *sfx_command = new SFXCommand(command, mi); 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) void SFXManager::queue(SFXCommands command, MusicInformation *mi, float f)
{ {
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (!UserConfigParams::m_enable_sound) if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN)
return; return;
SFXCommand *sfx_command = new SFXCommand(command, mi, f); 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) void SFXManager::queueCommand(SFXCommand *command)
{ {
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (!UserConfigParams::m_enable_sound) if (!UserConfigParams::m_enable_sound || STKProcess::getType() != PT_MAIN)
return; return;
m_sfx_commands.lock(); m_sfx_commands.lock();
@ -541,6 +542,8 @@ void SFXManager::toggleSound(const bool on)
*/ */
bool SFXManager::sfxAllowed() bool SFXManager::sfxAllowed()
{ {
if (STKProcess::getType() != PT_MAIN)
return false;
if(!UserConfigParams::m_sfx || !m_initialized) if(!UserConfigParams::m_sfx || !m_initialized)
return false; return false;
else else
@ -705,7 +708,7 @@ SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer,
SFXBase* sfx = NULL; SFXBase* sfx = NULL;
#ifdef ENABLE_SOUND #ifdef ENABLE_SOUND
if (UserConfigParams::m_enable_sound) if (UserConfigParams::m_enable_sound && STKProcess::getType() == PT_MAIN)
{ {
//assert( alIsBuffer(buffer->getBufferID()) ); crashes on server //assert( alIsBuffer(buffer->getBufferID()) ); crashes on server
sfx = new SFXOpenAL(buffer, positional, buffer->getGain(), owns_buffer); sfx = new SFXOpenAL(buffer, positional, buffer->getGain(), owns_buffer);