Only issue sfx commands once per rendered frame (during the last
substep).
This commit is contained in:
parent
c7bc47f2e3
commit
fa20e4f866
@ -60,6 +60,7 @@
|
||||
#include "karts/max_speed.hpp"
|
||||
#include "karts/rescue_animation.hpp"
|
||||
#include "karts/skidding.hpp"
|
||||
#include "main_loop.hpp"
|
||||
#include "modes/overworld.hpp"
|
||||
#include "modes/soccer_world.hpp"
|
||||
#include "modes/world.hpp"
|
||||
@ -1755,7 +1756,7 @@ void Kart::handleMaterialSFX(const Material *material)
|
||||
|
||||
// terrain sound is not necessarily a looping sound so check its status before
|
||||
// setting its speed, to avoid 'ressuscitating' sounds that had already stopped
|
||||
if(m_terrain_sound &&
|
||||
if(m_terrain_sound && main_loop->isLstSubstep() &&
|
||||
(m_terrain_sound->getStatus()==SFXBase::SFX_PLAYING ||
|
||||
m_terrain_sound->getStatus()==SFXBase::SFX_PAUSED))
|
||||
{
|
||||
@ -2387,10 +2388,13 @@ void Kart::updatePhysics(float dt)
|
||||
*/
|
||||
void Kart::updateEngineSFX(float dt)
|
||||
{
|
||||
// when going faster, use higher pitch for engine
|
||||
if(!m_engine_sound || !SFXManager::get()->sfxAllowed())
|
||||
// Only update SFX during the last substep (otherwise too many SFX commands
|
||||
// in one frame), and if sfx are enabled
|
||||
if(!m_engine_sound || !SFXManager::get()->sfxAllowed() ||
|
||||
!main_loop->isLstSubstep() )
|
||||
return;
|
||||
|
||||
// when going faster, use higher pitch for engine
|
||||
if(isOnGround())
|
||||
{
|
||||
float max_speed = m_kart_properties->getEngineMaxSpeed();
|
||||
|
@ -45,9 +45,10 @@ MainLoop* main_loop = 0;
|
||||
MainLoop::MainLoop() :
|
||||
m_abort(false)
|
||||
{
|
||||
m_curr_time = 0;
|
||||
m_prev_time = 0;
|
||||
m_throttle_fps = true;
|
||||
m_curr_time = 0;
|
||||
m_prev_time = 0;
|
||||
m_throttle_fps = true;
|
||||
m_is_last_substep = false;
|
||||
} // MainLoop
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -232,6 +233,7 @@ void MainLoop::run()
|
||||
float left_over_time = 0;
|
||||
while(!m_abort)
|
||||
{
|
||||
m_is_last_substep = false;
|
||||
PROFILER_PUSH_CPU_MARKER("Main loop", 0xFF, 0x00, 0xF7);
|
||||
|
||||
left_over_time += getLimitedDt();
|
||||
@ -267,6 +269,9 @@ void MainLoop::run()
|
||||
|
||||
for(int i=0; i<num_steps; i++)
|
||||
{
|
||||
// Enable last substep in last iteration
|
||||
m_is_last_substep = (i == num_steps - 1);
|
||||
|
||||
PROFILER_PUSH_CPU_MARKER("Update race", 0, 255, 255);
|
||||
if (World::getWorld()) updateRace(dt);
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
@ -290,7 +295,7 @@ void MainLoop::run()
|
||||
|
||||
if (World::getWorld()) World::getWorld()->updateTime(dt);
|
||||
} // while dt > time_step_size
|
||||
|
||||
m_is_last_substep = false;
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
PROFILER_SYNC_FRAME();
|
||||
} // while !m_abort
|
||||
|
@ -34,6 +34,10 @@ private:
|
||||
/** True if the frame rate should be throttled. */
|
||||
bool m_throttle_fps;
|
||||
|
||||
/** True during the last substep of the inner main loop (where world
|
||||
* is updated). Used to reduce amount of updates (e.g. sfx positions
|
||||
* etc). */
|
||||
bool m_is_last_substep;
|
||||
Uint32 m_curr_time;
|
||||
Uint32 m_prev_time;
|
||||
float getLimitedDt();
|
||||
@ -47,6 +51,10 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if STK is to be stoppe. */
|
||||
bool isAborted() const { return m_abort; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns if this is the last substep. Used to reduce the amount
|
||||
* of updates (e.g. to sfx position) to once per rendered frame. */
|
||||
bool isLstSubstep() const { return m_is_last_substep; }
|
||||
}; // MainLoop
|
||||
|
||||
extern MainLoop* main_loop;
|
||||
|
Loading…
x
Reference in New Issue
Block a user