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

@@ -8,6 +8,7 @@
#define NAZARA_CORE_COMPONENTS_LIFETIMECOMPONENT_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Time.hpp>
#include <Nazara/Utility/Config.hpp>
namespace Nz
@@ -15,14 +16,14 @@ namespace Nz
class LifetimeComponent
{
public:
inline LifetimeComponent(float lifetime);
inline LifetimeComponent(Time lifetime);
LifetimeComponent(const LifetimeComponent&) = default;
LifetimeComponent(LifetimeComponent&&) = default;
~LifetimeComponent() = default;
inline void DecreaseLifetime(float elapsedTime);
inline void DecreaseLifetime(Time elapsedTime);
inline float GetRemainingLifeTime() const;
inline Time GetRemainingLifeTime() const;
inline bool IsAlive() const;
@@ -30,7 +31,7 @@ namespace Nz
LifetimeComponent& operator=(LifetimeComponent&&) = default;
private:
float m_remainingLifetime;
Time m_remainingLifetime;
};
}

View File

@@ -7,24 +7,24 @@
namespace Nz
{
inline LifetimeComponent::LifetimeComponent(float lifetime) :
inline LifetimeComponent::LifetimeComponent(Time lifetime) :
m_remainingLifetime(lifetime)
{
}
inline void LifetimeComponent::DecreaseLifetime(float elapsedTime)
inline void LifetimeComponent::DecreaseLifetime(Time elapsedTime)
{
m_remainingLifetime -= elapsedTime;
}
inline float LifetimeComponent::GetRemainingLifeTime() const
inline Time LifetimeComponent::GetRemainingLifeTime() const
{
return m_remainingLifetime;
}
inline bool LifetimeComponent::IsAlive() const
{
return m_remainingLifetime >= 0.f;
return m_remainingLifetime >= Time::Zero();
}
}