Run the music manager from the sfx thread.

This commit is contained in:
hiker 2014-10-16 08:13:55 +11:00
parent 09f8ffb16e
commit aae834ba4b
3 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -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; }

View File

@ -21,7 +21,7 @@
#include <assert.h>
#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