Ankush's Garage
A collection of stuff made by Ankush Roy
Loading...
Searching...
No Matches
Time.h
Go to the documentation of this file.
1#ifndef INCLUDE_UTILS_DELTATIME_H_
2#define INCLUDE_UTILS_DELTATIME_H_
3
4#include <chrono>
5
6namespace Utils
7{
8
15class Time
16{
17 // --------------------- DeltaTime ---------------------
18 public:
25 static void UpdateDeltaTime() noexcept;
26
33 static void Init() noexcept;
34
40 static double DeltaTime() noexcept;
41
47 static uint32_t GetTicks() noexcept;
48
49 private:
50 static double m_DeltaTime;
51
52 static std::chrono::time_point<std::chrono::high_resolution_clock>
54 static std::chrono::time_point<std::chrono::high_resolution_clock>
56 static std::chrono::time_point<std::chrono::high_resolution_clock>
58
59 // --------------------- Cap FPS ---------------------
60 public:
66 static void CapFPS();
67
68 private:
69 static constexpr int m_TargetFPS = 60;
70 static constexpr std::chrono::milliseconds m_FrameDuration =
71 std::chrono::milliseconds(1000 / m_TargetFPS);
72};
73
74} // namespace Utils
75
76#endif // INCLUDE_UTILS_DELTATIME_H_
Utility class for handling delta time and FPS capping.
Definition Time.h:16
static uint32_t GetTicks() noexcept
Gets the time in milliseconds since the start of the program.
Definition Time.cpp:20
static double DeltaTime() noexcept
Retrieves the time elapsed between the last two frames.
Definition Time.cpp:28
static double m_DeltaTime
Stores the delta time value in seconds.
Definition Time.h:50
static constexpr int m_TargetFPS
The target frames per second.
Definition Time.h:69
static void CapFPS()
Caps the FPS to the target frame rate.
Definition Time.cpp:44
static void Init() noexcept
Initializes the time tracking system.
Definition Time.cpp:14
static constexpr std::chrono::milliseconds m_FrameDuration
The expected duration of each frame.
Definition Time.h:70
static std::chrono::time_point< std::chrono::high_resolution_clock > m_PreviousTime
Stores the previous frame's timestamp.
Definition Time.h:53
static std::chrono::time_point< std::chrono::high_resolution_clock > m_CurrentTime
Stores the current frame's timestamp.
Definition Time.h:55
static void UpdateDeltaTime() noexcept
Updates the delta time value.
Definition Time.cpp:33
static std::chrono::time_point< std::chrono::high_resolution_clock > m_StartTime
Stores the program start timestamp.
Definition Time.h:57
Definition CapFPS.cpp:5