vengine  0.0.1
3D graphics engine
Loading...
Searching...
No Matches
Clock.hpp
Go to the documentation of this file.
1///
2/// @file Clock.hpp
3/// @brief This file contains the Clock class
4/// @namespace ven
5///
6
7#pragma once
8
9#include <chrono>
10
11namespace ven {
12
13 using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock>;
14
15 ///
16 /// @class Clock
17 /// @brief Class for clock
18 /// @namespace ven
19 ///
20 class Clock {
21
22 public:
23
24 Clock() { start(); }
25 ~Clock() = default;
26
27 Clock(const Clock&) = delete;
28 Clock& operator=(const Clock&) = delete;
29 Clock(Clock&&) = delete;
30 Clock& operator=(Clock&&) = delete;
31
32 void start() { m_startTime = std::chrono::high_resolution_clock::now(); }
33 void stop();
34 void resume();
35 void update();
36 static std::chrono::high_resolution_clock::time_point now() { return std::chrono::high_resolution_clock::now(); }
37
38 [[nodiscard]] float getDeltaTime() const { return m_deltaTime.count(); }
39 [[nodiscard]] float getDeltaTimeMS() const { return m_deltaTime.count() * 1000.F; }
40 [[nodiscard]] float getFPS() const { return 1.F / m_deltaTime.count(); }
41
42 private:
43
46 std::chrono::duration<float> m_deltaTime{0.F};
47
48 bool m_isStopped{false};
49
50 }; // class Clock
51
52} // namespace ven
Class for clock.
Definition Clock.hpp:20
float getDeltaTimeMS() const
Definition Clock.hpp:39
Clock(const Clock &)=delete
std::chrono::duration< float > m_deltaTime
Definition Clock.hpp:46
bool m_isStopped
Definition Clock.hpp:48
TimePoint m_stopTime
Definition Clock.hpp:45
void start()
Definition Clock.hpp:32
Clock & operator=(const Clock &)=delete
TimePoint m_startTime
Definition Clock.hpp:44
Clock & operator=(Clock &&)=delete
void update()
Definition clock.cpp:3
Clock(Clock &&)=delete
float getDeltaTime() const
Definition Clock.hpp:38
~Clock()=default
float getFPS() const
Definition Clock.hpp:40
static std::chrono::high_resolution_clock::time_point now()
Definition Clock.hpp:36
void stop()
Definition clock.cpp:10
void resume()
Definition clock.cpp:20
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
Definition Clock.hpp:13