Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
time_manager.h
Go to the documentation of this file.
1 #pragma once
2 #include "helpers/logging.h"
3 
4 class TimeManager {
5  Uint64 lastTick = SDL_GetPerformanceCounter();
6  Uint64 currentTick = 0;
7  float deltaTime = 0.0;
8 
9  Uint64 frameCount = 0;
10  float elapsedTime = 0.0;
11  float fps = 0.0;
12 
13  /* MAX_FPS = 1 -> UNLIMITED */
14  Uint32 MAX_FPS = 60;
15  bool bIsPaused = false;
16  Uint64 pausedTick = 0;
17 
18 
19 public:
21  lastTick = SDL_GetPerformanceCounter();
22  }
23 
24  float GetDeltaTime() {
25  if (bIsPaused) {
26  return 0.0f;
27  }
28 
29  return this->deltaTime;
30  }
31 
32  Uint64 GetFrameCount() {
33  return this->frameCount;
34  }
35 
36  float GetElapsedTime() {
37  return this->elapsedTime;
38  }
39 
40  void SetMaxFps(Uint32 fps) {
41  this->MAX_FPS = fps;
42 
43  LOG_INFO("Target FPS (frames per second) to %02.03f ms", (float) fps * 1000.f);
44  }
45 
46  float GetFps() {
47  return this->fps;
48  }
49 
50  bool IsPaused() {
51  return this->bIsPaused;
52  }
53 
54  void Pause();
55 
56  void Resume();
57 
58  void Update();
59 
60  /* max_fps = 1 -> UNLIMITED */
61  void FixedFrameRate(Uint32 max_fps = 60);
62 };
63 
64 
Definition: time_manager.h:4
float GetElapsedTime()
Definition: time_manager.h:36
float GetFps()
Definition: time_manager.h:46
void Resume()
Definition: time_manager.cpp:10
void Pause()
Definition: time_manager.cpp:3
bool IsPaused()
Definition: time_manager.h:50
Uint64 GetFrameCount()
Definition: time_manager.h:32
TimeManager()
Definition: time_manager.h:20
void SetMaxFps(Uint32 fps)
Definition: time_manager.h:40
float GetDeltaTime()
Definition: time_manager.h:24
void FixedFrameRate(Uint32 max_fps=60)
Definition: time_manager.cpp:50
void Update()
Definition: time_manager.cpp:18
#define LOG_INFO(...)
INFO logging.
Definition: logging.h:75