diff options
| author | Shauren <shauren.trinity@gmail.com> | 2017-09-14 22:33:40 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2019-07-09 21:17:59 +0200 |
| commit | 6eecb685ce0f3d3bf4cb7cd387b83ccf384b0c48 (patch) | |
| tree | 1371c51fa67715c8afce5e05110750be534e9ebe /src/server/game/Weather | |
| parent | 9a9af3cc5f7433a4de653b2cf28f3d8c757db8f9 (diff) | |
Core/Weather: Fixed weather updates to be thread safe
(cherry picked from commit 6eb997394722fcd4b5248646b5abfa185a7ec58f)
Diffstat (limited to 'src/server/game/Weather')
| -rw-r--r-- | src/server/game/Weather/Weather.cpp | 8 | ||||
| -rw-r--r-- | src/server/game/Weather/Weather.h | 1 | ||||
| -rw-r--r-- | src/server/game/Weather/WeatherMgr.cpp | 73 | ||||
| -rw-r--r-- | src/server/game/Weather/WeatherMgr.h | 10 |
4 files changed, 15 insertions, 77 deletions
diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp index ffdbf6eeab8..48ea407dffb 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -29,8 +29,6 @@ #include "ScriptMgr.h" #include "Util.h" #include "World.h" -#include "WorldPacket.h" -#include "WorldSession.h" /// Create the Weather object Weather::Weather(uint32 zone, WeatherData const* weatherChances) @@ -199,6 +197,12 @@ void Weather::SendWeatherUpdateToPlayer(Player* player) player->SendDirectMessage(weather.Write()); } +void Weather::SendFineWeatherUpdateToPlayer(Player* player) +{ + WorldPackets::Misc::Weather weather(WEATHER_STATE_FINE); + player->SendDirectMessage(weather.Write()); +} + /// Send the new weather to all players in the zone bool Weather::UpdateWeather() { diff --git a/src/server/game/Weather/Weather.h b/src/server/game/Weather/Weather.h index 0c2893fcbef..02f40586c5e 100644 --- a/src/server/game/Weather/Weather.h +++ b/src/server/game/Weather/Weather.h @@ -75,6 +75,7 @@ class TC_GAME_API Weather bool UpdateWeather(); void SendWeatherUpdateToPlayer(Player* player); + static void SendFineWeatherUpdateToPlayer(Player* player); void SetWeather(WeatherType type, float grade); /// For which zone is this weather? diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp index 4ebe7f4283c..51273e4766c 100644 --- a/src/server/game/Weather/WeatherMgr.cpp +++ b/src/server/game/Weather/WeatherMgr.cpp @@ -21,12 +21,12 @@ */ #include "WeatherMgr.h" +#include "Containers.h" #include "DatabaseEnv.h" #include "Log.h" #include "ObjectMgr.h" -#include "Player.h" +#include "Timer.h" #include "Weather.h" -#include "WorldSession.h" #include "MiscPackets.h" namespace WeatherMgr @@ -34,51 +34,12 @@ 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 : nullptr; - } -} - -/// 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 nullptr; - - 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 +67,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 +103,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->SendDirectMessage(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 diff --git a/src/server/game/Weather/WeatherMgr.h b/src/server/game/Weather/WeatherMgr.h index b542b99fdb8..84eb16cbc2a 100644 --- a/src/server/game/Weather/WeatherMgr.h +++ b/src/server/game/Weather/WeatherMgr.h @@ -27,18 +27,12 @@ class Weather; class Player; +struct WeatherData; namespace WeatherMgr { TC_GAME_API void LoadWeatherData(); - - TC_GAME_API Weather* FindWeather(uint32 id); - TC_GAME_API Weather* AddWeather(uint32 zone_id); - TC_GAME_API void RemoveWeather(uint32 zone_id); - - TC_GAME_API void SendFineWeatherUpdateToPlayer(Player* player); - - TC_GAME_API void Update(uint32 diff); + TC_GAME_API WeatherData const* GetWeatherData(uint32 zone_id); } #endif |
