From 27d1e03d7bdf8fcfe7292c06e40bc3e2fca9158e Mon Sep 17 00:00:00 2001 From: Denis Oliver Kropp Date: Tue, 19 Oct 2010 15:56:15 +0200 Subject: pluggit --- src/FPS.cxx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/FPS.cxx (limited to 'src/FPS.cxx') diff --git a/src/FPS.cxx b/src/FPS.cxx new file mode 100644 index 0000000..3c0dd54 --- /dev/null +++ b/src/FPS.cxx @@ -0,0 +1,43 @@ +namespace PluggIt { + +class FPS +{ + private int frames; + private char str[20]; + + private Clock clock; + + + public FPS() { + Reset(); + } + + public void Reset() { + frames = 0; + str[0] = 0; + + clock.Reset(); + } + + public void Count( float interval ) { + float time = clock.GetTime(); + + frames++; + + if (time >= interval) { + float fps = frames / time; + + snprintf( str, sizeof(str), "%.1f", fps ); + + frames = 0; + clock.Reset(); + } + } + + public const char *GetFPS() { + return str; + } +}; + +} + -- cgit