From 197ebb6bfd30ef52e6a9a5e88ab1df6ef64faf00 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Mon, 11 Jan 2010 13:31:37 +0300 Subject: [PATCH] [9147] More code cleanup in poolmgr. * Use normal result pointer instead args pair in pool roll. * Send PoolObject pointer into (Re)Spawn1Object and set internaly spawned field. --- src/game/PoolManager.cpp | 102 +++++++++++++++++++-------------------- src/game/PoolManager.h | 6 +-- src/shared/revision_nr.h | 2 +- 3 files changed, 54 insertions(+), 56 deletions(-) diff --git a/src/game/PoolManager.cpp b/src/game/PoolManager.cpp index c8abdf63f..97fc3f5c7 100644 --- a/src/game/PoolManager.cpp +++ b/src/game/PoolManager.cpp @@ -68,7 +68,7 @@ bool PoolGroup::IsSpawnedObject(uint32 guid) const } template -void PoolGroup::RollOne(int32& index, PoolObjectList** store, uint32 triggerFrom) +PoolObject* PoolGroup::RollOne(uint32 triggerFrom) { if (!ExplicitlyChanced.empty()) { @@ -80,27 +80,20 @@ void PoolGroup::RollOne(int32& index, PoolObjectList** store, uint32 triggerF // Triggering object is marked as spawned at this time and can be also rolled (respawn case) // so this need explicit check for this case if (roll < 0 && (!ExplicitlyChanced[i].spawned || ExplicitlyChanced[i].guid == triggerFrom)) - { - index = i; - *store = &ExplicitlyChanced; - return; - } + return &ExplicitlyChanced[i]; } } if (!EqualChanced.empty()) { - index = irand(0, EqualChanced.size()-1); + int32 index = irand(0, EqualChanced.size()-1); // Triggering object is marked as spawned at this time and can be also rolled (respawn case) // so this need explicit check for this case if (!EqualChanced[index].spawned || EqualChanced[index].guid == triggerFrom) - { - *store = &EqualChanced; - return; - } + return &EqualChanced[index]; } - index = -1; + return NULL; } // Main method to despawn a creature or gameobject in a pool @@ -210,23 +203,20 @@ void PoolGroup::SpawnObject(uint32 limit, uint32 triggerFrom) // This will try to spawn the rest of pool, not guaranteed for (int i = 0; i < count; ++i) { - int index; - PoolObjectList* store; - - RollOne(index, &store, triggerFrom); - if (index == -1) + PoolObject* obj = RollOne(triggerFrom); + if (!obj) continue; - if ((*store)[index].guid == lastDespawned) + if (obj->guid == lastDespawned) continue; - if ((*store)[index].guid == triggerFrom) + if (obj->guid == triggerFrom) { - (*store)[index].spawned = ReSpawn1Object(triggerFrom); + ReSpawn1Object(obj); triggerFrom = 0; continue; } else - (*store)[index].spawned = Spawn1Object((*store)[index].guid); + Spawn1Object(obj); if (triggerFrom) { @@ -242,11 +232,11 @@ void PoolGroup::SpawnObject(uint32 limit, uint32 triggerFrom) // Method that is actualy doing the spawn job on 1 creature template <> -bool PoolGroup::Spawn1Object(uint32 guid) +void PoolGroup::Spawn1Object(PoolObject* obj) { - if (CreatureData const* data = sObjectMgr.GetCreatureData(guid)) + if (CreatureData const* data = sObjectMgr.GetCreatureData(obj->guid)) { - sObjectMgr.AddCreatureToGrid(guid, data); + sObjectMgr.AddCreatureToGrid(obj->guid, data); // Spawn if necessary (loaded grids only) Map* map = const_cast(sMapMgr.CreateBaseMap(data->mapid)); @@ -254,27 +244,29 @@ bool PoolGroup::Spawn1Object(uint32 guid) if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { Creature* pCreature = new Creature; - //sLog.outDebug("Spawning creature %u",guid); - if (!pCreature->LoadFromDB(guid, map)) + //sLog.outDebug("Spawning creature %u",obj->guid); + if (!pCreature->LoadFromDB(obj->guid, map)) { delete pCreature; - return false; + obj->spawned = false; + return; } else map->Add(pCreature); } - return true; + obj->spawned = true; + return; } - return false; + obj->spawned = false; } // Same for 1 gameobject template <> -bool PoolGroup::Spawn1Object(uint32 guid) +void PoolGroup::Spawn1Object(PoolObject* obj) { - if (GameObjectData const* data = sObjectMgr.GetGOData(guid)) + if (GameObjectData const* data = sObjectMgr.GetGOData(obj->guid)) { - sObjectMgr.AddGameobjectToGrid(guid, data); + sObjectMgr.AddGameobjectToGrid(obj->guid, data); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existed Map* map = const_cast(sMapMgr.CreateBaseMap(data->mapid)); @@ -282,11 +274,12 @@ bool PoolGroup::Spawn1Object(uint32 guid) if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { GameObject* pGameobject = new GameObject; - //sLog.outDebug("Spawning gameobject %u", guid); - if (!pGameobject->LoadFromDB(guid, map)) + //sLog.outDebug("Spawning gameobject %u", obj->guid); + if (!pGameobject->LoadFromDB(obj->guid, map)) { delete pGameobject; - return false; + obj->spawned = false; + return; } else { @@ -294,50 +287,55 @@ bool PoolGroup::Spawn1Object(uint32 guid) map->Add(pGameobject); } } - return true; + obj->spawned = true; + return; } - return false; + obj->spawned = false; } // Same for 1 pool template <> -bool PoolGroup::Spawn1Object(uint32 child_pool_id) +void PoolGroup::Spawn1Object(PoolObject* obj) { - sPoolMgr.SpawnPool(child_pool_id); - return true; + sPoolMgr.SpawnPool(obj->guid); + obj->spawned = true; } // Method that does the respawn job on the specified creature template <> -bool PoolGroup::ReSpawn1Object(uint32 guid) +void PoolGroup::ReSpawn1Object(PoolObject* obj) { - if (CreatureData const* data = sObjectMgr.GetCreatureData(guid)) + if (CreatureData const* data = sObjectMgr.GetCreatureData(obj->guid)) { - if (Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_UNIT))) + if (Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(obj->guid, data->id, HIGHGUID_UNIT))) pCreature->GetMap()->Add(pCreature); - return true; + obj->spawned = true; + return; } - return false; + + obj->spawned = false; } // Same for 1 gameobject template <> -bool PoolGroup::ReSpawn1Object(uint32 guid) +void PoolGroup::ReSpawn1Object(PoolObject* obj) { - if (GameObjectData const* data = sObjectMgr.GetGOData(guid)) + if (GameObjectData const* data = sObjectMgr.GetGOData(obj->guid)) { - if (GameObject* pGameobject = ObjectAccessor::GetGameObjectInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_GAMEOBJECT))) + if (GameObject* pGameobject = ObjectAccessor::GetGameObjectInWorld(MAKE_NEW_GUID(obj->guid, data->id, HIGHGUID_GAMEOBJECT))) pGameobject->GetMap()->Add(pGameobject); - return true; + obj->spawned = true; + return; } - return false; + + obj->spawned = false; } // Nothing to do for a child Pool template <> -bool PoolGroup::ReSpawn1Object(uint32 /*guid*/) +void PoolGroup::ReSpawn1Object(PoolObject* obj) { - return true; + obj->spawned = true; } diff --git a/src/game/PoolManager.h b/src/game/PoolManager.h index 01e333358..2da420e1e 100644 --- a/src/game/PoolManager.h +++ b/src/game/PoolManager.h @@ -47,13 +47,13 @@ class PoolGroup bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); } void AddEntry(PoolObject& poolitem, uint32 maxentries); bool CheckPool() const; - void RollOne(int32& index, PoolObjectList** store, uint32 triggerFrom); + PoolObject* RollOne(uint32 triggerFrom); bool IsSpawnedObject(uint32 guid) const; void DespawnObject(uint32 guid=0); void Despawn1Object(uint32 guid); void SpawnObject(uint32 limit, uint32 triggerFrom); - bool Spawn1Object(uint32 guid); - bool ReSpawn1Object(uint32 guid); + void Spawn1Object(PoolObject* obj); + void ReSpawn1Object(PoolObject* obj); void RemoveOneRelation(uint16 child_pool_id); private: PoolObjectList ExplicitlyChanced; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 3c074d5ce..a4c996ae6 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 "9146" + #define REVISION_NR "9147" #endif // __REVISION_NR_H__