[10687] UInt32 timer class copies instead using time_t timers for mstime cases.

Also cleanup weather update code and some random code cleanups.
This commit is contained in:
VladimirMangos 2010-11-06 21:54:05 +03:00
parent 478bf3b367
commit 464908f453
15 changed files with 87 additions and 67 deletions

View file

@ -49,7 +49,7 @@ inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
{
// getMSTime() have limited data range and this is case when it overflow in this tick
if (oldMSTime > newMSTime)
return (0xFFFFFFFF - oldMSTime) + newMSTime;
return (uint32(0xFFFFFFFF) - oldMSTime) + newMSTime;
else
return newMSTime - oldMSTime;
}
@ -59,9 +59,18 @@ 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 Update(time_t diff)
{
_current += diff;
if (_current < 0)
_current = 0;
}
bool Passed() const { return _current >= _interval; }
void Reset()
{
if (_current >= _interval)
_current -= _interval;
}
void SetCurrent(time_t current) { _current = current; }
void SetInterval(time_t interval) { _interval = interval; }
@ -73,24 +82,57 @@ class IntervalTimer
time_t _current;
};
struct TimeTracker
class ShortIntervalTimer
{
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;
public:
ShortIntervalTimer() : _interval(0), _current(0) {}
void Update(uint32 diff)
{
_current += diff;
}
bool Passed() const { return _current >= _interval; }
void Reset()
{
if (_current >= _interval)
_current -= _interval;
}
void SetCurrent(uint32 current) { _current = current; }
void SetInterval(uint32 interval) { _interval = interval; }
uint32 GetInterval() const { return _interval; }
uint32 GetCurrent() const { return _current; }
private:
uint32 _interval;
uint32 _current;
};
struct TimeTrackerSmall
struct TimeTracker
{
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;
public:
TimeTracker(time_t expiry) : i_expiryTime(expiry) {}
void Update(time_t diff) { i_expiryTime -= diff; }
bool Passed() const { return (i_expiryTime <= 0); }
void Reset(time_t interval) { i_expiryTime = interval; }
time_t GetExpiry() const { return i_expiryTime; }
private:
time_t i_expiryTime;
};
struct ShortTimeTracker
{
public:
ShortTimeTracker(int32 expiry) : i_expiryTime(expiry) {}
void Update(int32 diff) { i_expiryTime -= diff; }
bool Passed() const { return (i_expiryTime <= 0); }
void Reset(int32 interval) { i_expiryTime = interval; }
int32 GetExpiry() const { return i_expiryTime; }
private:
int32 i_expiryTime;
};
#endif