-
Notifications
You must be signed in to change notification settings - Fork 0
/
fps.h
119 lines (87 loc) · 3.03 KB
/
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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* Module for measuring FPS for Allegro games.
Written by Miran Amon.
version: 1.02
date: 27. June 2003
*/
#ifndef FPS_H
#define FPS_H
#include <allegro.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Underlaying structure for measuring FPS. The user should create an instance
of this structure with create_fps() and destroy it with destroy_fps().
The user should not use the contents of the structure directly,
functions for manipulating with the FPS structure should be used instead.
*/
typedef struct FPS {
int *samples;
int nSamples;
int curSample;
int frameCounter;
int framesPerSecond;
} FPS;
/* Creates an instance of the FPS structure and initializes it. The user
should call this function somewhere at the beginning of the program and
use the value it returns to access the current FPS.
Parameters:
int fps - the frequency of the timer used to control the speed of the program
Returns:
FPS *fps - an instance of the FPS structure
*/
FPS *create_fps(int fps);
/* Destroys an FPS object. The user should call this function when he's
done measuring the FPS, i.e. at the end of the program.
Parameters:
FPS *fps - a pointer to an FPS object
Returns:
nothing
*/
void destroy_fps(FPS *fps);
/* Updates the FPS measuring logic. The user should call this function exactly
fps times per second where fps is the speed of their timer. Usually this is
implemented in the logic code, i.e. in the while(timer_counter) loop or
an equivalent.
Parameters:
FPS *fps - a pointer to an FPS object
Returns:
nothing
*/
void fps_tick(FPS *fps);
/* Counts the number of drawn frames. The user should call this function
every time they draw their frame.
Parameters:
FPS *fps - a pointer to an FPS object
Returns:
nothing
*/
void fps_frame(FPS *fps);
/* Retreives the current frame rate in frames per second. This will actually
be the average frame rate over the last second.
Parameters:
FPS *fps - a pointer to an FPS object
Returns:
int fps - the average frame rate over the last second
*/
int get_fps(FPS *fps);
/* Draws the current frame rate on the specified bitmap with the specified
parameters.
Parameters:
FPS *fps - a pointer to an FPS object
BITMAP *bmp - destination bitmap
FONT *font - the font used for printing the fps
int x, y - position of the fps text on the destination bitmap
int color - the color of the fps text
char *format - the format of the text as you would pass to printf(); the
format should contain whatever text you wish to print and
a format sequence for outputting an integer;
Returns:
nothing
Example:
draw_fps(fps, screen, font, 100, 50, makecol(123,234,213), "FPS = %d");
*/
void draw_fps(FPS *fps, BITMAP *bmp, FONT *font, int x, int y, int color, char *format);
#ifdef __cplusplus
}
#endif
#endif