diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-01-06 18:46:17 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-01-06 18:46:17 +0000 |
commit | 383339dedf6f1a52b8d6b0196068232daec83526 (patch) | |
tree | fe8bca4bc6b45e83d5c8e70a2ff1e1af4d1b99ae /src/utils/timer.cpp | |
parent | 593e65eef0d43f2ff61dc1b4f3160c0a16b5f015 (diff) | |
download | manaserv-383339dedf6f1a52b8d6b0196068232daec83526.tar.gz manaserv-383339dedf6f1a52b8d6b0196068232daec83526.tar.bz2 manaserv-383339dedf6f1a52b8d6b0196068232daec83526.tar.xz manaserv-383339dedf6f1a52b8d6b0196068232daec83526.zip |
Removed world timer usage from account server, instead letting ENet wait during
each host service to reduce CPU usage. Modified timer code to gracefully handle
jumps back in time.
Diffstat (limited to 'src/utils/timer.cpp')
-rw-r--r-- | src/utils/timer.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp index b0a05bc5..a1d8bd46 100644 --- a/src/utils/timer.cpp +++ b/src/utils/timer.cpp @@ -19,9 +19,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <time.h> #include "timer.h" +#include <time.h> +#include <sys/time.h> + +#ifdef _WIN32 +#include "wingettimeofday.h" +#endif + namespace utils { @@ -52,8 +58,18 @@ int Timer::poll() int elapsed = 0; if (active) { - elapsed = (getTimeInMillisec() - lastpulse) / interval; - lastpulse += interval * elapsed; + uint64_t now = getTimeInMillisec(); + if (now > lastpulse) + { + elapsed = (now - lastpulse) / interval; + lastpulse += interval * elapsed; + } + else + { + // Time has made a jump to the past. This should be a rare + // occurence, so just reset lastpulse to prevent problems. + lastpulse = now; + } }; return elapsed; } |