sculpto
timer.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file timer.h
3 * \brief Timer, calculating interframe deltatime and fps
4 * class definition module.
5 *
6 * \author Sabitov Kirill
7 * \date 28 June 2022
8 *********************************************************************/
9
10#pragma once
11
12#include "base.h"
13
14namespace scl
15{
16 using namespace std::chrono;
17 class timer
18 {
19 using time_point = time_point<high_resolution_clock>;
20
21 private:
22 bool IsPause {};
23 float Time {};
24 float DeltaTime {};
25 float Fps { -1 };
26
27 time_point StartTime {};
28 time_point OldTime {};
29 time_point LastFpsCalcutionTime {};
30 u32 LastFpsCalcutionFramesCount {};
32 static shared<timer> GlobalTimerInstance;
33
34 public:
35 static const float UpdateDelay;
38 static bool GetIsPause() { return GlobalTimerInstance->IsPause; }
40 static float GetTime() { return GlobalTimerInstance->Time; }
42 static float GetDeltaTime() { return GlobalTimerInstance->DeltaTime; }
44 static float GetFps() { return GlobalTimerInstance->Fps; }
45
47 static void SetIsPause(bool IsPause) { GlobalTimerInstance->IsPause = IsPause; }
49 static void SwitchIsPause() { GlobalTimerInstance->IsPause = !GlobalTimerInstance->IsPause; }
50
51 public:
53 timer();
54
55 /*!*
56 * Timer response function.
57 * Calculate inter-frame delta time each call,
58 * but FPS only once second.
59 *
60 * \param None.
61 * \return None.
62 */
63 void Response();
64
65 /*!*
66 * Global timer getter function.
67 *
68 * \param None.
69 * \return None.
70 */
71 static shared<timer> &Get() { return GlobalTimerInstance; }
72 };
73}
Topology object basis class for mesh creating implementation module.
static shared< timer > & Get()
Definition: timer.h:71
static float GetTime()
Definition: timer.h:40
static void SetIsPause(bool IsPause)
Definition: timer.h:47
static const float UpdateDelay
Definition: timer.h:35
static float GetFps()
Definition: timer.h:44
static void SwitchIsPause()
Definition: timer.h:49
void Response()
Definition: timer.cpp:21
static float GetDeltaTime()
Definition: timer.h:42
static bool GetIsPause()
Definition: timer.h:38
Definition: base.h:33
std::shared_ptr< T > shared
Definition: smart_ptr.h:15
uint32_t u32
Definition: math_common.h:21