Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rendering_engine::AppClock Class Reference

Provides high-resolution timing for frame updates. More...

#include <app_clock.hpp>

Public Member Functions

 AppClock ()
 Constructs a new clock initialized with the current time. More...
 
 AppClock (AppClock const &)=default
 
AppClockoperator= (AppClock const &)=default
 
 AppClock (AppClock &&)=default
 
AppClockoperator= (AppClock &&)=default
 
 ~AppClock ()=default
 
const std::chrono::steady_clock::time_point & StartTime () const
 Returns the timestamp when the clock was started. More...
 
const std::chrono::steady_clock::time_point & CurrentTime () const
 Returns the most recent recorded time (current frame). More...
 
const std::chrono::steady_clock::time_point & LastTime () const
 Returns the time recorded at the previous frame. More...
 
void Reset ()
 Resets the clock to the current system time. More...
 
void UpdateAppTime (AppTime &appTime)
 Updates the given AppTime instance with elapsed and total durations. More...
 

Detailed Description

Provides high-resolution timing for frame updates.

AppClock tracks time since the application started and between frames. Each call to UpdateAppTime() updates an AppTime instance with new total and elapsed durations.

Typical usage:

AppClock clock;
AppTime time;
clock.Reset();
while (running)
{
clock.UpdateAppTime(time);
float delta = time.ElapsedAppTimeMilliseconds();
// Update logic...
}
Provides high-resolution timing for frame updates.
Definition: app_clock.hpp:50
void Reset()
Resets the clock to the current system time.
Definition: app_clock.cpp:31
void UpdateAppTime(AppTime &appTime)
Updates the given AppTime instance with elapsed and total durations.
Definition: app_clock.cpp:38
Manages current, total, and elapsed time for the application.
Definition: app_time.hpp:36
See also
rendering_engine::AppTime

Definition at line 49 of file app_clock.hpp.

Constructor & Destructor Documentation

◆ AppClock() [1/3]

rendering_engine::AppClock::AppClock ( )

Constructs a new clock initialized with the current time.

Definition at line 7 of file app_clock.cpp.

8:
9mStartTime(),
10mCurrentTime(),
11mLastTime()
12{
13 Reset();
14}

◆ AppClock() [2/3]

rendering_engine::AppClock::AppClock ( AppClock const &  )
default

◆ AppClock() [3/3]

rendering_engine::AppClock::AppClock ( AppClock &&  )
default

◆ ~AppClock()

rendering_engine::AppClock::~AppClock ( )
default

Member Function Documentation

◆ CurrentTime()

const std::chrono::steady_clock::time_point & rendering_engine::AppClock::CurrentTime ( ) const

Returns the most recent recorded time (current frame).

Definition at line 21 of file app_clock.cpp.

22{
23 return mCurrentTime;
24}

◆ LastTime()

const std::chrono::steady_clock::time_point & rendering_engine::AppClock::LastTime ( ) const

Returns the time recorded at the previous frame.

Definition at line 26 of file app_clock.cpp.

27{
28 return mLastTime;
29}

◆ operator=() [1/2]

AppClock & rendering_engine::AppClock::operator= ( AppClock &&  )
default

◆ operator=() [2/2]

AppClock & rendering_engine::AppClock::operator= ( AppClock const &  )
default

◆ Reset()

void rendering_engine::AppClock::Reset ( )

Resets the clock to the current system time.

Definition at line 31 of file app_clock.cpp.

32{
33 mStartTime = std::chrono::steady_clock::now();
34 mCurrentTime = mStartTime;
35 mLastTime = mCurrentTime;
36}

◆ StartTime()

const std::chrono::steady_clock::time_point & rendering_engine::AppClock::StartTime ( ) const

Returns the timestamp when the clock was started.

Definition at line 16 of file app_clock.cpp.

17{
18 return mStartTime;
19}

◆ UpdateAppTime()

void rendering_engine::AppClock::UpdateAppTime ( AppTime appTime)

Updates the given AppTime instance with elapsed and total durations.

Calculates the time difference between the last and current frame, updates internal state, and synchronizes AppTime accordingly.

Parameters
appTimeReference to the AppTime instance to update.

Definition at line 38 of file app_clock.cpp.

39{
40 mLastTime = mCurrentTime;
41 mCurrentTime = std::chrono::steady_clock::now();
42
43 appTime.SetCurrentTime( mCurrentTime );
44 appTime.SetTotalAppTime( std::chrono::duration_cast<std::chrono::milliseconds>(mCurrentTime - mStartTime) );
45 appTime.SetElapsedAppTime( std::chrono::duration_cast<std::chrono::milliseconds>(mCurrentTime - mLastTime) );
46}

The documentation for this class was generated from the following files: