| Fling Engine 0.00.1 Fling Engine is a game engine written in Vulkan

Timing.h
Go to the documentation of this file.
1 #pragma once
2
3 // A basic timing class that was taken from: this multiplayer book:
4 // https://github.com/BenjaFriend/MultiplayerBook/blob/master/Chapter%208/RoboCatAction/RoboCat/Src/Timing.cpp
5
6 #include "pch.h"
7 #include <chrono>
8
9 namespace Fling
10 {
11 // #TODO Have a "game time" and "real time"
12 // @see 8.5.4 in Game Engine arch
13 class Timing : public Singleton<Timing>
14 {
15 public:
16
17 virtual void Init() override;
18
23 void Update();
24
28 void UpdateFps();
29
30 float FLING_API GetDeltaTime();
31
37 double FLING_API GetTime() const;
38
44 float FLING_API GetTimef() const
45 {
46 return static_cast<float>( GetTime() );
47 }
48
54 float FLING_API GetFrameStartTime() const { return m_frameStartTimef; }
55
61 double FLING_API GetStartTime() const { return m_startTime; }
62
68 float FLING_API GetTimeSinceStart() const { return GetTimef() - static_cast<float>(m_startTime); }
69
75 int FLING_API GetFrameCount() const { return m_fpsFrameCount; }
76
82 float FLING_API GetFrameTime() const { return 1000.0f / static_cast<float>(m_fpsFrameCount); }
83
84 private:
85
86 // Initialize delta time at 60 FPS to avoid an ImGUI assertion
87 float m_deltaTime = 1.0f / 60.0f;
88
89 double m_lastFrameStartTime = 0.0;
90 float m_frameStartTimef = 0.0f;
91
92 float m_fpsTimeElapsed = 0.0f;
93 int m_fpsFrameCount = 0;
94 int m_fpsFrameCountTemp = 0;
95
97 double m_startTime = 0.0;
98 };
99 } // namespace Fling
Fling::Timing::GetTimef
float FLING_API GetTimef() const
Get the current time of the application (float)
Definition: Timing.h:44
Fling::Timing
Definition: Timing.h:13
Fling::Timing::m_frameStartTimef
float m_frameStartTimef
Definition: Timing.h:90
Fling::Timing::m_fpsFrameCount
int m_fpsFrameCount
Definition: Timing.h:93
Fling::Timing::UpdateFps
void UpdateFps()
Updates current frame timer
Definition: Timing.cpp:38
Fling::Timing::m_lastFrameStartTime
double m_lastFrameStartTime
Definition: Timing.h:89
Fling::Timing::GetTime
double FLING_API GetTime() const
Get the current time of the application (double)
Definition: Timing.cpp:50
Fling::Timing::GetDeltaTime
float FLING_API GetDeltaTime()
Definition: Timing.cpp:33
Fling::Timing::m_deltaTime
float m_deltaTime
Definition: Timing.h:87
Fling::Singleton
Class that can have only one instance.
Definition: Singleton.hpp:11
Fling::Timing::GetTimeSinceStart
float FLING_API GetTimeSinceStart() const
Get the time since that application has started (i.e.
Definition: Timing.h:68
Fling::Timing::GetFrameCount
int FLING_API GetFrameCount() const
Get fps count.
Definition: Timing.h:75
pch.h
Fling::Timing::m_fpsFrameCountTemp
int m_fpsFrameCountTemp
Definition: Timing.h:94
Fling::Timing::Init
virtual void Init() override
Definition: Timing.cpp:7
Fling::Timing::GetFrameStartTime
float FLING_API GetFrameStartTime() const
Get the time that that frame has started.
Definition: Timing.h:54
Fling::Timing::GetStartTime
double FLING_API GetStartTime() const
Get the time that the application has started.
Definition: Timing.h:61
Fling::Timing::Update
void Update()
Update the time values of the timer.
Definition: Timing.cpp:12
Fling::Timing::m_startTime
double m_startTime
The time that the program started.
Definition: Timing.h:97
Fling
Definition: Engine.h:29
Fling::Timing::m_fpsTimeElapsed
float m_fpsTimeElapsed
Definition: Timing.h:92
Fling::Timing::GetFrameTime
float FLING_API GetFrameTime() const
Get current frame time.
Definition: Timing.h:82