Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
helios::app::Time Class Reference

#include <time.hpp>

Public Types

using ClockType = std::chrono::steady_clock
 
using TimePoint = ClockType::time_point
 
using Duration = ClockType::duration
 

Public Member Functions

constexpr Time () noexcept=default
 Default constructor.
 
constexpr Time (const Time &) noexcept=default
 
constexpr Time (Time &&) noexcept=default
 
constexpr ~Time () noexcept=default
 
constexpr Timeoperator= (const Time &) noexcept=default
 
constexpr Timeoperator= (Time &&) noexcept=default
 
void Tick () noexcept
 Updates timing information for a new frame.
 
void Reset () noexcept
 Resets all timing information.
 
constexpr bool IsFirstFrame () const noexcept
 Checks if this is the first frame.
 
constexpr Duration Delta () const noexcept
 Gets the raw delta duration.
 
constexpr float DeltaSeconds () const noexcept
 Gets the time elapsed since the last frame in seconds.
 
constexpr float DeltaMilliseconds () const noexcept
 Gets the time elapsed since the last frame in milliseconds.
 
constexpr Duration Elapsed () const noexcept
 Gets the total elapsed time since timing started.
 
constexpr float ElapsedSeconds () const noexcept
 Gets the total elapsed time since timing started in seconds.
 
constexpr uint64_t FrameCount () const noexcept
 Gets the current frame number.
 
constexpr float Fps () const noexcept
 Calculates the current frames per second.
 

Static Public Member Functions

static constexpr std::string_view GetName () noexcept
 Gets the resource name for trait requirements.
 

Detailed Description

Definition at line 31 of file time.hpp.

Member Typedef Documentation

◆ ClockType

◆ Duration

◆ TimePoint

Constructor & Destructor Documentation

◆ Time() [1/3]

constexpr helios::app::Time::Time ( )
constexprdefaultnoexcept

Default constructor.

Initializes time with zero delta and records start time.

Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

◆ Time() [2/3]

constexpr helios::app::Time::Time ( const Time )
constexprdefaultnoexcept

◆ Time() [3/3]

constexpr helios::app::Time::Time ( Time &&  )
constexprdefaultnoexcept

◆ ~Time()

constexpr helios::app::Time::~Time ( )
constexprdefaultnoexcept

Member Function Documentation

◆ Delta()

constexpr Duration helios::app::Time::Delta ( ) const
inlineconstexprnoexcept

Gets the raw delta duration.

Returns
Delta time as std::chrono::duration
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 72 of file time.hpp.

72{ return delta_; }

◆ DeltaMilliseconds()

constexpr float helios::app::Time::DeltaMilliseconds ( ) const
inlineconstexprnoexcept

Gets the time elapsed since the last frame in milliseconds.

Returns
Delta time in milliseconds as float
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 84 of file time.hpp.

84{ return delta_seconds_ * 1000.0F; }

◆ DeltaSeconds()

constexpr float helios::app::Time::DeltaSeconds ( ) const
inlineconstexprnoexcept

Gets the time elapsed since the last frame in seconds.

Returns
Delta time in seconds as float
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 78 of file time.hpp.

78{ return delta_seconds_; }

◆ Elapsed()

constexpr Duration helios::app::Time::Elapsed ( ) const
inlineconstexprnoexcept

Gets the total elapsed time since timing started.

Returns
Total elapsed time as std::chrono::duration
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 90 of file time.hpp.

90{ return elapsed_; }

◆ ElapsedSeconds()

constexpr float helios::app::Time::ElapsedSeconds ( ) const
inlineconstexprnoexcept

Gets the total elapsed time since timing started in seconds.

Returns
Total elapsed time in seconds as float
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 96 of file time.hpp.

96{ return elapsed_seconds_; }

◆ Fps()

constexpr float helios::app::Time::Fps ( ) const
inlineconstexprnoexcept

Calculates the current frames per second.

Based on the current delta time.

Returns
FPS as float, or 0 if delta is zero
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 110 of file time.hpp.

110{ return delta_seconds_ > 0.0F ? 1.0F / delta_seconds_ : 0.0F; }

◆ FrameCount()

constexpr uint64_t helios::app::Time::FrameCount ( ) const
inlineconstexprnoexcept

Gets the current frame number.

Incremented each time Tick() is called.

Returns
Current frame count (0-indexed, first frame is 0)
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 103 of file time.hpp.

103{ return frame_count_; }

◆ GetName()

static constexpr std::string_view helios::app::Time::GetName ( )
inlinestaticconstexprnoexcept

Gets the resource name for trait requirements.

Returns
Resource name
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 116 of file time.hpp.

116{ return "Time"; }

◆ IsFirstFrame()

constexpr bool helios::app::Time::IsFirstFrame ( ) const
inlineconstexprnoexcept

Checks if this is the first frame.

Returns
True if frame count is 0
Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 66 of file time.hpp.

66{ return frame_count_ == 0; }

◆ operator=() [1/2]

constexpr Time & helios::app::Time::operator= ( const Time )
constexprdefaultnoexcept

◆ operator=() [2/2]

constexpr Time & helios::app::Time::operator= ( Time &&  )
constexprdefaultnoexcept

◆ Reset()

void helios::app::Time::Reset ( )
inlinenoexcept

Resets all timing information.

Sets delta to zero, resets elapsed time, and resets frame count.

Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 144 of file time.hpp.

144 {
145 const TimePoint now = ClockType::now();
146
147 last_tick_ = now;
148 start_time_ = now;
149 delta_ = Duration::zero();
150 elapsed_ = Duration::zero();
151 delta_seconds_ = 0.0F;
152 elapsed_seconds_ = 0.0F;
153 frame_count_ = 0;
154}
ClockType::time_point TimePoint
Definition time.hpp:34

◆ Tick()

void helios::app::Time::Tick ( )
inlinenoexcept

Updates timing information for a new frame.

Should be called at the beginning of each frame by the runner. Calculates delta time based on the time since last update.

Examples
/home/runner/work/HeliosEngine/HeliosEngine/src/core/include/helios/core/app/time.hpp.

Definition at line 131 of file time.hpp.

131 {
132 const TimePoint now = ClockType::now();
133
134 delta_ = now - last_tick_;
135 elapsed_ = now - start_time_;
136
137 delta_seconds_ = std::chrono::duration<float>(delta_).count();
138 elapsed_seconds_ = std::chrono::duration<float>(elapsed_).count();
139
140 last_tick_ = now;
141 ++frame_count_;
142}