diff options
author | Stijn Buys <ingar@osirion.org> | 2011-05-11 14:48:17 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2011-05-11 14:48:17 +0000 |
commit | 1c63cbf204b1d2c667ce9f821ccb197d0ffb0ac3 (patch) | |
tree | c2d0ff7cc4a8a264657abd0ac99017a5b664ecd2 /src/sys/timer.cc | |
parent | bb0f860989f84b901f80017ae0139a3fc0446dc1 (diff) |
Review of the main loop timer, converted timers from float to unsigned long,
corrected a number of timing bugs, improved client framerate stability.
Diffstat (limited to 'src/sys/timer.cc')
-rw-r--r-- | src/sys/timer.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/sys/timer.cc b/src/sys/timer.cc new file mode 100644 index 0000000..c46ece2 --- /dev/null +++ b/src/sys/timer.cc @@ -0,0 +1,46 @@ +/* + sys/timer.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "sys/timer.h" + +#include <sys/time.h> + +#include <unistd.h> +#include <iostream> + +namespace sys +{ + +Timer::Timer() +{ + reset(); +} + +Timer::~Timer() +{ +} + +void Timer::reset() +{ + struct timeval tick; + struct timezone tick_tz; + + gettimeofday(&tick, &tick_tz); + timer_start = tick.tv_sec * 1000 + tick.tv_usec / 1000; +} + +unsigned long Timer::timestamp() const +{ + struct timeval tick; + struct timezone tick_tz; + + gettimeofday(&tick, &tick_tz); + unsigned long delta = (tick.tv_sec * 1000 + tick.tv_usec / 1000) - timer_start; + + return delta; +} + +} |