aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/Timer.h')
-rw-r--r--src/shared/Timer.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/shared/Timer.h b/src/shared/Timer.h
index 03a379b2471..82f5be161d9 100644
--- a/src/shared/Timer.h
+++ b/src/shared/Timer.h
@@ -17,9 +17,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#ifndef TRINITY_TIMER_H
#define TRINITY_TIMER_H
+
#include "Platform/CompilerDefs.h"
+
#if PLATFORM == PLATFORM_WINDOWS
# include <ace/config-all.h>
# include <mmsystem.h>
@@ -31,6 +34,7 @@
# include <sys/time.h>
# include <sys/timeb.h>
#endif
+
#if PLATFORM == PLATFORM_WINDOWS
inline uint32 getMSTime() { return GetTickCount(); }
#else
@@ -42,6 +46,7 @@ inline uint32 getMSTime()
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
#endif
+
inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
{
// getMSTime() have limited data range and this is case when it overflow in this tick
@@ -50,21 +55,26 @@ inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
else
return newMSTime - oldMSTime;
}
+
class IntervalTimer
{
public:
IntervalTimer() : _interval(0), _current(0) {}
+
void Update(time_t diff) { _current += diff; if(_current<0) _current=0;}
bool Passed() { return _current >= _interval; }
void Reset() { if(_current >= _interval) _current -= _interval; }
+
void SetCurrent(time_t current) { _current = current; }
void SetInterval(time_t interval) { _interval = interval; }
time_t GetInterval() const { return _interval; }
time_t GetCurrent() const { return _current; }
+
private:
time_t _interval;
time_t _current;
};
+
struct TimeTracker
{
TimeTracker(time_t expiry) : i_expiryTime(expiry) {}
@@ -74,6 +84,7 @@ struct TimeTracker
time_t GetExpiry(void) const { return i_expiryTime; }
time_t i_expiryTime;
};
+
struct TimeTrackerSmall
{
TimeTrackerSmall(int32 expiry) : i_expiryTime(expiry) {}
@@ -83,5 +94,6 @@ struct TimeTrackerSmall
int32 GetExpiry(void) const { return i_expiryTime; }
int32 i_expiryTime;
};
+
#endif