diff options
author | Shauren <shauren.trinity@gmail.com> | 2017-09-14 22:33:40 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2017-09-14 22:33:40 +0200 |
commit | 6eb997394722fcd4b5248646b5abfa185a7ec58f (patch) | |
tree | d6a224a43940a1ba0580450854dcf55399222fc1 /src/server/game/Weather/WeatherMgr.cpp | |
parent | 6d2bc7abf48a7e64b04b42b082ebabecd0c5dce6 (diff) |
Core/Weather: Fixed weather updates to be thread safe
Diffstat (limited to 'src/server/game/Weather/WeatherMgr.cpp')
-rw-r--r-- | src/server/game/Weather/WeatherMgr.cpp | 74 |
1 files changed, 6 insertions, 68 deletions
diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp index fcda5662560..ae69d8a009f 100644 --- a/src/server/game/Weather/WeatherMgr.cpp +++ b/src/server/game/Weather/WeatherMgr.cpp @@ -21,64 +21,24 @@ */ #include "WeatherMgr.h" +#include "Containers.h" #include "DatabaseEnv.h" #include "Log.h" -#include "MiscPackets.h" #include "ObjectMgr.h" -#include "Player.h" +#include "Timer.h" #include "Weather.h" -#include "WorldSession.h" namespace WeatherMgr { namespace { - typedef std::unordered_map<uint32, std::shared_ptr<Weather> > WeatherMap; - typedef std::unordered_map<uint32, WeatherData> WeatherZoneMap; - - WeatherMap m_weathers; - WeatherZoneMap mWeatherZoneMap; - - WeatherData const* GetWeatherData(uint32 zone_id) - { - WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id); - return (itr != mWeatherZoneMap.end()) ? &itr->second : NULL; - } -} - -/// Find a Weather object by the given zoneid -Weather* FindWeather(uint32 id) -{ - WeatherMap::const_iterator itr = m_weathers.find(id); - return (itr != m_weathers.end()) ? itr->second.get() : nullptr; + std::unordered_map<uint32, WeatherData> _weatherData; } -/// Remove a Weather object for the given zoneid -void RemoveWeather(uint32 id) +WeatherData const* GetWeatherData(uint32 zone_id) { - // not called at the moment. Kept for completeness - WeatherMap::iterator itr = m_weathers.find(id); - - if (itr != m_weathers.end()) - m_weathers.erase(itr); -} - -/// Add a Weather object to the list -Weather* AddWeather(uint32 zone_id) -{ - WeatherData const* weatherChances = GetWeatherData(zone_id); - - // zone does not have weather, ignore - if (!weatherChances) - return NULL; - - Weather* w = new Weather(zone_id, weatherChances); - m_weathers[w->GetZone()].reset(w); - w->ReGenerate(); - w->UpdateWeather(); - - return w; + return Trinity::Containers::MapGetValuePtr(_weatherData, zone_id); } void LoadWeatherData() @@ -106,7 +66,7 @@ void LoadWeatherData() uint32 zone_id = fields[0].GetUInt32(); - WeatherData& wzc = mWeatherZoneMap[zone_id]; + WeatherData& wzc = _weatherData[zone_id]; for (uint8 season = 0; season < WEATHER_SEASONS; ++season) { @@ -142,26 +102,4 @@ void LoadWeatherData() TC_LOG_INFO("server.loading", ">> Loaded %u weather definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -void SendFineWeatherUpdateToPlayer(Player* player) -{ - WorldPackets::Misc::Weather weather(WEATHER_STATE_FINE); - player->GetSession()->SendPacket(weather.Write()); -} - -void Update(uint32 diff) -{ - ///- Send an update signal to Weather objects - WeatherMap::iterator itr, next; - for (itr = m_weathers.begin(); itr != m_weathers.end(); itr = next) - { - next = itr; - ++next; - - ///- and remove Weather objects for zones with no player - // As interval > WorldTick - if (!itr->second->Update(diff)) - m_weathers.erase(itr); - } -} - } // namespace |