vengine  0.1.0
3D graphics engine made with Vulkan
Loading...
Searching...
No Matches
clock.cpp
Go to the documentation of this file.
2
4{
5 if (m_paused) {
6 return;
7 }
8 m_pause = std::chrono::high_resolution_clock::now();
9 m_paused = true;
10}
11
13{
14 if (!m_paused) {
15 return;
16 }
17
18 m_start += std::chrono::high_resolution_clock::now() - m_pause;
19 m_paused = false;
20}
21
23{
24 TimePoint now = std::chrono::high_resolution_clock::now();
25 std::chrono::duration<float> elapsed_time{};
26 if (m_paused) {
27 elapsed_time = m_pause - m_start;
28 } else {
29 elapsed_time = now - m_start;
30 }
31 return Time(elapsed_time.count());
32}
Clock class for time management.
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
TimePoint is a type alias for a time point which is a very long and complicated type in the standard ...
Definition Clock.hpp:16
Time getElapsedTime() const
Get the elapsed time since the last restart.
Definition clock.cpp:22
TimePoint m_pause
Definition Clock.hpp:62
bool m_paused
Definition Clock.hpp:67
void resume()
Resume the clock.
Definition clock.cpp:12
void pause()
Pause the clock.
Definition clock.cpp:3
Class used for time management.
Definition Time.hpp:15