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 
25  float FLING_API GetDeltaTime() const { return m_deltaTime; }
26 
32  double FLING_API GetTime() const;
33 
39  float FLING_API GetTimef() const
40  {
41  return static_cast<float>( GetTime() );
42  }
43 
49  float FLING_API GetFrameStartTime() const { return m_frameStartTimef; }
50 
56  double FLING_API GetStartTime() const { return m_startTime; }
57 
63  float FLING_API GetTimeSinceStart() const { return GetTimef() - static_cast<float>(m_startTime); }
64 
65  private:
66 
67  float m_deltaTime = 0.0f;
68 
69  double m_lastFrameStartTime = 0.0;
70  float m_frameStartTimef = 0.0f;
71 
73  double m_startTime = 0.0;
74 
75  };
76 } // namespace Fling
float FLING_API GetTimef() const
Get the current time of the application (float)
Definition: Timing.h:39
Definition: Timing.h:13
float m_frameStartTimef
Definition: Timing.h:70
float FLING_API GetDeltaTime() const
Definition: Timing.h:25
double m_lastFrameStartTime
Definition: Timing.h:69
double FLING_API GetTime() const
Get the current time of the application (double)
Definition: Timing.cpp:22
float m_deltaTime
Definition: Timing.h:67
Class that can have only one instance.
Definition: Singleton.hpp:11
float FLING_API GetTimeSinceStart() const
Get the time since that application has started (i.e.
Definition: Timing.h:63
virtual void Init() override
Definition: Timing.cpp:7
float FLING_API GetFrameStartTime() const
Get the time that that frame has started.
Definition: Timing.h:49
double FLING_API GetStartTime() const
Get the time that the application has started.
Definition: Timing.h:56
void Update()
Update the time values of the timer.
Definition: Timing.cpp:12
double m_startTime
The time that the program started.
Definition: Timing.h:73
Definition: Engine.h:13