From 03c9654d17263c39932637f3b5b63801ae432513 Mon Sep 17 00:00:00 2001 From: XTZGZoReX Date: Wed, 30 Sep 2009 18:15:28 +0200 Subject: [PATCH] [8574] Use map pointer in BattleGround for faster access this avoids the HashMapHolder usage when searching for objects --- src/game/BattleGround.cpp | 38 ++++++++++++++++++-------------------- src/game/BattleGround.h | 10 ++++++++++ src/game/BattleGroundEY.cpp | 2 +- src/game/BattleGroundMgr.cpp | 2 +- src/game/BattleGroundWS.cpp | 2 +- src/game/MapInstanced.cpp | 1 + src/shared/revision_nr.h | 2 +- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp index f993c3b88..7e3bc1cf8 100644 --- a/src/game/BattleGround.cpp +++ b/src/game/BattleGround.cpp @@ -152,6 +152,7 @@ BattleGround::BattleGround() m_MinPlayers = 0; m_MapId = 0; + m_Map = NULL; m_TeamStartLocX[BG_TEAM_ALLIANCE] = 0; m_TeamStartLocX[BG_TEAM_HORDE] = 0; @@ -214,10 +215,12 @@ BattleGround::~BattleGround() } sBattleGroundMgr.RemoveBattleGround(GetInstanceID(), GetTypeID()); + // unload map - if (Map * map = MapManager::Instance().FindMap(GetMapId(), GetInstanceID())) - if (map->IsBattleGroundOrArena()) - ((BattleGroundMap*)map)->SetUnload(); + // map can be null at bg destruction + if (m_Map) + m_Map->SetUnload(); + // remove from bg free slot queue this->RemoveFromBGFreeSlotQueue(); @@ -1292,15 +1295,11 @@ void BattleGround::UpdatePlayerScore(Player *Source, uint32 type, uint32 value) bool BattleGround::AddObject(uint32 type, uint32 entry, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime) { - Map * map = MapManager::Instance().FindMap(GetMapId(),GetInstanceID()); - if (!map) - return false; - // must be created this way, adding to godatamap would add it to the base map of the instance // and when loading it (in go::LoadFromDB()), a new guid would be assigned to the object, and a new object would be created // so we must create it specific for this instance GameObject * go = new GameObject; - if(!go->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT),entry, map, + if(!go->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT),entry, GetBgMap(), PHASEMASK_NORMAL, x,y,z,o,rotation0,rotation1,rotation2,rotation3,100,GO_STATE_READY)) { sLog.outErrorDb("Gameobject template %u not found in database! BattleGround not created!", entry); @@ -1340,7 +1339,7 @@ bool BattleGround::AddObject(uint32 type, uint32 entry, float x, float y, float //it would be nice to correctly implement GO_ACTIVATED state and open/close doors in gameobject code void BattleGround::DoorClose(uint64 const& guid) { - GameObject *obj = HashMapHolder::Find(guid); + GameObject *obj = GetBgMap()->GetGameObject(guid); if (obj) { //if doors are open, close it @@ -1359,7 +1358,7 @@ void BattleGround::DoorClose(uint64 const& guid) void BattleGround::DoorOpen(uint64 const& guid) { - GameObject *obj = HashMapHolder::Find(guid); + GameObject *obj = GetBgMap()->GetGameObject(guid); if (obj) { //change state to be sure they will be opened @@ -1459,12 +1458,11 @@ void BattleGround::SpawnEvent(uint8 event1, uint8 event2, bool spawn) void BattleGround::SpawnBGObject(uint64 const& guid, uint32 respawntime) { - GameObject *obj = HashMapHolder::Find(guid); + Map* map = GetBgMap(); + + GameObject *obj = map->GetGameObject(guid); if(!obj) return; - Map * map = MapManager::Instance().FindMap(GetMapId(),GetInstanceID()); - if (!map) - return; if (respawntime == 0) { //we need to change state from GO_JUST_DEACTIVATED to GO_READY in case battleground is starting again @@ -1483,12 +1481,11 @@ void BattleGround::SpawnBGObject(uint64 const& guid, uint32 respawntime) void BattleGround::SpawnBGCreature(uint64 const& guid, uint32 respawntime) { - Creature* obj = HashMapHolder::Find(guid); + Map* map = GetBgMap(); + + Creature* obj = map->GetCreature(guid); if (!obj) return; - Map * map = MapManager::Instance().FindMap(GetMapId(),GetInstanceID()); - if (!map) - return; if (respawntime == 0) { obj->Respawn(); @@ -1508,12 +1505,13 @@ bool BattleGround::DelObject(uint32 type) if (!m_BgObjects[type]) return true; - GameObject *obj = HashMapHolder::Find(m_BgObjects[type]); + GameObject *obj = GetBgMap()->GetGameObject(m_BgObjects[type]); if (!obj) { sLog.outError("Can't find gobject guid: %u",GUID_LOPART(m_BgObjects[type])); return false; } + obj->SetRespawnTime(0); // not save respawn time obj->Delete(); m_BgObjects[type] = 0; @@ -1560,7 +1558,7 @@ buffs are in their positions when battleground starts */ void BattleGround::HandleTriggerBuff(uint64 const& go_guid) { - GameObject *obj = HashMapHolder::Find(go_guid); + GameObject *obj = GetBgMap()->GetGameObject(go_guid); if (!obj || obj->GetGoType() != GAMEOBJECT_TYPE_TRAP || !obj->isSpawned()) return; diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h index 2096e340a..ef7b3af24 100644 --- a/src/game/BattleGround.h +++ b/src/game/BattleGround.h @@ -36,6 +36,7 @@ class GameObject; class Group; class Player; class WorldPacket; +class BattleGroundMap; struct WorldSafeLocsEntry; @@ -394,6 +395,14 @@ class BattleGround void SetMapId(uint32 MapID) { m_MapId = MapID; } uint32 GetMapId() const { return m_MapId; } + /* Map pointers */ + void SetBgMap(BattleGroundMap* map) { m_Map = map; } + BattleGroundMap* GetBgMap() + { + ASSERT(m_Map); + return m_Map; + } + void SetTeamStartLoc(uint32 TeamID, float X, float Y, float Z, float O); void GetTeamStartLoc(uint32 TeamID, float &X, float &Y, float &Z, float &O) const { @@ -618,6 +627,7 @@ class BattleGround /* Start location */ uint32 m_MapId; + BattleGroundMap* m_Map; float m_TeamStartLocX[BG_TEAMS_COUNT]; float m_TeamStartLocY[BG_TEAMS_COUNT]; float m_TeamStartLocZ[BG_TEAMS_COUNT]; diff --git a/src/game/BattleGroundEY.cpp b/src/game/BattleGroundEY.cpp index 6f8be6c17..f3ef573f2 100644 --- a/src/game/BattleGroundEY.cpp +++ b/src/game/BattleGroundEY.cpp @@ -468,7 +468,7 @@ void BattleGroundEY::RespawnFlagAfterDrop() { RespawnFlag(true); - GameObject *obj = HashMapHolder::Find(GetDroppedFlagGUID()); + GameObject *obj = GetBgMap()->GetGameObject(GetDroppedFlagGUID()); if (obj) obj->Delete(); else diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp index 3d3dfc501..70d22c796 100644 --- a/src/game/BattleGroundMgr.cpp +++ b/src/game/BattleGroundMgr.cpp @@ -1620,7 +1620,7 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsA case BATTLEGROUND_SA: bg = new BattleGroundSA; break; case BATTLEGROUND_DS: bg = new BattleGroundDS; break; case BATTLEGROUND_RV: bg = new BattleGroundRV; break; - default:bg = new BattleGround; break; // placeholder for non implemented BG + default: bg = new BattleGround; break; // placeholder for non implemented BG } bg->SetMapId(MapID); diff --git a/src/game/BattleGroundWS.cpp b/src/game/BattleGroundWS.cpp index 21766e146..296e79875 100644 --- a/src/game/BattleGroundWS.cpp +++ b/src/game/BattleGroundWS.cpp @@ -150,7 +150,7 @@ void BattleGroundWS::RespawnFlagAfterDrop(uint32 team) PlaySoundToAll(BG_WS_SOUND_FLAGS_RESPAWNED); - GameObject *obj = HashMapHolder::Find(GetDroppedFlagGUID(team)); + GameObject *obj = GetBgMap()->GetGameObject(GetDroppedFlagGUID(team)); if (obj) obj->Delete(); else diff --git a/src/game/MapInstanced.cpp b/src/game/MapInstanced.cpp index 3b259c260..7cc88e87e 100644 --- a/src/game/MapInstanced.cpp +++ b/src/game/MapInstanced.cpp @@ -218,6 +218,7 @@ BattleGroundMap* MapInstanced::CreateBattleGroundMap(uint32 InstanceId, BattleGr BattleGroundMap *map = new BattleGroundMap(GetId(), GetGridExpiry(), InstanceId, this); ASSERT(map->IsBattleGroundOrArena()); map->SetBG(bg); + bg->SetBgMap(map); m_InstancedMaps[InstanceId] = map; return map; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index ddf8aa5d8..019795e4a 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8573" + #define REVISION_NR "8574" #endif // __REVISION_NR_H__ -- 2.11.4.GIT