X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;ds=sidebyside;f=src%2F3dengfx%2Fsrc%2Fcommon%2Ffps_counter.c;fp=src%2F3dengfx%2Fsrc%2Fcommon%2Ffps_counter.c;h=48aeef0b6b74d063c244700ce783a3f01cc44a4f;hb=6e23259dbabaeb1711a2a5ca25b9cb421f693759;hp=0000000000000000000000000000000000000000;hpb=fe068fa879814784c45e0cb2e65dac489e8f5594;p=summerhack diff --git a/src/3dengfx/src/common/fps_counter.c b/src/3dengfx/src/common/fps_counter.c new file mode 100644 index 0000000..48aeef0 --- /dev/null +++ b/src/3dengfx/src/common/fps_counter.c @@ -0,0 +1,35 @@ +#include +#include "fps_counter.h" + +void fps_start(fps_counter *fpsc, unsigned long time, unsigned long sample_interval) { + fpsc->sample_interval = sample_interval; + fpsc->sample_start_time = time; + fpsc->frame_count = 0; + fpsc->fps = 0.0f; +} + +int fps_frame_proc(fps_counter *fpsc, unsigned long time) { + if(time - fpsc->sample_start_time < fpsc->sample_interval) { + fpsc->frame_count++; + return 0; + } else { + fpsc->fps = (float)fpsc->frame_count / ((float)fpsc->sample_interval / 1000.0f); + + fpsc->sample_start_time = time; + fpsc->frame_count = 0; + return 1; + } +} + +/* changed it to a macro, see header */ +/* +float fps_get_frame_rate(fps_counter *fpsc) { + return fpsc->fps; +} +*/ + +const char *fps_get_frame_rate_str(fps_counter *fpsc) { + static char str[32]; + sprintf(str, "%.1f", fpsc->fps); + return str; +}