Replaced time(NULL) on sGameTime.GetGameTime() this is used for better performance.

Original Timer.h divided into 2 parts. Shared project has no need to know about GameTime Singleton.
2 Identical structures with different types are now replaced with one generic templated structure and 2 typedefs.

--HG--
branch : trunk
This commit is contained in:
n0n4m3
2009-12-23 08:04:10 +01:00
parent 7ea2510980
commit 3fe0bc5254
51 changed files with 352 additions and 364 deletions
+4 -75
View File
@@ -18,21 +18,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TRINITY_TIMER_H
#define TRINITY_TIMER_H
#ifndef _TIMER_H
#define _TIMER_H
#include "Platform/CompilerDefs.h"
#include "Platform/Define.h"
#if PLATFORM == PLATFORM_WINDOWS
# include <ace/config-all.h>
# include <mmsystem.h>
# include <time.h>
#else
# if defined(__APPLE_CC__)
# include <time.h>
# endif
#if (PLATFORM != PLATFORM_WINDOWS)
# include <sys/time.h>
# include <sys/timeb.h>
#endif
#if PLATFORM == PLATFORM_WINDOWS
@@ -56,67 +48,4 @@ inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
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) {}
void Update(time_t diff) { i_expiryTime -= diff; }
bool Passed(void) const { return (i_expiryTime <= 0); }
void Reset(time_t interval) { i_expiryTime = interval; }
time_t GetExpiry(void) const { return i_expiryTime; }
time_t i_expiryTime;
};
struct TimeTrackerSmall
{
TimeTrackerSmall(int32 expiry) : i_expiryTime(expiry) {}
void Update(int32 diff) { i_expiryTime -= diff; }
bool Passed(void) const { return (i_expiryTime <= 0); }
void Reset(int32 interval) { i_expiryTime = interval; }
int32 GetExpiry(void) const { return i_expiryTime; }
int32 i_expiryTime;
};
struct PeriodicTimer
{
PeriodicTimer(int32 period, int32 start_time) :
i_expireTime(start_time), i_period(period) {}
bool Update(const uint32 &diff)
{
if((i_expireTime -= diff) > 0)
return false;
i_expireTime += i_period > diff ? i_period : diff;
return true;
}
void SetPeriodic(int32 period, int32 start_time)
{
i_expireTime=start_time, i_period=period;
}
int32 i_period;
int32 i_expireTime;
};
#endif