JoltPhysics3D: Skip the rigid body update if no physics step took place
This improves the framerate if FPS > physics rate
This commit is contained in:
parent
72182327dd
commit
f09175228d
|
|
@ -59,15 +59,15 @@ namespace Nz
|
|||
|
||||
void RefreshBodies();
|
||||
|
||||
inline void RegisterStepListener(JoltPhysicsStepListener* character);
|
||||
inline void RegisterStepListener(JoltPhysicsStepListener* stepListener);
|
||||
|
||||
void SetGravity(const Vector3f& gravity);
|
||||
void SetMaxStepCount(std::size_t maxStepCount);
|
||||
void SetStepSize(Time stepSize);
|
||||
|
||||
void Step(Time timestep);
|
||||
bool Step(Time timestep);
|
||||
|
||||
inline void UnregisterStepListener(JoltPhysicsStepListener* character);
|
||||
inline void UnregisterStepListener(JoltPhysicsStepListener* stepListener);
|
||||
|
||||
JoltPhysWorld3D& operator=(const JoltPhysWorld3D&) = delete;
|
||||
JoltPhysWorld3D& operator=(JoltPhysWorld3D&&) = delete;
|
||||
|
|
|
|||
|
|
@ -456,15 +456,17 @@ namespace Nz
|
|||
m_stepSize = stepSize;
|
||||
}
|
||||
|
||||
void JoltPhysWorld3D::Step(Time timestep)
|
||||
bool JoltPhysWorld3D::Step(Time timestep)
|
||||
{
|
||||
m_timestepAccumulator += timestep;
|
||||
if (m_timestepAccumulator < m_stepSize)
|
||||
return false;
|
||||
|
||||
RefreshBodies();
|
||||
|
||||
JPH::JobSystem& jobSystem = JoltPhysics3D::Instance()->GetThreadPool();
|
||||
float stepSize = m_stepSize.AsSeconds<float>();
|
||||
|
||||
m_timestepAccumulator += timestep;
|
||||
|
||||
std::size_t stepCount = 0;
|
||||
while (m_timestepAccumulator >= m_stepSize && stepCount < m_maxStepCount)
|
||||
{
|
||||
|
|
@ -476,6 +478,8 @@ namespace Nz
|
|||
m_timestepAccumulator -= m_stepSize;
|
||||
stepCount++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void JoltPhysWorld3D::RegisterBody(const JPH::BodyID& bodyID, bool activate, bool removeFromDeactivationList)
|
||||
|
|
|
|||
|
|
@ -90,7 +90,8 @@ namespace Nz
|
|||
});
|
||||
|
||||
// Update the physics world
|
||||
m_physWorld.Step(elapsedTime);
|
||||
if (!m_physWorld.Step(elapsedTime))
|
||||
return; // No physics step took place
|
||||
|
||||
// Replicate characters to their NodeComponent
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue