-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFPSCounter.hpp
78 lines (76 loc) · 2.03 KB
/
FPSCounter.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* @file FPSCounter.hpp
* @brief Definition of the FPSCounter class for frame rate calculation and rendering.
* @date Created on 24-12-23
* @author Renato Chavez
*/
#ifndef ALGOVISUALIZER_FPSCOUNTER_HPP
#define ALGOVISUALIZER_FPSCOUNTER_HPP
/**
* @brief Includes SDL2 main header for rendering functionalities.
*/
#include "SDL2/SDL.h"
/**
* @brief Includes SDL2 extension for TrueType font rendering.
*/
#include "SDL2/SDL_ttf.h"
/**
* @brief
*/
#include <string>
/**
* @brief A class to count and display frames per second (FPS).
*
* The FPSCounter class is responsible for calculating the frames per second and rendering this information on screen.
* It uses SDL and SDL_ttf for rendering the FPS count.
*/
class FPSCounter{
public:
/**
* @brief Constructor for the FPSCounter.
*
* Initializes the FPS counter with the SDL_Renderer and TTF_Font to be used for rendering the text.
*
* @param renderer SDL_Renderer used for rendering the FPS text.
* @param font TTF_Font used to display the FPS text.
*/
FPSCounter(SDL_Renderer* renderer, TTF_Font* font);
/**
* @brief Updates the FPS counter.
*
* Calculates the current frames per second based on the number of frames rendered.
*/
void update();
/**
* @brief Renders the FPS count to the screen.
*
* Displays the current FPS on the screen using the provided SDL_Renderer and TTF_Font.
*/
void render();
private:
/**
* @brief SDL_Renderer used for rendering the FPS text.
*/
SDL_Renderer* renderer;
/**
* @brief TTF_Font used for displaying the FPS text.
*/
TTF_Font* font;
/**
* @brief Timestamp of the last frame update.
*/
Uint32 lastTime;
/**
* @brief Count of frames rendered since the last update.
*/
int frameCount;
/**
* @brief Calculated frames per second.
*/
float fps;
/**
* @brief Color used for rendering the FPS text.
*/
SDL_Color textColor;
};
#endif //ALGOVISUALIZER_FPSCOUNTER_HPP