-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfps.h
53 lines (41 loc) · 932 Bytes
/
fps.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
//********************************************************
// Cesar Tadeu Pozzer
// 09/2009
// UFSM
//********************************************************
// Desclassificado.
#ifndef _FPS_H___
#define _FPS_H___
#include <time.h>
#define UPDATE_RATE 30 // Milisegundos
struct fps
{
float fps;
float delta;
clock_t tick;
clock_t last;
int count;
// Internals.
};
static inline void fps_init(struct fps *fps)
{
fps->tick = clock();
fps->count = 0;
fps->fps = 20;
}
static inline void fps_update(struct fps *fps)
{
float elapsed = clock();
float diff = elapsed - fps->tick;
fps->delta = elapsed - fps->last;
fps->last = elapsed;
fps->count++;
if (diff * 1000 / CLOCKS_PER_SEC > UPDATE_RATE)
{
fps->tick = fps->last;
fps->fps = fps->count / (diff / CLOCKS_PER_SEC);
fps->count = 0;
}
}
#endif