mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 10:37:03 +00:00
[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:
parent
478bf3b367
commit
464908f453
15 changed files with 87 additions and 67 deletions
|
|
@ -78,6 +78,8 @@ struct MANGOS_DLL_DECL Cell
|
|||
bool NoCreate() const { return data.Part.nocreate; }
|
||||
void SetNoCreate() { data.Part.nocreate = 1; }
|
||||
|
||||
GridPair gridPair() const { return GridPair(GridX(),GridY()); }
|
||||
|
||||
CellPair cellPair() const
|
||||
{
|
||||
return CellPair(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class Map;
|
|||
template<typename TRAVELLER>
|
||||
class MANGOS_DLL_DECL DestinationHolder
|
||||
{
|
||||
TimeTrackerSmall i_tracker;
|
||||
ShortTimeTracker i_tracker;
|
||||
uint32 i_totalTravelTime;
|
||||
uint32 i_timeElapsed;
|
||||
bool i_destSet;
|
||||
|
|
|
|||
|
|
@ -246,10 +246,10 @@ MapManager::Update(uint32 diff)
|
|||
return;
|
||||
|
||||
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
|
||||
iter->second->Update((uint32)i_timer.GetCurrent());
|
||||
iter->second->Update(i_timer.GetCurrent());
|
||||
|
||||
for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
|
||||
(*iter)->Update((uint32)i_timer.GetCurrent());
|
||||
(*iter)->Update(i_timer.GetCurrent());
|
||||
|
||||
i_timer.SetCurrent(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
|
|||
typedef MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex>::Lock Guard;
|
||||
uint32 i_gridCleanUpDelay;
|
||||
MapMapType i_maps;
|
||||
IntervalTimer i_timer;
|
||||
ShortIntervalTimer i_timer;
|
||||
};
|
||||
|
||||
#define sMapMgr MapManager::Instance()
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class MANGOS_DLL_SPEC RandomMovementGenerator
|
|||
|
||||
bool GetResetPosition(T&, float& x, float& y, float& z);
|
||||
private:
|
||||
TimeTrackerSmall i_nextMoveTime;
|
||||
ShortTimeTracker i_nextMoveTime;
|
||||
|
||||
DestinationHolder< Traveller<T> > i_destinationHolder;
|
||||
uint32 i_nextMove;
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ class MANGOS_DLL_SPEC ThreatManager
|
|||
private:
|
||||
HostileReference* iCurrentVictim;
|
||||
Unit* iOwner;
|
||||
TimeTrackerSmall iUpdateTimer;
|
||||
ShortTimeTracker iUpdateTimer;
|
||||
bool iUpdateNeed;
|
||||
ThreatContainer iThreatContainer;
|
||||
ThreatContainer iThreatOfflineContainer;
|
||||
|
|
|
|||
|
|
@ -8721,7 +8721,7 @@ DiminishingLevels Unit::GetDiminishing(DiminishingGroup group)
|
|||
return DIMINISHING_LEVEL_1;
|
||||
|
||||
// If last spell was casted more than 15 seconds ago - reset the count.
|
||||
if(i->stack==0 && getMSTimeDiff(i->hitTime,getMSTime()) > 15000)
|
||||
if (i->stack==0 && getMSTimeDiff(i->hitTime,getMSTime()) > 15*IN_MILLISECONDS)
|
||||
{
|
||||
i->hitCount = DIMINISHING_LEVEL_1;
|
||||
return DIMINISHING_LEVEL_1;
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public PathMovementBase<Creature, WaypointPath const*>
|
|||
bool GetResetPosition(Creature&, float& x, float& y, float& z);
|
||||
|
||||
private:
|
||||
TimeTrackerSmall i_nextMoveTime;
|
||||
ShortTimeTracker i_nextMoveTime;
|
||||
bool m_isArrivalDone;
|
||||
bool m_isStoppedByPlayer;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,15 +35,13 @@ Weather::Weather(uint32 zone, WeatherZoneChances const* weatherChances) : m_zone
|
|||
m_type = WEATHER_TYPE_FINE;
|
||||
m_grade = 0;
|
||||
|
||||
DETAIL_FILTER_LOG(LOG_FILTER_WEATHER, "WORLD: Starting weather system for zone %u (change every %u minutes).", m_zone, (uint32)(m_timer.GetInterval() / (MINUTE*IN_MILLISECONDS)) );
|
||||
DETAIL_FILTER_LOG(LOG_FILTER_WEATHER, "WORLD: Starting weather system for zone %u (change every %u minutes).", m_zone, (m_timer.GetInterval() / (MINUTE*IN_MILLISECONDS)) );
|
||||
}
|
||||
|
||||
/// Launch a weather update
|
||||
bool Weather::Update(time_t diff)
|
||||
{
|
||||
if (m_timer.GetCurrent()>=0)
|
||||
m_timer.Update(diff);
|
||||
else m_timer.SetCurrent(0);
|
||||
|
||||
///- If the timer has passed, ReGenerate the weather
|
||||
if(m_timer.Passed())
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class Weather
|
|||
uint32 m_zone;
|
||||
WeatherType m_type;
|
||||
float m_grade;
|
||||
IntervalTimer m_timer;
|
||||
ShortIntervalTimer m_timer;
|
||||
WeatherZoneChances const* m_weatherChances;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1286,7 +1286,7 @@ void World::SetInitialWorldSettings()
|
|||
//one second is 1000 -(tested on win system)
|
||||
mail_timer = uint32((((localtime( &m_gameTime )->tm_hour + 20) % 24)* HOUR * IN_MILLISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval() );
|
||||
//1440
|
||||
mail_timer_expires = uint32( (DAY * IN_MILLISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval()));
|
||||
mail_timer_expires = (DAY * IN_MILLISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval();
|
||||
DEBUG_LOG("Mail timer set to: %u, mail return is called every %u minutes", mail_timer, mail_timer_expires);
|
||||
|
||||
///- Initialize static helper structures
|
||||
|
|
@ -1384,12 +1384,7 @@ void World::Update(uint32 diff)
|
|||
{
|
||||
///- Update the different timers
|
||||
for(int i = 0; i < WUPDATE_COUNT; ++i)
|
||||
{
|
||||
if (m_timers[i].GetCurrent()>=0)
|
||||
m_timers[i].Update(diff);
|
||||
else
|
||||
m_timers[i].SetCurrent(0);
|
||||
}
|
||||
|
||||
///- Update the game time and check for shutdown time
|
||||
_UpdateGameTime();
|
||||
|
|
@ -1434,23 +1429,21 @@ void World::Update(uint32 diff)
|
|||
/// <li> Handle weather updates when the timer has passed
|
||||
if (m_timers[WUPDATE_WEATHERS].Passed())
|
||||
{
|
||||
m_timers[WUPDATE_WEATHERS].Reset();
|
||||
|
||||
///- Send an update signal to Weather objects
|
||||
WeatherMap::iterator itr, next;
|
||||
for (itr = m_weathers.begin(); itr != m_weathers.end(); itr = next)
|
||||
for (WeatherMap::iterator itr = m_weathers.begin(); itr != m_weathers.end(); )
|
||||
{
|
||||
next = itr;
|
||||
++next;
|
||||
|
||||
///- and remove Weather objects for zones with no player
|
||||
//As interval > WorldTick
|
||||
if(!itr->second->Update(m_timers[WUPDATE_WEATHERS].GetInterval()))
|
||||
{
|
||||
delete itr->second;
|
||||
m_weathers.erase(itr);
|
||||
m_weathers.erase(itr++);
|
||||
}
|
||||
else
|
||||
++itr;
|
||||
}
|
||||
|
||||
m_timers[WUPDATE_WEATHERS].SetCurrent(0);
|
||||
}
|
||||
/// <li> Update uptime table
|
||||
if (m_timers[WUPDATE_UPTIME].Passed())
|
||||
|
|
|
|||
|
|
@ -616,7 +616,7 @@ class World
|
|||
|
||||
time_t m_startTime;
|
||||
time_t m_gameTime;
|
||||
IntervalTimer m_timers[WUPDATE_COUNT];
|
||||
ShortIntervalTimer m_timers[WUPDATE_COUNT];
|
||||
uint32 mail_timer;
|
||||
uint32 mail_timer_expires;
|
||||
|
||||
|
|
|
|||
|
|
@ -76,21 +76,6 @@ public:
|
|||
uint32 curtime = getMSTime();
|
||||
//DEBUG_LOG("anti-freeze: time=%u, counters=[%u; %u]",curtime,Master::m_masterLoopCounter,World::m_worldLoopCounter);
|
||||
|
||||
// There is no Master anymore
|
||||
// TODO: clear the rest of the code
|
||||
// // normal work
|
||||
// if(m_loops != Master::m_masterLoopCounter)
|
||||
// {
|
||||
// m_lastchange = curtime;
|
||||
// m_loops = Master::m_masterLoopCounter;
|
||||
// }
|
||||
// // possible freeze
|
||||
// else if(getMSTimeDiff(m_lastchange,curtime) > _delaytime)
|
||||
// {
|
||||
// sLog.outError("Main/Sockets Thread hangs, kicking out server!");
|
||||
// *((uint32 volatile*)NULL) = 0; // bang crash
|
||||
// }
|
||||
|
||||
// normal work
|
||||
if (w_loops != World::m_worldLoopCounter)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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,23 +82,56 @@ class IntervalTimer
|
|||
time_t _current;
|
||||
};
|
||||
|
||||
class ShortIntervalTimer
|
||||
{
|
||||
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 TimeTracker
|
||||
{
|
||||
public:
|
||||
TimeTracker(time_t expiry) : i_expiryTime(expiry) {}
|
||||
void Update(time_t diff) { i_expiryTime -= diff; }
|
||||
bool Passed(void) const { return (i_expiryTime <= 0); }
|
||||
bool Passed() const { return (i_expiryTime <= 0); }
|
||||
void Reset(time_t interval) { i_expiryTime = interval; }
|
||||
time_t GetExpiry(void) const { return i_expiryTime; }
|
||||
time_t GetExpiry() const { return i_expiryTime; }
|
||||
|
||||
private:
|
||||
time_t i_expiryTime;
|
||||
};
|
||||
|
||||
struct TimeTrackerSmall
|
||||
struct ShortTimeTracker
|
||||
{
|
||||
TimeTrackerSmall(int32 expiry) : i_expiryTime(expiry) {}
|
||||
public:
|
||||
ShortTimeTracker(int32 expiry) : i_expiryTime(expiry) {}
|
||||
void Update(int32 diff) { i_expiryTime -= diff; }
|
||||
bool Passed(void) const { return (i_expiryTime <= 0); }
|
||||
bool Passed() const { return (i_expiryTime <= 0); }
|
||||
void Reset(int32 interval) { i_expiryTime = interval; }
|
||||
int32 GetExpiry(void) const { return i_expiryTime; }
|
||||
int32 GetExpiry() const { return i_expiryTime; }
|
||||
|
||||
private:
|
||||
int32 i_expiryTime;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "10686"
|
||||
#define REVISION_NR "10687"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue