diff --git a/include/Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp b/include/Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp index 6994e62ae..e5143e037 100644 --- a/include/Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp +++ b/include/Nazara/JoltPhysics3D/JoltPhysWorld3D.hpp @@ -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; diff --git a/src/Nazara/JoltPhysics3D/JoltPhysWorld3D.cpp b/src/Nazara/JoltPhysics3D/JoltPhysWorld3D.cpp index fef957a92..941b4307b 100644 --- a/src/Nazara/JoltPhysics3D/JoltPhysWorld3D.cpp +++ b/src/Nazara/JoltPhysics3D/JoltPhysWorld3D.cpp @@ -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(); - 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) diff --git a/src/Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.cpp b/src/Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.cpp index 8b1309b9f..1508a68cf 100644 --- a/src/Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.cpp +++ b/src/Nazara/JoltPhysics3D/Systems/JoltPhysics3DSystem.cpp @@ -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 {