-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfpscontrol.h
62 lines (48 loc) · 1.42 KB
/
fpscontrol.h
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
#ifndef FPSCONTROL_H
#define FPSCONTROL_H
#include <SDL2/SDL.h>
#include "timerlib.h"
#define DEFULT_PLAYER_SPEED 1.2
#define DEFAULT_FPS_MAX 60
#define FPS_MINIMAL_LIMIT 50 // if fps is lower or equal this value, we increment fail-count
#define FPS_MINIMAL_MAX_FAIL 10 // if we have 10 consecutive times fps is under limit, we take action
struct st_fps_data
{
unsigned long frame_min;
unsigned long frame_max;
double frame_average;
int fps;
};
class fpscontrol
{
public:
fpscontrol();
void initialize();
bool limit();
void fps_count();
int get_current_frame_n();
int get_frame_drop_n();
bool get_failed_min_fps();
void reset_failed_min_fps();
private:
st_fps_data data;
float max_frame_ticks;
unsigned long last_second_ticks;
int frame_count;
unsigned long min_ticks;
unsigned long max_ticks;
double average_ticks;
unsigned long last_frame_ticks;
unsigned long current_ticks;
unsigned long target_ticks;
unsigned short fps_max;
unsigned long fps_timer;
int fps_counter;
// if we are getting less than 60 fps, this will tell main loop how many times it will run full until drop one
int frame_drop_period;
char _fps_buffer[128];
unsigned int fps_min_fail_count; // counts the number of sequential times the FPS is under minumal limit
bool failed_min_fps;
timerlib timer;
};
#endif // FPSCONTROL_H