mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 01:15:35 +01:00
Core/Weather: Fixed weather updates to be thread safe
(cherry picked from commit 6eb9973947)
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
#include "Vehicle.h"
|
||||
#include "VMapFactory.h"
|
||||
#include "Weather.h"
|
||||
#include "WeatherMgr.h"
|
||||
#include "World.h"
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
@@ -65,7 +66,7 @@ static uint16 const holetab_v[4] = { 0x000F, 0x00F0, 0x0F00, 0xF000 };
|
||||
GridState* si_GridStates[MAX_GRID_STATE];
|
||||
|
||||
|
||||
ZoneDynamicInfo::ZoneDynamicInfo() : MusicId(0), WeatherId(WEATHER_STATE_FINE),
|
||||
ZoneDynamicInfo::ZoneDynamicInfo() : MusicId(0), DefaultWeather(nullptr), WeatherId(WEATHER_STATE_FINE),
|
||||
WeatherGrade(0.0f), OverrideLightId(0), LightFadeInTime(0) { }
|
||||
|
||||
Map::~Map()
|
||||
@@ -288,6 +289,8 @@ i_scriptLock(false), _respawnCheckTimer(0), _defaultLight(GetDefaultMapLight(id)
|
||||
//lets initialize visibility distance for map
|
||||
Map::InitVisibilityDistance();
|
||||
|
||||
_weatherUpdateTimer.SetInterval(time_t(1 * IN_MILLISECONDS));
|
||||
|
||||
sScriptMgr->OnCreateMap(this);
|
||||
}
|
||||
|
||||
@@ -589,7 +592,6 @@ bool Map::AddPlayerToMap(Player* player)
|
||||
|
||||
SendInitSelf(player);
|
||||
SendInitTransports(player);
|
||||
SendZoneDynamicInfo(player);
|
||||
|
||||
player->m_clientGUIDs.clear();
|
||||
player->UpdateObjectVisibility(false);
|
||||
@@ -858,6 +860,15 @@ void Map::Update(uint32 t_diff)
|
||||
i_scriptLock = false;
|
||||
}
|
||||
|
||||
if (_weatherUpdateTimer.Passed())
|
||||
{
|
||||
for (auto&& zoneInfo : _zoneDynamicInfo)
|
||||
if (zoneInfo.second.DefaultWeather && !zoneInfo.second.DefaultWeather->Update(_weatherUpdateTimer.GetInterval()))
|
||||
zoneInfo.second.DefaultWeather.reset();
|
||||
|
||||
_weatherUpdateTimer.Reset();
|
||||
}
|
||||
|
||||
MoveAllCreaturesInMoveList();
|
||||
MoveAllGameObjectsInMoveList();
|
||||
|
||||
@@ -4559,10 +4570,9 @@ void Map::RemoveOldCorpses()
|
||||
}
|
||||
}
|
||||
|
||||
void Map::SendZoneDynamicInfo(Player* player)
|
||||
void Map::SendZoneDynamicInfo(uint32 zoneId, Player* player) const
|
||||
{
|
||||
uint32 zoneId = GetZoneId(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
|
||||
ZoneDynamicInfoMap::const_iterator itr = _zoneDynamicInfo.find(zoneId);
|
||||
auto itr = _zoneDynamicInfo.find(zoneId);
|
||||
if (itr == _zoneDynamicInfo.end())
|
||||
return;
|
||||
|
||||
@@ -4573,11 +4583,7 @@ void Map::SendZoneDynamicInfo(Player* player)
|
||||
player->SendDirectMessage(&data);
|
||||
}
|
||||
|
||||
if (WeatherState weatherId = itr->second.WeatherId)
|
||||
{
|
||||
WorldPackets::Misc::Weather weather(weatherId, itr->second.WeatherGrade);
|
||||
player->SendDirectMessage(weather.Write());
|
||||
}
|
||||
SendZoneWeather(itr->second, player);
|
||||
|
||||
if (uint32 overrideLight = itr->second.OverrideLightId)
|
||||
{
|
||||
@@ -4589,11 +4595,32 @@ void Map::SendZoneDynamicInfo(Player* player)
|
||||
}
|
||||
}
|
||||
|
||||
void Map::SendZoneWeather(uint32 zoneId, Player* player) const
|
||||
{
|
||||
auto itr = _zoneDynamicInfo.find(zoneId);
|
||||
if (itr == _zoneDynamicInfo.end())
|
||||
return;
|
||||
|
||||
SendZoneWeather(itr->second, player);
|
||||
}
|
||||
|
||||
void Map::SendZoneWeather(ZoneDynamicInfo const& zoneDynamicInfo, Player* player) const
|
||||
{
|
||||
if (WeatherState weatherId = zoneDynamicInfo.WeatherId)
|
||||
{
|
||||
WorldPackets::Misc::Weather weather(weatherId, zoneDynamicInfo.WeatherGrade);
|
||||
player->SendDirectMessage(weather.Write());
|
||||
}
|
||||
else if (zoneDynamicInfo.DefaultWeather)
|
||||
{
|
||||
zoneDynamicInfo.DefaultWeather->SendWeatherUpdateToPlayer(player);
|
||||
}
|
||||
else
|
||||
Weather::SendFineWeatherUpdateToPlayer(player);
|
||||
}
|
||||
|
||||
void Map::SetZoneMusic(uint32 zoneId, uint32 musicId)
|
||||
{
|
||||
if (_zoneDynamicInfo.find(zoneId) == _zoneDynamicInfo.end())
|
||||
_zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo()));
|
||||
|
||||
_zoneDynamicInfo[zoneId].MusicId = musicId;
|
||||
|
||||
Map::PlayerList const& players = GetPlayers();
|
||||
@@ -4609,37 +4636,49 @@ void Map::SetZoneMusic(uint32 zoneId, uint32 musicId)
|
||||
}
|
||||
}
|
||||
|
||||
Weather* Map::GetOrGenerateZoneDefaultWeather(uint32 zoneId)
|
||||
{
|
||||
WeatherData const* weatherData = WeatherMgr::GetWeatherData(zoneId);
|
||||
if (!weatherData)
|
||||
return nullptr;
|
||||
|
||||
ZoneDynamicInfo& info = _zoneDynamicInfo[zoneId];
|
||||
if (!info.DefaultWeather)
|
||||
{
|
||||
info.DefaultWeather = Trinity::make_unique<Weather>(zoneId, weatherData);
|
||||
info.DefaultWeather->ReGenerate();
|
||||
info.DefaultWeather->UpdateWeather();
|
||||
}
|
||||
|
||||
return info.DefaultWeather.get();
|
||||
}
|
||||
|
||||
void Map::SetZoneWeather(uint32 zoneId, WeatherState weatherId, float weatherGrade)
|
||||
{
|
||||
if (_zoneDynamicInfo.find(zoneId) == _zoneDynamicInfo.end())
|
||||
_zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo()));
|
||||
|
||||
ZoneDynamicInfo& info = _zoneDynamicInfo[zoneId];
|
||||
info.WeatherId = weatherId;
|
||||
info.WeatherGrade = weatherGrade;
|
||||
Map::PlayerList const& players = GetPlayers();
|
||||
|
||||
Map::PlayerList const& players = GetPlayers();
|
||||
if (!players.isEmpty())
|
||||
{
|
||||
WorldPackets::Misc::Weather weather(weatherId, weatherGrade);
|
||||
weather.Write();
|
||||
|
||||
for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
|
||||
if (Player* player = itr->GetSource())
|
||||
if (player->GetZoneId() == zoneId)
|
||||
player->SendDirectMessage(weather.Write());
|
||||
player->SendDirectMessage(weather.GetRawPacket());
|
||||
}
|
||||
}
|
||||
|
||||
void Map::SetZoneOverrideLight(uint32 zoneId, uint32 lightId, uint32 fadeInTime)
|
||||
{
|
||||
if (_zoneDynamicInfo.find(zoneId) == _zoneDynamicInfo.end())
|
||||
_zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo()));
|
||||
|
||||
ZoneDynamicInfo& info = _zoneDynamicInfo[zoneId];
|
||||
info.OverrideLightId = lightId;
|
||||
info.LightFadeInTime = fadeInTime;
|
||||
Map::PlayerList const& players = GetPlayers();
|
||||
|
||||
Map::PlayerList const& players = GetPlayers();
|
||||
if (!players.isEmpty())
|
||||
{
|
||||
WorldPacket data(SMSG_OVERRIDE_LIGHT, 4 + 4 + 1);
|
||||
|
||||
Reference in New Issue
Block a user