Plasma Engine  2.0
Loading...
Searching...
No Matches
Time.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Configuration/StaticSubSystem.h>
5
11struct PL_FOUNDATION_DLL plTime
12{
13public:
15 static plTime Now(); // [tested]
16
18 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime MakeFromNanoseconds(double fNanoseconds) { return plTime(fNanoseconds * 0.000000001); }
19 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime Nanoseconds(double fNanoseconds) { return plTime(fNanoseconds * 0.000000001); }
20
22 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime MakeFromMicroseconds(double fMicroseconds) { return plTime(fMicroseconds * 0.000001); }
23 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime Microseconds(double fMicroseconds) { return plTime(fMicroseconds * 0.000001); }
24
26 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime MakeFromMilliseconds(double fMilliseconds) { return plTime(fMilliseconds * 0.001); }
27 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime Milliseconds(double fMilliseconds) { return plTime(fMilliseconds * 0.001); }
28
30 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime MakeFromSeconds(double fSeconds) { return plTime(fSeconds); }
31 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime Seconds(double fSeconds) { return plTime(fSeconds); }
32
34 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime MakeFromMinutes(double fMinutes) { return plTime(fMinutes * 60); }
35 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime Minutes(double fMinutes) { return plTime(fMinutes * 60); }
36
38 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime MakeFromHours(double fHours) { return plTime(fHours * 60 * 60); }
39 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime Hours(double fHours) { return plTime(fHours * 60 * 60); }
40
42 [[nodiscard]] PL_ALWAYS_INLINE constexpr static plTime MakeZero() { return plTime(0.0); }
43
44 PL_DECLARE_POD_TYPE();
45
47 PL_ALWAYS_INLINE constexpr plTime() = default;
48
50 PL_ALWAYS_INLINE constexpr bool IsZero() const { return m_fTime == 0.0; }
51
53 PL_ALWAYS_INLINE constexpr bool IsNegative() const { return m_fTime < 0.0; }
54
56 PL_ALWAYS_INLINE constexpr bool IsPositive() const { return m_fTime > 0.0; }
57
59 PL_ALWAYS_INLINE constexpr bool IsZeroOrNegative() const { return m_fTime <= 0.0; }
60
62 PL_ALWAYS_INLINE constexpr bool IsZeroOrPositive() const { return m_fTime >= 0.0; }
63
69 constexpr float AsFloatInSeconds() const;
70
72 constexpr double GetNanoseconds() const;
73
75 constexpr double GetMicroseconds() const;
76
78 constexpr double GetMilliseconds() const;
79
81 constexpr double GetSeconds() const;
82
84 constexpr double GetMinutes() const;
85
87 constexpr double GetHours() const;
88
90 constexpr void operator-=(const plTime& other);
91
93 constexpr void operator+=(const plTime& other);
94
96 constexpr void operator*=(double fFactor);
97
99 constexpr void operator/=(double fFactor);
100
102 constexpr plTime operator-(const plTime& other) const;
103
105 constexpr plTime operator+(const plTime& other) const;
106
107 constexpr plTime operator-() const;
108
109 constexpr bool operator<(const plTime& rhs) const { return m_fTime < rhs.m_fTime; }
110 constexpr bool operator<=(const plTime& rhs) const { return m_fTime <= rhs.m_fTime; }
111 constexpr bool operator>(const plTime& rhs) const { return m_fTime > rhs.m_fTime; }
112 constexpr bool operator>=(const plTime& rhs) const { return m_fTime >= rhs.m_fTime; }
113 constexpr bool operator==(const plTime& rhs) const { return m_fTime == rhs.m_fTime; }
114 constexpr bool operator!=(const plTime& rhs) const { return m_fTime != rhs.m_fTime; }
115
116private:
118 constexpr explicit plTime(double fTime);
119
121 double m_fTime = 0.0;
122
123private:
124 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(Foundation, Time);
125
126 static void Initialize();
127};
128
129constexpr plTime operator*(plTime t, double f);
130constexpr plTime operator*(double f, plTime t);
131constexpr plTime operator*(plTime f, plTime t); // not physically correct, but useful (should result in seconds squared)
132
133constexpr plTime operator/(plTime t, double f);
134constexpr plTime operator/(double f, plTime t);
135constexpr plTime operator/(plTime f, plTime t); // not physically correct, but useful (should result in a value without a unit)
136
137
138#include <Foundation/Time/Implementation/Time_inl.h>
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
PL_ALWAYS_INLINE constexpr bool IsPositive() const
Checks for a positive time value. This does not include zero.
Definition Time.h:56
PL_ALWAYS_INLINE static constexpr plTime MakeFromMilliseconds(double fMilliseconds)
Creates an instance of plTime that was initialized from milliseconds.
Definition Time.h:26
PL_ALWAYS_INLINE constexpr bool IsZeroOrNegative() const
Returns true if the stored time is zero or negative.
Definition Time.h:59
PL_ALWAYS_INLINE constexpr plTime()=default
The default constructor sets the time to zero.
PL_ALWAYS_INLINE constexpr bool IsNegative() const
Checks for a negative time value.
Definition Time.h:53
PL_ALWAYS_INLINE static constexpr plTime MakeFromSeconds(double fSeconds)
Creates an instance of plTime that was initialized from seconds.
Definition Time.h:30
PL_ALWAYS_INLINE static constexpr plTime MakeZero()
Creates an instance of plTime that was initialized with zero.
Definition Time.h:42
PL_ALWAYS_INLINE static constexpr plTime MakeFromHours(double fHours)
Creates an instance of plTime that was initialized from hours.
Definition Time.h:38
PL_ALWAYS_INLINE constexpr bool IsZero() const
Returns true if the stored time is exactly zero. That typically means the value was not changed from ...
Definition Time.h:50
PL_ALWAYS_INLINE constexpr bool IsZeroOrPositive() const
Returns true if the stored time is zero or positive.
Definition Time.h:62
PL_ALWAYS_INLINE static constexpr plTime MakeFromMicroseconds(double fMicroseconds)
Creates an instance of plTime that was initialized from microseconds.
Definition Time.h:22
PL_ALWAYS_INLINE static constexpr plTime MakeFromNanoseconds(double fNanoseconds)
Creates an instance of plTime that was initialized from nanoseconds.
Definition Time.h:18
PL_ALWAYS_INLINE static constexpr plTime MakeFromMinutes(double fMinutes)
Creates an instance of plTime that was initialized from minutes.
Definition Time.h:34