Replace float/UInt64 durations by a more precise Time class (#388)

Improve Clock class with atomic RestartIfOver method and allows to choose required precision
This commit is contained in:
Jérôme Leclercq
2022-12-29 21:31:46 +01:00
committed by GitHub
parent 1de5f65536
commit dd421a6385
84 changed files with 1278 additions and 663 deletions

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/Time.hpp>
#include <Nazara/Math/Angle.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Physics2D/Config.hpp>
@@ -59,7 +60,7 @@ namespace Nz
cpSpace* GetHandle() const;
std::size_t GetIterationCount() const;
std::size_t GetMaxStepCount() const;
float GetStepSize() const;
Time GetStepSize() const;
bool NearestBodyQuery(const Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RigidBody2D** nearestBody = nullptr);
bool NearestBodyQuery(const Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, NearestQueryResult* result);
@@ -78,10 +79,10 @@ namespace Nz
void SetGravity(const Vector2f& gravity);
void SetIterationCount(std::size_t iterationCount);
void SetMaxStepCount(std::size_t maxStepCount);
void SetSleepTime(float sleepTime);
void SetStepSize(float stepSize);
void SetSleepTime(Time sleepTime);
void SetStepSize(Time stepSize);
void Step(float timestep);
void Step(Time timestep);
void UseSpatialHash(float cellSize, std::size_t entityCount);
@@ -156,8 +157,8 @@ namespace Nz
std::unordered_map<cpCollisionHandler*, std::unique_ptr<Callback>> m_callbacks;
std::unordered_map<RigidBody2D*, PostStepContainer> m_rigidPostSteps;
cpSpace* m_handle;
float m_stepSize;
float m_timestepAccumulator;
Time m_stepSize;
Time m_timestepAccumulator;
};
}

View File

@@ -8,6 +8,7 @@
#define NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Time.hpp>
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <Nazara/Physics2D/Components/RigidBody2DComponent.hpp>
#include <Nazara/Utils/TypeList.hpp>
@@ -31,7 +32,7 @@ namespace Nz
inline PhysWorld2D& GetPhysWorld();
inline const PhysWorld2D& GetPhysWorld() const;
void Update(float elapsedTime);
void Update(Time elapsedTime);
Physics2DSystem& operator=(const Physics2DSystem&) = delete;
Physics2DSystem& operator=(Physics2DSystem&&) = delete;