From 673d2fff4022e5f14f102a7dba4dfd8edb2988a3 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 4 Jan 2022 18:46:40 -0500 Subject: [PATCH] Core/Map: Kill zoneId from RespawnInfo, all it did was significantly slow down startup to make one gm command faster Port From (https://github.com/TrinityCore/TrinityCore/commit/8f3904f8fd4e7536d1e7ba8e701f4774519fd867) --- Source/Game/Chat/Commands/ListCommands.cs | 23 ++++++++++++++----- Source/Game/Chat/Commands/MiscCommands.cs | 2 +- Source/Game/Entities/Creature/Creature.cs | 2 +- Source/Game/Entities/GameObject/GameObject.cs | 2 +- Source/Game/Maps/Map.cs | 18 ++++++--------- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Source/Game/Chat/Commands/ListCommands.cs b/Source/Game/Chat/Commands/ListCommands.cs index 0cc6673b2..f2fabfd94 100644 --- a/Source/Game/Chat/Commands/ListCommands.cs +++ b/Source/Game/Chat/Commands/ListCommands.cs @@ -579,28 +579,39 @@ namespace Game.Chat.Commands string stringOverdue = Global.ObjectMgr.GetCypherString(CypherStrings.ListRespawnsOverdue, locale); uint zoneId = player.GetZoneId(); - + string zoneName = GetZoneName(zoneId, locale); for (SpawnObjectType type = 0; type < SpawnObjectType.Max; type++) { if (range != 0) handler.SendSysMessage(CypherStrings.ListRespawnsRange, type, range); else - handler.SendSysMessage(CypherStrings.ListRespawnsZone, type, GetZoneName(zoneId, locale), zoneId); + handler.SendSysMessage(CypherStrings.ListRespawnsZone, type, zoneName, zoneId); handler.SendSysMessage(CypherStrings.ListRespawnsListheader); List respawns = new(); - map.GetRespawnInfo(respawns, (SpawnObjectTypeMask)(1 << (int)type), range != 0 ? 0 : zoneId); + map.GetRespawnInfo(respawns, (SpawnObjectTypeMask)(1 << (int)type)); foreach (RespawnInfo ri in respawns) { SpawnData data = Global.ObjectMgr.GetSpawnData(ri.type, ri.spawnId); if (data == null) continue; - if (range != 0 && !player.IsInDist(data.spawnPoint, range)) - continue; + + uint respawnZoneId = map.GetZoneId(PhasingHandler.EmptyPhaseShift, data.spawnPoint); + if (range != 0) + { + if (!player.IsInDist(data.spawnPoint, range)) + continue; + } + else + { + if (zoneId != respawnZoneId) + continue; + } + uint gridY = ri.gridId / MapConst.MaxGrids; uint gridX = ri.gridId % MapConst.MaxGrids; string respawnTime = ri.respawnTime > GameTime.GetGameTime() ? Time.secsToTimeString((ulong)(ri.respawnTime - GameTime.GetGameTime()), true) : stringOverdue; - handler.SendSysMessage($"{ri.spawnId} | {ri.entry} | [{gridX:2},{gridY:2}] | {GetZoneName(ri.zoneId, locale)} ({ri.zoneId}) | {respawnTime}{(map.IsSpawnGroupActive(data.spawnGroupData.groupId) ? "" : " (inactive)")}"); + handler.SendSysMessage($"{ri.spawnId} | {ri.entry} | [{gridX:2},{gridY:2}] | {GetZoneName(respawnZoneId, locale)} ({respawnZoneId}) | {respawnTime}{(map.IsSpawnGroupActive(data.spawnGroupData.groupId) ? "" : " (inactive)")}"); } } return true; diff --git a/Source/Game/Chat/Commands/MiscCommands.cs b/Source/Game/Chat/Commands/MiscCommands.cs index 9ebdb9748..54a842493 100644 --- a/Source/Game/Chat/Commands/MiscCommands.cs +++ b/Source/Game/Chat/Commands/MiscCommands.cs @@ -1953,7 +1953,7 @@ namespace Game.Chat // Now handle any that had despawned, but had respawn time logged. List data = new(); - player.GetMap().GetRespawnInfo(data, SpawnObjectTypeMask.All, 0); + player.GetMap().GetRespawnInfo(data, SpawnObjectTypeMask.All); if (!data.Empty()) { uint gridId = GridDefines.ComputeGridCoord(player.GetPositionX(), player.GetPositionY()).GetId(); diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 32e21b2ec..08ffc8943 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -2265,7 +2265,7 @@ namespace Game.Entities } long thisRespawnTime = forceDelay != 0 ? GameTime.GetGameTime() + forceDelay : m_respawnTime; - GetMap().SaveRespawnTime(SpawnObjectType.Creature, m_spawnId, GetEntry(), thisRespawnTime, GetMap().GetZoneId(GetPhaseShift(), GetHomePosition()), GridDefines.ComputeGridCoord(GetHomePosition().GetPositionX(), GetHomePosition().GetPositionY()).GetId()); + GetMap().SaveRespawnTime(SpawnObjectType.Creature, m_spawnId, GetEntry(), thisRespawnTime, GridDefines.ComputeGridCoord(GetHomePosition().GetPositionX(), GetHomePosition().GetPositionY()).GetId()); } public bool CanCreatureAttack(Unit victim, bool force = true) diff --git a/Source/Game/Entities/GameObject/GameObject.cs b/Source/Game/Entities/GameObject/GameObject.cs index 23937b082..37a2d1f62 100644 --- a/Source/Game/Entities/GameObject/GameObject.cs +++ b/Source/Game/Entities/GameObject/GameObject.cs @@ -1267,7 +1267,7 @@ namespace Game.Entities } long thisRespawnTime = forceDelay != 0 ? GameTime.GetGameTime() + forceDelay : m_respawnTime; - GetMap().SaveRespawnTime(SpawnObjectType.GameObject, m_spawnId, GetEntry(), thisRespawnTime, GetZoneId(), GridDefines.ComputeGridCoord(GetPositionX(), GetPositionY()).GetId()); + GetMap().SaveRespawnTime(SpawnObjectType.GameObject, m_spawnId, GetEntry(), thisRespawnTime, GridDefines.ComputeGridCoord(GetPositionX(), GetPositionY()).GetId()); } } diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index 05f757e80..d24708c4b 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -2487,19 +2487,18 @@ namespace Game.Maps return true; } - static void PushRespawnInfoFrom(List data, Dictionary map, uint zoneId) + static void PushRespawnInfoFrom(List data, Dictionary map) { foreach (var pair in map) - if (zoneId == 0 || pair.Value.zoneId == zoneId) - data.Add(pair.Value); + data.Add(pair.Value); } - public void GetRespawnInfo(List respawnData, SpawnObjectTypeMask types, uint zoneId) + public void GetRespawnInfo(List respawnData, SpawnObjectTypeMask types) { if (types.HasAnyFlag(SpawnObjectTypeMask.Creature)) - PushRespawnInfoFrom(respawnData, _creatureRespawnTimesBySpawnId, zoneId); + PushRespawnInfoFrom(respawnData, _creatureRespawnTimesBySpawnId); if (types.HasAnyFlag(SpawnObjectTypeMask.GameObject)) - PushRespawnInfoFrom(respawnData, _gameObjectRespawnTimesBySpawnId, zoneId); + PushRespawnInfoFrom(respawnData, _gameObjectRespawnTimesBySpawnId); } RespawnInfo GetRespawnInfo(SpawnObjectType type, ulong spawnId) @@ -3025,7 +3024,7 @@ namespace Game.Maps m_activeNonPlayers.Remove(obj); } - public void SaveRespawnTime(SpawnObjectType type, ulong spawnId, uint entry, long respawnTime, uint zoneId, uint gridId = 0, SQLTransaction dbTrans = null, bool startup = false) + public void SaveRespawnTime(SpawnObjectType type, ulong spawnId, uint entry, long respawnTime, uint gridId = 0, SQLTransaction dbTrans = null, bool startup = false) { if (spawnId == 0) return; @@ -3043,7 +3042,6 @@ namespace Game.Maps ri.entry = entry; ri.respawnTime = respawnTime; ri.gridId = gridId; - ri.zoneId = zoneId; bool success = AddRespawnInfo(ri); if (startup) @@ -3085,7 +3083,7 @@ namespace Game.Maps { SpawnData data = Global.ObjectMgr.GetSpawnData(type, spawnId); if (data != null) - SaveRespawnTime(type, spawnId, data.Id, respawnTime, GetZoneId(PhasingHandler.EmptyPhaseShift, data.spawnPoint), GridDefines.ComputeGridCoord(data.spawnPoint.GetPositionX(), data.spawnPoint.GetPositionY()).GetId(), null, true); + SaveRespawnTime(type, spawnId, data.Id, respawnTime, GridDefines.ComputeGridCoord(data.spawnPoint.GetPositionX(), data.spawnPoint.GetPositionY()).GetId(), null, true); else Log.outError(LogFilter.Maps, $"Loading saved respawn time of {respawnTime} for spawnid ({type},{spawnId}) - spawn does not exist, ignoring"); } @@ -5567,7 +5565,6 @@ namespace Game.Maps public uint entry; public long respawnTime; public uint gridId; - public uint zoneId; public RespawnInfo() { } public RespawnInfo(RespawnInfo info) @@ -5577,7 +5574,6 @@ namespace Game.Maps entry = info.entry; respawnTime = info.respawnTime; gridId = info.gridId; - zoneId = info.zoneId; } }