diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/utils/timer.cpp | 10 | ||||
-rw-r--r-- | src/utils/timer.h | 20 |
3 files changed, 21 insertions, 13 deletions
@@ -6,6 +6,8 @@ implementation of the UNIX gettimeofday function. * src/main.cpp: world time doesn't get async anymore when world ticks are skipped. added a warning when tick skip occurs. + * src/util/timer.h, src/util/timer.cpp: made sure every compiler uses a + 64bit unsigned integer for getTimeInMillisec. 2006-04-28 Eugenio Favalli <elvenprogrammer@gmail.com> @@ -407,4 +409,4 @@ src/dal/sqlitedataprovider.cpp, src/dal/mysqldataprovider.cpp, src/dal/pqdataprovider.cpp, src/main.cpp, src/client.cpp: Grammar corrections, and a little bit of work on getting the name - of the Db.
\ No newline at end of file + of the Db. diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp index 25d96cbc..97965c75 100644 --- a/src/utils/timer.cpp +++ b/src/utils/timer.cpp @@ -26,7 +26,7 @@ namespace tmwserv namespace utils { -Timer::Timer(signed int ms, bool createActive) +Timer::Timer(unsigned int ms, bool createActive) { active = createActive; interval = ms; @@ -55,18 +55,18 @@ void Timer::stop() active = false; }; -void Timer::changeInterval(signed int newinterval) +void Timer::changeInterval(unsigned int newinterval) { interval = newinterval; }; -signed long long int Timer::getTimeInMillisec() +uint64_t Timer::getTimeInMillisec() { - signed long long int timeInMillisec; + uint64_t timeInMillisec; timeval time; gettimeofday(&time, 0); - timeInMillisec = (signed long long int)time.tv_sec * 1000 + time.tv_usec / 1000; + timeInMillisec = (uint64_t)time.tv_sec * 1000 + time.tv_usec / 1000; return timeInMillisec; }; diff --git a/src/utils/timer.h b/src/utils/timer.h index 1fdf7af5..a921a828 100644 --- a/src/utils/timer.h +++ b/src/utils/timer.h @@ -24,8 +24,15 @@ #include <sys/time.h> +/* I need a 64-bit unsigned integer */ +#ifdef _MSC_VER + typedef __uint64 uint64_t // when using MSVC use its internal type +#else + #include <stdint.h> // on other compilers use the C99 official header +#endif + #ifdef _WIN32 -#include "wingettimeofday.h" + #include "wingettimeofday.h" #endif namespace tmwserv @@ -35,7 +42,6 @@ namespace utils /** * This class is for timing purpose as a replacement for SDL_TIMER - * connections from and connecting to other computers. */ class Timer @@ -44,7 +50,7 @@ class Timer /** * Constructor. */ - Timer(signed int ms, bool createActive = true); + Timer(unsigned int ms, bool createActive = true); /** * returns the number of elapsed tics since last call @@ -64,23 +70,23 @@ class Timer /** * changes the interval between two pulses */ - void changeInterval (signed int newinterval); + void changeInterval (unsigned int newinterval); private: /** * calls gettimeofday() and converts it into milliseconds */ - signed long long int getTimeInMillisec(); + uint64_t getTimeInMillisec(); /** * interval between two pulses */ - signed int interval; + unsigned int interval; /** * the time the last pulse occured */ - signed long long int lastpulse; + uint64_t lastpulse; /** * activity status of the timer |