Ankush's Garage
A collection of stuff made by Ankush Roy
Loading...
Searching...
No Matches
Utils::Time Class Reference

Utility class for handling delta time and FPS capping. More...

#include <Time.h>

Static Public Member Functions

static void UpdateDeltaTime () noexcept
 Updates the delta time value.
 
static void Init () noexcept
 Initializes the time tracking system.
 
static double DeltaTime () noexcept
 Retrieves the time elapsed between the last two frames.
 
static uint32_t GetTicks () noexcept
 Gets the time in milliseconds since the start of the program.
 
static void CapFPS ()
 Caps the FPS to the target frame rate.
 

Static Private Attributes

static double m_DeltaTime = 0.0
 Stores the delta time value in seconds.
 
static std::chrono::time_point< std::chrono::high_resolution_clock > m_PreviousTime
 Stores the previous frame's timestamp.
 
static std::chrono::time_point< std::chrono::high_resolution_clock > m_CurrentTime
 Stores the current frame's timestamp.
 
static std::chrono::time_point< std::chrono::high_resolution_clock > m_StartTime
 Stores the program start timestamp.
 
static constexpr int m_TargetFPS = 60
 The target frames per second.
 
static constexpr std::chrono::milliseconds m_FrameDuration
 The expected duration of each frame.
 

Detailed Description

Utility class for handling delta time and FPS capping.

This class provides static methods to manage delta timing, which measures the time elapsed between frames, and functions for retrieving program ticks.

Member Function Documentation

◆ CapFPS()

void Utils::Time::CapFPS ( )
static

Caps the FPS to the target frame rate.

This function ensures that the frame rate does not exceed a predefined limit.

◆ DeltaTime()

double Utils::Time::DeltaTime ( )
staticnoexcept

Retrieves the time elapsed between the last two frames.

Returns
The delta time in milliseconds.

◆ GetTicks()

uint32_t Utils::Time::GetTicks ( )
staticnoexcept

Gets the time in milliseconds since the start of the program.

Returns
The number of milliseconds since the program began execution.

◆ Init()

void Utils::Time::Init ( )
staticnoexcept

Initializes the time tracking system.

This method sets the start time and initializes the timing variables. This function should be called only once during initialisation.

◆ UpdateDeltaTime()

void Utils::Time::UpdateDeltaTime ( )
staticnoexcept

Updates the delta time value.

This method should be called once at the start of every frame to calculate the time difference between the current and previous frame.

Member Data Documentation

◆ m_CurrentTime

std::chrono::time_point< std::chrono::high_resolution_clock > Utils::Time::m_CurrentTime
staticprivate

Stores the current frame's timestamp.

◆ m_DeltaTime

double Utils::Time::m_DeltaTime = 0.0
staticprivate

Stores the delta time value in seconds.

◆ m_FrameDuration

std::chrono::milliseconds Utils::Time::m_FrameDuration
staticconstexprprivate
Initial value:
=
std::chrono::milliseconds(1000 / m_TargetFPS)
static constexpr int m_TargetFPS
The target frames per second.
Definition Time.h:69

The expected duration of each frame.

◆ m_PreviousTime

std::chrono::time_point< std::chrono::high_resolution_clock > Utils::Time::m_PreviousTime
staticprivate

Stores the previous frame's timestamp.

◆ m_StartTime

std::chrono::time_point< std::chrono::high_resolution_clock > Utils::Time::m_StartTime
staticprivate

Stores the program start timestamp.

◆ m_TargetFPS

int Utils::Time::m_TargetFPS = 60
staticconstexprprivate

The target frames per second.


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