added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / common / fps_counter.c
1 #include <stdio.h>
2 #include "fps_counter.h"
3
4 void fps_start(fps_counter *fpsc, unsigned long time, unsigned long sample_interval) {
5         fpsc->sample_interval = sample_interval;
6         fpsc->sample_start_time = time;
7         fpsc->frame_count = 0;
8         fpsc->fps = 0.0f;
9 }
10
11 int fps_frame_proc(fps_counter *fpsc, unsigned long time) {
12         if(time - fpsc->sample_start_time < fpsc->sample_interval) {
13                 fpsc->frame_count++;
14                 return 0;
15         } else {
16                 fpsc->fps = (float)fpsc->frame_count / ((float)fpsc->sample_interval / 1000.0f);
17
18                 fpsc->sample_start_time = time;
19                 fpsc->frame_count = 0;
20                 return 1;
21         }
22 }
23
24 /* changed it to a macro, see header */
25 /*
26 float fps_get_frame_rate(fps_counter *fpsc) {
27         return fpsc->fps;
28 }
29 */
30
31 const char *fps_get_frame_rate_str(fps_counter *fpsc) {
32         static char str[32];
33         sprintf(str, "%.1f", fpsc->fps);
34         return str;
35 }