-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFramerate.cpp
More file actions
59 lines (36 loc) · 1.26 KB
/
Copy pathFramerate.cpp
File metadata and controls
59 lines (36 loc) · 1.26 KB
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
//=============================================================================
#include <SDL/SDL.h>
#include "Framerate.h"
namespace ATCsim { // Project ATCsim namespace.
namespace Framerate {
// These variables are only visible from inside this namespace.
// They cannot be accessed from outside with FPS::oldTime for example.
// They are initialized at startup and keep their values between function calls.
unsigned int oldTime(0);
unsigned int lastTime(0);
float speedFactor(0);
unsigned int frames(0);
unsigned int nFrames(50);
// Not initialized to zero or we'll get infinite speed.
void compute() {
// Compute framerate (aka FPS).
++frames;
if (oldTime + 1000 < SDL_GetTicks()) {
oldTime = SDL_GetTicks();
nFrames = frames;
frames = 0;
}
// Compute speed factor.
speedFactor = ( float(SDL_GetTicks() - lastTime) / 1000.0f ); // * 32.0f;
lastTime = SDL_GetTicks();
}
//----------------------------------------------------------------------------
unsigned int getFPS() {
return nFrames;
}
//----------------------------------------------------------------------------
float getSpeedFactor() {
return speedFactor;
}
}
} // End of project ATCsim namespace.