diff --git a/src/game/Cell.h b/src/game/Cell.h index f01cddf2e..031149af2 100644 --- a/src/game/Cell.h +++ b/src/game/Cell.h @@ -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( diff --git a/src/game/DestinationHolder.h b/src/game/DestinationHolder.h index 2c8e8a1b1..133c01221 100644 --- a/src/game/DestinationHolder.h +++ b/src/game/DestinationHolder.h @@ -30,7 +30,7 @@ class Map; template class MANGOS_DLL_DECL DestinationHolder { - TimeTrackerSmall i_tracker; + ShortTimeTracker i_tracker; uint32 i_totalTravelTime; uint32 i_timeElapsed; bool i_destSet; diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index 9b12a063a..fd8505a56 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -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); } diff --git a/src/game/MapManager.h b/src/game/MapManager.h index a578c2f4b..57e07075f 100644 --- a/src/game/MapManager.h +++ b/src/game/MapManager.h @@ -171,7 +171,7 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton::Lock Guard; uint32 i_gridCleanUpDelay; MapMapType i_maps; - IntervalTimer i_timer; + ShortIntervalTimer i_timer; }; #define sMapMgr MapManager::Instance() diff --git a/src/game/RandomMovementGenerator.h b/src/game/RandomMovementGenerator.h index 19224ed4d..1f41242a2 100644 --- a/src/game/RandomMovementGenerator.h +++ b/src/game/RandomMovementGenerator.h @@ -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 > i_destinationHolder; uint32 i_nextMove; diff --git a/src/game/ThreatManager.h b/src/game/ThreatManager.h index 98ff67a55..2dfd9f581 100644 --- a/src/game/ThreatManager.h +++ b/src/game/ThreatManager.h @@ -215,7 +215,7 @@ class MANGOS_DLL_SPEC ThreatManager private: HostileReference* iCurrentVictim; Unit* iOwner; - TimeTrackerSmall iUpdateTimer; + ShortTimeTracker iUpdateTimer; bool iUpdateNeed; ThreatContainer iThreatContainer; ThreatContainer iThreatOfflineContainer; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index da86ded52..c7092ced3 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -8717,11 +8717,11 @@ DiminishingLevels Unit::GetDiminishing(DiminishingGroup group) if(!i->hitCount) return DIMINISHING_LEVEL_1; - if(!i->hitTime) + if (!i->hitTime) 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; diff --git a/src/game/WaypointMovementGenerator.h b/src/game/WaypointMovementGenerator.h index 44872502b..dfffdaf4b 100644 --- a/src/game/WaypointMovementGenerator.h +++ b/src/game/WaypointMovementGenerator.h @@ -99,7 +99,7 @@ public PathMovementBase bool GetResetPosition(Creature&, float& x, float& y, float& z); private: - TimeTrackerSmall i_nextMoveTime; + ShortTimeTracker i_nextMoveTime; bool m_isArrivalDone; bool m_isStoppedByPlayer; }; diff --git a/src/game/Weather.cpp b/src/game/Weather.cpp index 9fc8a1e9d..bbf55aa7c 100644 --- a/src/game/Weather.cpp +++ b/src/game/Weather.cpp @@ -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); + m_timer.Update(diff); ///- If the timer has passed, ReGenerate the weather if(m_timer.Passed()) diff --git a/src/game/Weather.h b/src/game/Weather.h index 166786298..33d90500d 100644 --- a/src/game/Weather.h +++ b/src/game/Weather.h @@ -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 diff --git a/src/game/World.cpp b/src/game/World.cpp index 289971995..47e89554d 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -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); - } + m_timers[i].Update(diff); ///- Update the game time and check for shutdown time _UpdateGameTime(); @@ -1434,23 +1429,21 @@ void World::Update(uint32 diff) ///
  • 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); } ///
  • Update uptime table if (m_timers[WUPDATE_UPTIME].Passed()) diff --git a/src/game/World.h b/src/game/World.h index 099ad5961..ae885b3f6 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -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; diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp index f4aa2e6d2..7df1fe35d 100644 --- a/src/mangosd/Master.cpp +++ b/src/mangosd/Master.cpp @@ -76,32 +76,17 @@ 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) + if (w_loops != World::m_worldLoopCounter) { w_lastchange = curtime; w_loops = World::m_worldLoopCounter; } // possible freeze - else if(getMSTimeDiff(w_lastchange,curtime) > _delaytime) + else if (getMSTimeDiff(w_lastchange, curtime) > _delaytime) { sLog.outError("World Thread hangs, kicking out server!"); - *((uint32 volatile*)NULL) = 0; // bang crash + *((uint32 volatile*)NULL) = 0; // bang crash } } sLog.outString("Anti-freeze thread exiting without problems."); diff --git a/src/shared/Timer.h b/src/shared/Timer.h index fde623a62..5acf0af1b 100644 --- a/src/shared/Timer.h +++ b/src/shared/Timer.h @@ -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 diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 6645cb34b..24a82ce3f 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10686" + #define REVISION_NR "10687" #endif // __REVISION_NR_H__