From aae834ba4b217985b9fd9adbb3b422ae8bc76892 Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 16 Oct 2014 08:13:55 +1100 Subject: [PATCH] Run the music manager from the sfx thread. --- src/audio/sfx_manager.cpp | 16 ++++++++++++++-- src/audio/sfx_manager.hpp | 2 ++ src/main_loop.cpp | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index 079c59714..b836d25ea 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -214,9 +214,19 @@ void SFXManager::queueCommand(SFXCommand *command) m_sfx_commands.getData().push_back(command); m_sfx_commands.unlock(); // Wake up the sfx thread - pthread_cond_signal(&m_cond_request); } // queueCommand +//---------------------------------------------------------------------------- +/** Make sures that the sfx thread is started at least one per frame. It also + * adds an update command for the music manager. + * \param dt Time step size. + */ +void SFXManager::update(float dt) +{ + queue(SFX_UPDATE_MUSIC, NULL, dt); + pthread_cond_signal(&m_cond_request); +} // update + //---------------------------------------------------------------------------- /** Puts a NULL request into the queue, which will trigger the thread to * exit. @@ -279,6 +289,8 @@ void* SFXManager::mainLoop(void *obj) me->deleteSFX(current->m_sfx); break; } case SFX_LISTENER: me->reallyPositionListenerNow(); break; + case SFX_UPDATE_MUSIC: music_manager->update( + current->m_parameter.getX()); break; default: assert("Not yet supported."); } delete current; @@ -326,7 +338,7 @@ void SFXManager::soundToggled(const bool on) { pauseAll(); } -} +} // soundToggled //---------------------------------------------------------------------------- /** Returns if sfx can be played. This means sfx are enabled and diff --git a/src/audio/sfx_manager.hpp b/src/audio/sfx_manager.hpp index 6d5d2e542..eb41f701c 100644 --- a/src/audio/sfx_manager.hpp +++ b/src/audio/sfx_manager.hpp @@ -71,6 +71,7 @@ public: SFX_POSITION, SFX_VOLUME, SFX_LISTENER, + SFX_UPDATE_MUSIC, SFX_EXIT, }; // SFXCommands @@ -213,6 +214,7 @@ public: void deleteSFXMapping(const std::string &name); void pauseAll(); void resumeAll(); + void update(float dt); bool soundExist(const std::string &name); void setMasterSFXVolume(float gain); float getMasterSFXVolume() const { return m_master_gain; } diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 216bdcbc6..4e7bccff0 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -21,7 +21,7 @@ #include -#include "audio/music_manager.hpp" +#include "audio/sfx_manager.hpp" #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" #include "graphics/material_manager.hpp" @@ -138,7 +138,7 @@ void MainLoop::run() if (!m_abort && !ProfileWorld::isNoGraphics()) { PROFILER_PUSH_CPU_MARKER("Music/input/GUI", 0x7F, 0x00, 0x00); - music_manager->update(dt); + SFXManager::get()->update(dt); input_manager->update(dt); #ifdef ENABLE_WIIUSE