diff options
| author | Treeston <treeston.mmoc@gmail.com> | 2019-07-15 17:14:58 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2021-12-16 01:33:09 +0100 |
| commit | eee950cdd7bcbe9443a53ea5c4cce35444a503f7 (patch) | |
| tree | eba357353a54d8a6dc308e0a4c732f6459eb1bee /src/server/game/Maps/Map.h | |
| parent | d5e58cef694d3db65f0a27b93099ae4e517685a4 (diff) | |
Core/Misc: Various dynspawn cleanup and refactors split off from pooling rewrite:
- Map::RemoveRespawnTime(SpawnObjectType, LowType, doRespawn) split into Map::Respawn and Map::RemoveRespawnTime, without the extra boolean
- Map::RemoveRespawnTime(RespawnInfo*) merged into Map::DeleteRespawnInfo(RespawnInfo*) and is now private
- Map::DeleteRespawnInfo(void) renamed to Map::UnloadAllRespawnInfos to properly describe what it does
- Map::ProcessRespawns now actually saves the delayed respawn time to DB if the respawn was delayed
- Map::AddRespawnInfo now takes const reference, and returns success as a boolean
- Map::AddRespawnInfo no longer offers an unused "replace" parameter
- Map::DeleteRespawnInfo no longer offers a variety of unused private overloads
- Map::SaveRespawnTime no longer offers a tantalizing writeDB parameter. Parameter is now called "startup" to properly describe what it does.
- Map::SaveRespawnInfoDB now takes RespawnInfo reference instead of all the various fields. Still public because compatibility mode. QQ.
- Map::GetWorldObjectBySpawnId sanitized
- Map::GetXRespawnTime methods sanitized to all go through Map::GetRespawnTime
(cherry picked from commit d60082ae866d77a12a9e6d09dfce27fc1cb5df90)
Diffstat (limited to 'src/server/game/Maps/Map.h')
| -rw-r--r-- | src/server/game/Maps/Map.h | 101 |
1 files changed, 53 insertions, 48 deletions
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 8e579b9c1c4..fe85ecf3724 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -454,7 +454,18 @@ class TC_GAME_API Map : public GridRefManager<NGridType> Transport* GetTransport(ObjectGuid const& guid); Creature* GetCreatureBySpawnId(ObjectGuid::LowType spawnId) const; GameObject* GetGameObjectBySpawnId(ObjectGuid::LowType spawnId) const; - WorldObject* GetWorldObjectBySpawnId(SpawnObjectType type, ObjectGuid::LowType spawnId) const { return (type == SPAWN_TYPE_GAMEOBJECT) ? reinterpret_cast<WorldObject*>(GetGameObjectBySpawnId(spawnId)) : reinterpret_cast<WorldObject*>(GetCreatureBySpawnId(spawnId)); } + WorldObject* GetWorldObjectBySpawnId(SpawnObjectType type, ObjectGuid::LowType spawnId) const + { + switch (type) + { + case SPAWN_TYPE_CREATURE: + return reinterpret_cast<WorldObject*>(GetCreatureBySpawnId(spawnId)); + case SPAWN_TYPE_GAMEOBJECT: + return reinterpret_cast<WorldObject*>(GetGameObjectBySpawnId(spawnId)); + default: + return nullptr; + } + } MapStoredObjectTypesContainer& GetObjectsStore() { return _objectsStore; } @@ -516,26 +527,21 @@ class TC_GAME_API Map : public GridRefManager<NGridType> RESPAWN TIMES */ time_t GetLinkedRespawnTime(ObjectGuid guid) const; - time_t GetCreatureRespawnTime(ObjectGuid::LowType dbGuid) const - { - RespawnInfoMap::const_iterator itr = _creatureRespawnTimesBySpawnId.find(dbGuid); - return itr != _creatureRespawnTimesBySpawnId.end() ? itr->second->respawnTime : 0; - } - - time_t GetGORespawnTime(ObjectGuid::LowType dbGuid) const + time_t GetRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId) const { - RespawnInfoMap::const_iterator itr = _gameObjectRespawnTimesBySpawnId.find(dbGuid); - return itr != _gameObjectRespawnTimesBySpawnId.end() ? itr->second->respawnTime : 0; + auto const& map = GetRespawnMapForType(type); + auto it = map.find(spawnId); + return (it == map.end()) ? 0 : it->second->respawnTime; } - - time_t GetRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId) const { return (type == SPAWN_TYPE_GAMEOBJECT) ? GetGORespawnTime(spawnId) : GetCreatureRespawnTime(spawnId); } + time_t GetCreatureRespawnTime(ObjectGuid::LowType spawnId) const { return GetRespawnTime(SPAWN_TYPE_CREATURE, spawnId); } + time_t GetGORespawnTime(ObjectGuid::LowType spawnId) const { return GetRespawnTime(SPAWN_TYPE_GAMEOBJECT, spawnId); } void UpdatePlayerZoneStats(uint32 oldZone, uint32 newZone); - void SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 entry, time_t respawnTime, uint32 zoneId, uint32 gridId = 0, bool writeDB = true, bool replace = false, CharacterDatabaseTransaction dbTrans = nullptr); - void SaveRespawnTimeDB(SpawnObjectType type, ObjectGuid::LowType spawnId, time_t respawnTime, CharacterDatabaseTransaction dbTrans = nullptr); + void SaveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 entry, time_t respawnTime, uint32 zoneId, uint32 gridId, CharacterDatabaseTransaction dbTrans = nullptr, bool startup = false); + void SaveRespawnInfoDB(RespawnInfo const& info, CharacterDatabaseTransaction dbTrans = nullptr); void LoadRespawnTimes(); - void DeleteRespawnTimes() { DeleteRespawnInfo(); DeleteRespawnTimesInDB(GetId(), GetInstanceId()); } + void DeleteRespawnTimes() { UnloadAllRespawnInfos(); DeleteRespawnTimesInDB(GetId(), GetInstanceId()); } void LoadCorpseData(); void DeleteCorpseData(); @@ -728,45 +734,22 @@ class TC_GAME_API Map : public GridRefManager<NGridType> bool CheckRespawn(RespawnInfo* info); void DoRespawn(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 gridId); void Respawn(RespawnInfo* info, CharacterDatabaseTransaction dbTrans = nullptr); - void Respawn(std::vector<RespawnInfo*>& respawnData, CharacterDatabaseTransaction dbTrans = nullptr); - void AddRespawnInfo(RespawnInfo& info, bool replace = false); - void DeleteRespawnInfo(); - void DeleteRespawnInfo(RespawnInfo* info); - void DeleteRespawnInfo(std::vector<RespawnInfo*>& toDelete) - { - for (RespawnInfo* info : toDelete) - DeleteRespawnInfo(info); - toDelete.clear(); - } - void DeleteRespawnInfo(SpawnObjectTypeMask types, uint32 zoneId = 0) - { - std::vector<RespawnInfo*> v; - GetRespawnInfo(v, types, zoneId); - if (!v.empty()) - DeleteRespawnInfo(v); - } - void DeleteRespawnInfo(SpawnObjectType type, ObjectGuid::LowType spawnId) - { - if (RespawnInfo* info = GetRespawnInfo(type, spawnId)) - DeleteRespawnInfo(info); - } + bool AddRespawnInfo(RespawnInfo const& info); + void UnloadAllRespawnInfos(); + void DeleteRespawnInfo(RespawnInfo* info, CharacterDatabaseTransaction dbTrans = nullptr); public: void GetRespawnInfo(std::vector<RespawnInfo*>& respawnData, SpawnObjectTypeMask types, uint32 zoneId = 0) const; RespawnInfo* GetRespawnInfo(SpawnObjectType type, ObjectGuid::LowType spawnId) const; - void RemoveRespawnTime(RespawnInfo* info, bool doRespawn = false, CharacterDatabaseTransaction dbTrans = nullptr); - void RemoveRespawnTime(std::vector<RespawnInfo*>& respawnData, bool doRespawn = false, CharacterDatabaseTransaction dbTrans = nullptr); - void RemoveRespawnTime(SpawnObjectTypeMask types = SPAWN_TYPEMASK_ALL, uint32 zoneId = 0, bool doRespawn = false, CharacterDatabaseTransaction dbTrans = nullptr) + void Respawn(SpawnObjectType type, ObjectGuid::LowType spawnId, CharacterDatabaseTransaction dbTrans = nullptr) { - std::vector<RespawnInfo*> v; - GetRespawnInfo(v, types, zoneId); - if (!v.empty()) - RemoveRespawnTime(v, doRespawn, dbTrans); + if (RespawnInfo* info = GetRespawnInfo(type, spawnId)) + Respawn(info, dbTrans); } - void RemoveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, bool doRespawn = false, CharacterDatabaseTransaction dbTrans = nullptr) + void RemoveRespawnTime(SpawnObjectType type, ObjectGuid::LowType spawnId, CharacterDatabaseTransaction dbTrans = nullptr) { if (RespawnInfo* info = GetRespawnInfo(type, spawnId)) - RemoveRespawnTime(info, doRespawn, dbTrans); + DeleteRespawnInfo(info, dbTrans); } SpawnGroupTemplateData const* GetSpawnGroupData(uint32 groupId) const; @@ -819,8 +802,30 @@ class TC_GAME_API Map : public GridRefManager<NGridType> RespawnListContainer _respawnTimes; RespawnInfoMap _creatureRespawnTimesBySpawnId; RespawnInfoMap _gameObjectRespawnTimesBySpawnId; - RespawnInfoMap& GetRespawnMapForType(SpawnObjectType type) { return (type == SPAWN_TYPE_GAMEOBJECT) ? _gameObjectRespawnTimesBySpawnId : _creatureRespawnTimesBySpawnId; } - RespawnInfoMap const& GetRespawnMapForType(SpawnObjectType type) const { return (type == SPAWN_TYPE_GAMEOBJECT) ? _gameObjectRespawnTimesBySpawnId : _creatureRespawnTimesBySpawnId; } + RespawnInfoMap& GetRespawnMapForType(SpawnObjectType type) + { + switch (type) + { + default: + ASSERT(false); + case SPAWN_TYPE_CREATURE: + return _creatureRespawnTimesBySpawnId; + case SPAWN_TYPE_GAMEOBJECT: + return _gameObjectRespawnTimesBySpawnId; + } + } + RespawnInfoMap const& GetRespawnMapForType(SpawnObjectType type) const + { + switch (type) + { + default: + ASSERT(false); + case SPAWN_TYPE_CREATURE: + return _creatureRespawnTimesBySpawnId; + case SPAWN_TYPE_GAMEOBJECT: + return _gameObjectRespawnTimesBySpawnId; + } + } void SetSpawnGroupActive(uint32 groupId, bool state); std::unordered_set<uint32> _toggledSpawnGroupIds; |
