-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCFPSControl.h
57 lines (46 loc) · 1.09 KB
/
CFPSControl.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
#ifndef _CFPSCONTROL_H_
#define _CFPSCONTROL_H_
#ifdef _WIN32
# include <SDL\SDL.h>
#else
# include <SDL/SDL.h>
#endif
class CFPSControl
{
private:
int FPS;
Uint32 waittime;
Uint32 framestarttime;
Sint32 delaytime;
private:
CFPSControl();
public:
CFPSControl( int FPS ) : FPS( FPS )
{
setFPS( FPS );
}
int getFPS() { return FPS; }
void setFPS( int FPS )
{
this->FPS = FPS;
waittime = 1000.0f/FPS;
framestarttime = 0;
}
void raiseFPS() { if ( FPS < 128 ) { setFPS( FPS*2 ); } }
void lowerFPS() { if ( FPS > 1 ) { setFPS( FPS/2 ); } }
bool OnLoop()
{
delaytime = waittime - ( SDL_GetTicks() - framestarttime );
if ( delaytime > 0 )
{
//SDL_Delay( (Uint32)delaytime );
return false;
}
else
{
framestarttime = SDL_GetTicks();
return true;
}
}
};
#endif //_CCELLGRID_H_