diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index b484d3eb1..d026b559f 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -74,6 +74,7 @@ SFXManager::SFXManager() // The sound manager initialises OpenAL m_initialized = music_manager->initialized(); m_master_gain = UserConfigParams::m_sfx_volume; + m_last_update_time = -1.0f; // Init position, since it can be used before positionListener is called. // No need to use lock here, since the thread will be created later. m_listener_position.getData() = Vec3(0, 0, 0); @@ -669,9 +670,9 @@ void SFXManager::deleteSFXMapping(const std::string &name) * adds an update command for the music manager. * \param dt Time step size. */ -void SFXManager::update(float dt) +void SFXManager::update() { - queue(SFX_UPDATE, (SFXBase*)NULL, dt); + queue(SFX_UPDATE, (SFXBase*)NULL); // Wake up the sfx thread to handle all queued up audio commands. pthread_cond_signal(&m_cond_request); } // update @@ -683,8 +684,17 @@ void SFXManager::update(float dt) */ void SFXManager::reallyUpdateNow(SFXCommand *current) { + if (m_last_update_time < 0.0) + { + // first time + m_last_update_time = StkTime::getRealTime(); + } + + double previous_update_time = m_last_update_time; + m_last_update_time = StkTime::getRealTime(); + double dt = m_last_update_time - previous_update_time; + assert(current->m_command==SFX_UPDATE); - float dt = current->m_parameter.getX(); if (music_manager->getCurrentMusic()) music_manager->getCurrentMusic()->update(dt); m_all_sfx.lock(); diff --git a/src/audio/sfx_manager.hpp b/src/audio/sfx_manager.hpp index 08e939179..a05b0df35 100644 --- a/src/audio/sfx_manager.hpp +++ b/src/audio/sfx_manager.hpp @@ -200,6 +200,8 @@ private: /** Thread id of the thread running in this object. */ Synchronised m_thread_id; + double m_last_update_time; + /** A conditional variable to wake up the main loop. */ pthread_cond_t m_cond_request; @@ -253,7 +255,7 @@ public: void reallyPauseAllNow(); void resumeAll(); void reallyResumeAllNow(); - void update(float dt); + void update(); void reallyUpdateNow(SFXCommand *current); bool soundExist(const std::string &name); void setMasterSFXVolume(float gain);