Core/Pools: Implemented pooling for instances

This commit is contained in:
Shauren authored and Ovahlord committed 2022-12-29 11:56:56 +01:00
1 parent 317a9f2d32
commit 0f0b283168
10 files changed
+320 -200

No files matched your search

+222 -143
View File
@@ -21,67 +21,80 @@
#include "DatabaseEnv.h"
#include "GameObject.h"
#include "Log.h"
#include "MapManager.h"
#include "Map.h"
#include "ObjectMgr.h"
#include <sstream>
////////////////////////////////////////////////////////////
// template class ActivePoolData
// template class SpawnedPoolData
ActivePoolData::ActivePoolData() = default;
ActivePoolData::~ActivePoolData() = default;
SpawnedPoolData::SpawnedPoolData(Map* owner) : mOwner(owner) { }
SpawnedPoolData::~SpawnedPoolData() = default;
// Method that tell amount spawned objects/subpools
uint32 ActivePoolData::GetActiveObjectCount(uint32 pool_id) const
uint32 SpawnedPoolData::GetSpawnedObjects(uint32 pool_id) const
{
ActivePoolPools::const_iterator itr = mSpawnedPools.find(pool_id);
SpawnedPoolPools::const_iterator itr = mSpawnedPools.find(pool_id);
return itr != mSpawnedPools.end() ? itr->second : 0;
}
// Method that tell if a creature is spawned currently
template<>
TC_GAME_API bool ActivePoolData::IsActiveObject<Creature>(uint32 db_guid) const
TC_GAME_API bool SpawnedPoolData::IsSpawnedObject<Creature>(uint32 db_guid) const
{
return mSpawnedCreatures.find(db_guid) != mSpawnedCreatures.end();
}
// Method that tell if a gameobject is spawned currently
template<>
TC_GAME_API bool ActivePoolData::IsActiveObject<GameObject>(uint32 db_guid) const
TC_GAME_API bool SpawnedPoolData::IsSpawnedObject<GameObject>(uint32 db_guid) const
{
return mSpawnedGameobjects.find(db_guid) != mSpawnedGameobjects.end();
}
// Method that tell if a pool is spawned currently
template<>
TC_GAME_API bool ActivePoolData::IsActiveObject<Pool>(uint32 sub_pool_id) const
TC_GAME_API bool SpawnedPoolData::IsSpawnedObject<Pool>(uint32 sub_pool_id) const
{
return mSpawnedPools.find(sub_pool_id) != mSpawnedPools.end();
}
bool SpawnedPoolData::IsSpawnedObject(SpawnObjectType type, uint32 db_guid_or_pool_id) const
{
switch (type)
{
case SPAWN_TYPE_CREATURE:
return IsSpawnedObject<Creature>(db_guid_or_pool_id);
case SPAWN_TYPE_GAMEOBJECT:
return IsSpawnedObject<GameObject>(db_guid_or_pool_id);
default:
ASSERT(false, "Invalid spawn type %u passed to SpawnedPoolData::IsSpawnedObject (with spawnId %u)", uint32(type), db_guid_or_pool_id);
}
}
template<>
void ActivePoolData::ActivateObject<Creature>(uint32 db_guid, uint32 pool_id)
void SpawnedPoolData::AddSpawn<Creature>(uint32 db_guid, uint32 pool_id)
{
mSpawnedCreatures.insert(db_guid);
++mSpawnedPools[pool_id];
}
template<>
void ActivePoolData::ActivateObject<GameObject>(uint32 db_guid, uint32 pool_id)
void SpawnedPoolData::AddSpawn<GameObject>(uint32 db_guid, uint32 pool_id)
{
mSpawnedGameobjects.insert(db_guid);
++mSpawnedPools[pool_id];
}
template<>
void ActivePoolData::ActivateObject<Pool>(uint32 sub_pool_id, uint32 pool_id)
void SpawnedPoolData::AddSpawn<Pool>(uint32 sub_pool_id, uint32 pool_id)
{
mSpawnedPools[sub_pool_id] = 0;
++mSpawnedPools[pool_id];
}
template<>
void ActivePoolData::RemoveObject<Creature>(uint32 db_guid, uint32 pool_id)
void SpawnedPoolData::RemoveSpawn<Creature>(uint32 db_guid, uint32 pool_id)
{
mSpawnedCreatures.erase(db_guid);
uint32& val = mSpawnedPools[pool_id];
@@ -90,7 +103,7 @@ void ActivePoolData::RemoveObject<Creature>(uint32 db_guid, uint32 pool_id)
}
template<>
void ActivePoolData::RemoveObject<GameObject>(uint32 db_guid, uint32 pool_id)
void SpawnedPoolData::RemoveSpawn<GameObject>(uint32 db_guid, uint32 pool_id)
{
mSpawnedGameobjects.erase(db_guid);
uint32& val = mSpawnedPools[pool_id];
@@ -99,7 +112,7 @@ void ActivePoolData::RemoveObject<GameObject>(uint32 db_guid, uint32 pool_id)
}
template<>
void ActivePoolData::RemoveObject<Pool>(uint32 sub_pool_id, uint32 pool_id)
void SpawnedPoolData::RemoveSpawn<Pool>(uint32 sub_pool_id, uint32 pool_id)
{
mSpawnedPools.erase(sub_pool_id);
uint32& val = mSpawnedPools[pool_id];
@@ -118,6 +131,26 @@ PoolGroup<T>::PoolGroup() : poolId(0)
template <class T>
PoolGroup<T>::~PoolGroup() = default;
template <class T>
bool PoolGroup<T>::isEmptyDeepCheck() const
{
return isEmpty();
}
template <>
bool PoolGroup<Pool>::isEmptyDeepCheck() const
{
for (PoolObject const& explicitlyChanced : ExplicitlyChanced)
if (!sPoolMgr->IsEmpty(explicitlyChanced.guid))
return false;
for (PoolObject const& equalChanced : EqualChanced)
if (!sPoolMgr->IsEmpty(equalChanced.guid))
return false;
return true;
}
// Method to add a gameobject/creature guid to the proper list depending on pool type and chance value
template <class T>
void PoolGroup<T>::AddEntry(PoolObject& poolitem, uint32 maxentries)
@@ -147,99 +180,83 @@ bool PoolGroup<T>::CheckPool() const
// If no guid is passed, the pool is just removed (event end case)
// If guid is filled, cache will be used and no removal will occur, it just fill the cache
template<class T>
void PoolGroup<T>::DespawnObject(ActivePoolData& spawns, ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime)
void PoolGroup<T>::DespawnObject(SpawnedPoolData& spawns, ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime)
{
for (size_t i=0; i < EqualChanced.size(); ++i)
{
// if spawned
if (spawns.IsActiveObject<T>(EqualChanced[i].guid))
if (spawns.IsSpawnedObject<T>(EqualChanced[i].guid))
{
if (!guid || EqualChanced[i].guid == guid)
{
Despawn1Object(EqualChanced[i].guid, alwaysDeleteRespawnTime);
spawns.RemoveObject<T>(EqualChanced[i].guid, poolId);
Despawn1Object(spawns, EqualChanced[i].guid, alwaysDeleteRespawnTime);
spawns.RemoveSpawn<T>(EqualChanced[i].guid, poolId);
}
}
else if (alwaysDeleteRespawnTime)
RemoveRespawnTimeFromDB(EqualChanced[i].guid);
RemoveRespawnTimeFromDB(spawns, EqualChanced[i].guid);
}
for (size_t i = 0; i < ExplicitlyChanced.size(); ++i)
{
// spawned
if (spawns.IsActiveObject<T>(ExplicitlyChanced[i].guid))
if (spawns.IsSpawnedObject<T>(ExplicitlyChanced[i].guid))
{
if (!guid || ExplicitlyChanced[i].guid == guid)
{
Despawn1Object(ExplicitlyChanced[i].guid, alwaysDeleteRespawnTime);
spawns.RemoveObject<T>(ExplicitlyChanced[i].guid, poolId);
Despawn1Object(spawns, ExplicitlyChanced[i].guid, alwaysDeleteRespawnTime);
spawns.RemoveSpawn<T>(ExplicitlyChanced[i].guid, poolId);
}
}
else if (alwaysDeleteRespawnTime)
RemoveRespawnTimeFromDB(ExplicitlyChanced[i].guid);
RemoveRespawnTimeFromDB(spawns, ExplicitlyChanced[i].guid);
}
}
// Method that is actualy doing the removal job on one creature
template<>
void PoolGroup<Creature>::Despawn1Object(ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime, bool saveRespawnTime)
void PoolGroup<Creature>::Despawn1Object(SpawnedPoolData& spawns, ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime, bool saveRespawnTime)
{
if (CreatureData const* data = sObjectMgr->GetCreatureData(guid))
auto creatureBounds = spawns.GetMap()->GetCreatureBySpawnIdStore().equal_range(guid);
for (auto itr = creatureBounds.first; itr != creatureBounds.second;)
{
sObjectMgr->RemoveCreatureFromGrid(guid, data);
Map* map = sMapMgr->FindMap(data->mapId, 0);
if (map && !map->Instanceable())
{
auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(guid);
for (auto itr = creatureBounds.first; itr != creatureBounds.second; )
{
Creature* creature = itr->second;
++itr;
// For dynamic spawns, save respawn time here
if (saveRespawnTime && !creature->GetRespawnCompatibilityMode())
creature->SaveRespawnTime();
creature->AddObjectToRemoveList();
}
if (alwaysDeleteRespawnTime)
map->RemoveRespawnTime(SpawnObjectType::SPAWN_TYPE_CREATURE, guid, nullptr, true);
}
Creature* creature = itr->second;
++itr;
// For dynamic spawns, save respawn time here
if (saveRespawnTime && !creature->GetRespawnCompatibilityMode())
creature->SaveRespawnTime();
creature->AddObjectToRemoveList();
}
if (alwaysDeleteRespawnTime)
spawns.GetMap()->RemoveRespawnTime(SPAWN_TYPE_CREATURE, guid, nullptr, true);
}
// Same on one gameobject
template<>
void PoolGroup<GameObject>::Despawn1Object(ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime, bool saveRespawnTime)
void PoolGroup<GameObject>::Despawn1Object(SpawnedPoolData& spawns, ObjectGuid::LowType guid, bool alwaysDeleteRespawnTime, bool saveRespawnTime)
{
if (GameObjectData const* data = sObjectMgr->GetGameObjectData(guid))
auto gameobjectBounds = spawns.GetMap()->GetGameObjectBySpawnIdStore().equal_range(guid);
for (auto itr = gameobjectBounds.first; itr != gameobjectBounds.second;)
{
sObjectMgr->RemoveGameobjectFromGrid(guid, data);
GameObject* go = itr->second;
++itr;
Map* map = sMapMgr->FindMap(data->mapId, 0);
if (map && !map->Instanceable())
{
auto gameObjectBounds = map->GetGameObjectBySpawnIdStore().equal_range(guid);
for (auto itr = gameObjectBounds.first; itr != gameObjectBounds.second; )
{
GameObject* go = itr->second;
++itr;
// For dynamic spawns, save respawn time here
if (saveRespawnTime && !go->GetRespawnCompatibilityMode())
go->SaveRespawnTime();
go->AddObjectToRemoveList();
}
if (alwaysDeleteRespawnTime)
map->RemoveRespawnTime(SpawnObjectType::SPAWN_TYPE_GAMEOBJECT, guid, nullptr, true);
}
// For dynamic spawns, save respawn time here
if (saveRespawnTime && !go->GetRespawnCompatibilityMode())
go->SaveRespawnTime();
go->AddObjectToRemoveList();
}
if (alwaysDeleteRespawnTime)
spawns.GetMap()->RemoveRespawnTime(SPAWN_TYPE_GAMEOBJECT, guid, nullptr, true);
}
// Same on one pool
template<>
void PoolGroup<Pool>::Despawn1Object(uint32 child_pool_id, bool alwaysDeleteRespawnTime, bool /*saveRespawnTime*/)
void PoolGroup<Pool>::Despawn1Object(SpawnedPoolData& spawns, uint32 child_pool_id, bool alwaysDeleteRespawnTime, bool /*saveRespawnTime*/)
{
sPoolMgr->DespawnPool(child_pool_id, alwaysDeleteRespawnTime);
sPoolMgr->DespawnPool(spawns, child_pool_id, alwaysDeleteRespawnTime);
}
// Method for a pool only to remove any found record causing a circular dependency loop
@@ -265,9 +282,9 @@ void PoolGroup<Pool>::RemoveOneRelation(uint32 child_pool_id)
}
template <class T>
void PoolGroup<T>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 triggerFrom)
void PoolGroup<T>::SpawnObject(SpawnedPoolData& spawns, uint32 limit, uint32 triggerFrom)
{
int count = limit - spawns.GetActiveObjectCount(poolId);
int count = limit - spawns.GetSpawnedObjects(poolId);
// If triggered from some object respawn this object is still marked as spawned
// and also counted into m_SpawnedPoolAmount so we need increase count to be
@@ -290,7 +307,7 @@ void PoolGroup<T>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 trig
roll -= obj.chance;
// 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 && (obj.guid == triggerFrom || !spawns.IsActiveObject<T>(obj.guid)))
if (roll < 0 && (obj.guid == triggerFrom || !spawns.IsSpawnedObject<T>(obj.guid)))
{
rolledObjects.push_back(obj);
break;
@@ -302,7 +319,7 @@ void PoolGroup<T>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 trig
{
std::copy_if(EqualChanced.begin(), EqualChanced.end(), std::back_inserter(rolledObjects), [triggerFrom, &spawns](PoolObject const& object)
{
return object.guid == triggerFrom || !spawns.IsActiveObject<T>(object.guid);
return object.guid == triggerFrom || !spawns.IsSpawnedObject<T>(object.guid);
});
Trinity::Containers::RandomResize(rolledObjects, count);
@@ -313,13 +330,13 @@ void PoolGroup<T>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 trig
{
if (obj.guid == triggerFrom)
{
ReSpawn1Object(&obj);
ReSpawn1Object(spawns, &obj);
triggerFrom = 0;
}
else
{
spawns.ActivateObject<T>(obj.guid, poolId);
Spawn1Object(&obj);
spawns.AddSpawn<T>(obj.guid, poolId);
Spawn1Object(spawns, &obj);
}
}
}
@@ -330,20 +347,17 @@ void PoolGroup<T>::SpawnObject(ActivePoolData& spawns, uint32 limit, uint32 trig
// Method that is actualy doing the spawn job on 1 creature
template <>
void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
void PoolGroup<Creature>::Spawn1Object(SpawnedPoolData& spawns, PoolObject* obj)
{
if (CreatureData const* data = sObjectMgr->GetCreatureData(obj->guid))
{
sObjectMgr->AddCreatureToGrid(obj->guid, data);
// Spawn if necessary (loaded grids only)
Map* map = sMapMgr->FindMap(data->mapId, 0);
// We use spawn coords to spawn
if (map && !map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
if (spawns.GetMap()->IsGridLoaded(data->spawnPoint))
{
Creature* creature = new Creature();
//TC_LOG_DEBUG("pool", "Spawning creature %u", guid);
if (!creature->LoadFromDB(obj->guid, map, true, false))
if (!creature->LoadFromDB(obj->guid, spawns.GetMap(), true, false))
{
delete creature;
return;
@@ -354,28 +368,26 @@ void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
// Same for 1 gameobject
template <>
void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj)
void PoolGroup<GameObject>::Spawn1Object(SpawnedPoolData& spawns, PoolObject* obj)
{
if (GameObjectData const* data = sObjectMgr->GetGameObjectData(obj->guid))
{
sObjectMgr->AddGameobjectToGrid(obj->guid, data);
// Spawn if necessary (loaded grids only)
// this base map checked as non-instanced and then only existed
Map* map = sMapMgr->FindMap(data->mapId, 0);
// We use current coords to unspawn, not spawn coords since creature can have changed grid
if (map && !map->Instanceable() && map->IsGridLoaded(data->spawnPoint))
if (spawns.GetMap()->IsGridLoaded(data->spawnPoint))
{
GameObject* pGameobject = new GameObject;
GameObject* go = new GameObject;
//TC_LOG_DEBUG("pool", "Spawning gameobject %u", guid);
if (!pGameobject->LoadFromDB(obj->guid, map, false))
if (!go->LoadFromDB(obj->guid, spawns.GetMap(), false))
{
delete pGameobject;
delete go;
return;
}
else
{
if (pGameobject->isSpawnedByDefault())
map->AddToMap(pGameobject);
if (go->isSpawnedByDefault())
if (!spawns.GetMap()->AddToMap(go))
delete go;
}
}
}
@@ -383,59 +395,45 @@ void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj)
// Same for 1 pool
template <>
void PoolGroup<Pool>::Spawn1Object(PoolObject* obj)
void PoolGroup<Pool>::Spawn1Object(SpawnedPoolData& spawns, PoolObject* obj)
{
sPoolMgr->SpawnPool(obj->guid);
sPoolMgr->SpawnPool(spawns, obj->guid);
}
// Method that does the respawn job on the specified creature
template <>
void PoolGroup<Creature>::ReSpawn1Object(PoolObject* obj)
void PoolGroup<Creature>::ReSpawn1Object(SpawnedPoolData& spawns, PoolObject* obj)
{
Despawn1Object(obj->guid, false, false);
Spawn1Object(obj);
Despawn1Object(spawns, obj->guid, false, false);
Spawn1Object(spawns, obj);
}
// Method that does the respawn job on the specified gameobject
template <>
void PoolGroup<GameObject>::ReSpawn1Object(PoolObject* obj)
void PoolGroup<GameObject>::ReSpawn1Object(SpawnedPoolData& spawns, PoolObject* obj)
{
Despawn1Object(obj->guid, false, false);
Spawn1Object(obj);
Despawn1Object(spawns, obj->guid, false, false);
Spawn1Object(spawns, obj);
}
// Nothing to do for a child Pool
template <>
void PoolGroup<Pool>::ReSpawn1Object(PoolObject* /*obj*/) { }
void PoolGroup<Pool>::ReSpawn1Object(SpawnedPoolData& /*spawns*/, PoolObject* /*obj*/) { }
template <>
void PoolGroup<Creature>::RemoveRespawnTimeFromDB(ObjectGuid::LowType guid)
void PoolGroup<Creature>::RemoveRespawnTimeFromDB(SpawnedPoolData& spawns, ObjectGuid::LowType guid)
{
if (CreatureData const* data = sObjectMgr->GetCreatureData(guid))
{
Map* map = sMapMgr->CreateBaseMap(data->mapId);
if (!map->Instanceable())
{
map->RemoveRespawnTime(SPAWN_TYPE_CREATURE, guid, nullptr, true);
}
}
spawns.GetMap()->RemoveRespawnTime(SPAWN_TYPE_CREATURE, guid, nullptr, true);
}
template <>
void PoolGroup<GameObject>::RemoveRespawnTimeFromDB(ObjectGuid::LowType guid)
void PoolGroup<GameObject>::RemoveRespawnTimeFromDB(SpawnedPoolData& spawns, ObjectGuid::LowType guid)
{
if (GameObjectData const* data = sObjectMgr->GetGameObjectData(guid))
{
Map* map = sMapMgr->CreateBaseMap(data->mapId);
if (!map->Instanceable())
{
map->RemoveRespawnTime(SPAWN_TYPE_GAMEOBJECT, guid, nullptr, true);
}
}
spawns.GetMap()->RemoveRespawnTime(SPAWN_TYPE_GAMEOBJECT, guid, nullptr, true);
}
template <>
void PoolGroup<Pool>::RemoveRespawnTimeFromDB(ObjectGuid::LowType /*guid*/) { }
void PoolGroup<Pool>::RemoveRespawnTimeFromDB(SpawnedPoolData& /*spawns*/, ObjectGuid::LowType /*guid*/) { }
////////////////////////////////////////////////////////////
// Methods of class PoolMgr
@@ -478,6 +476,7 @@ void PoolMgr::LoadFromDB()
PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_id];
pPoolTemplate.MaxLimit = fields[1].GetUInt32();
pPoolTemplate.MapId = -1;
++count;
}
@@ -528,6 +527,15 @@ void PoolMgr::LoadFromDB()
continue;
}
PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id];
if (pPoolTemplate->MapId == -1)
pPoolTemplate->MapId = int32(data->mapId);
if (pPoolTemplate->MapId != int32(data->mapId))
{
TC_LOG_ERROR("sql.sql", "`pool_creature` has creature spawns on multiple different maps for creature guid %u in pool id (%u), skipped.", guid, pool_id);
continue;
}
PoolObject plObject = PoolObject(guid, chance);
PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id];
cregroup.SetPoolId(pool_id);
@@ -597,6 +605,15 @@ void PoolMgr::LoadFromDB()
}
PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id];
if (pPoolTemplate->MapId == -1)
pPoolTemplate->MapId = int32(data->mapId);
if (pPoolTemplate->MapId != int32(data->mapId))
{
TC_LOG_ERROR("sql.sql", "`pool_gameobject` has gameobject spawns on multiple different maps for gameobject guid (%u) in pool id (%u), skipped.", guid, pool_id);
continue;
}
PoolObject plObject = PoolObject(guid, chance);
PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id];
gogroup.SetPoolId(pool_id);
@@ -681,6 +698,21 @@ void PoolMgr::LoadFromDB()
std::set<uint32> checkedPools;
for (SearchMap::iterator poolItr = mPoolSearchMap.find(it.first); poolItr != mPoolSearchMap.end(); poolItr = mPoolSearchMap.find(poolItr->second))
{
if (mPoolTemplate[poolItr->first].MapId != -1)
{
if (mPoolTemplate[poolItr->second].MapId == -1)
mPoolTemplate[poolItr->second].MapId = mPoolTemplate[poolItr->first].MapId;
if (mPoolTemplate[poolItr->second].MapId != mPoolTemplate[poolItr->first].MapId)
{
TC_LOG_ERROR("sql.sql", "`pool_pool` has child pools on multiple maps in pool id (%u), skipped.", poolItr->second);
mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first);
mPoolSearchMap.erase(poolItr);
--count;
break;
}
}
checkedPools.insert(poolItr->first);
if (checkedPools.find(poolItr->second) != checkedPools.end())
{
@@ -703,6 +735,16 @@ void PoolMgr::LoadFromDB()
}
}
for (auto const& [poolId, templateData] : mPoolTemplate)
{
if (IsEmpty(poolId))
{
TC_LOG_ERROR("sql.sql", "Pool Id %u is empty (has no creatures and no gameobects and either no child pools or child pools are all empty. The pool will not be spawned", poolId);
continue;
}
ASSERT(templateData.MapId != -1);
}
// The initialize method will spawn all pools not in an event and not in another pool, this is why there is 2 left joins with 2 null checks
TC_LOG_INFO("server.loading", "Starting objects pooling system...");
{
@@ -725,6 +767,9 @@ void PoolMgr::LoadFromDB()
uint32 pool_entry = fields[0].GetUInt32();
uint32 pool_pool_id = fields[1].GetUInt32();
if (IsEmpty(pool_entry))
continue;
if (!CheckPool(pool_entry))
{
if (pool_pool_id)
@@ -739,14 +784,13 @@ void PoolMgr::LoadFromDB()
// Don't spawn child pools, they are spawned recursively by their parent pools
if (!pool_pool_id)
{
SpawnPool(pool_entry);
mAutoSpawnPoolsPerMap[mPoolTemplate[pool_entry].MapId].push_back(pool_entry);
count++;
}
}
while (result->NextRow());
TC_LOG_DEBUG("pool", "Pool handling system initialized, %u pools spawned in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
TC_LOG_DEBUG("pool", "Pool handling system initialized, %u pools will be spawned by default in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
}
}
@@ -754,57 +798,57 @@ void PoolMgr::LoadFromDB()
// Call to spawn a pool, if cache if true the method will spawn only if cached entry is different
// If it's same, the creature is respawned only (added back to map)
template<>
void PoolMgr::SpawnPool<Creature>(uint32 pool_id, uint32 db_guid)
void PoolMgr::SpawnPool<Creature>(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint32 db_guid)
{
auto it = mPoolCreatureGroups.find(pool_id);
if (it != mPoolCreatureGroups.end() && !it->second.isEmpty())
it->second.SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, db_guid);
it->second.SpawnObject(spawnedPoolData, mPoolTemplate[pool_id].MaxLimit, db_guid);
}
// Call to spawn a pool, if cache if true the method will spawn only if cached entry is different
// If it's same, the gameobject is respawned only (added back to map)
template<>
void PoolMgr::SpawnPool<GameObject>(uint32 pool_id, uint32 db_guid)
void PoolMgr::SpawnPool<GameObject>(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint32 db_guid)
{
auto it = mPoolGameobjectGroups.find(pool_id);
if (it != mPoolGameobjectGroups.end() && !it->second.isEmpty())
it->second.SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, db_guid);
it->second.SpawnObject(spawnedPoolData, mPoolTemplate[pool_id].MaxLimit, db_guid);
}
// Call to spawn a pool, if cache if true the method will spawn only if cached entry is different
// If it's same, the pool is respawned only
template<>
void PoolMgr::SpawnPool<Pool>(uint32 pool_id, uint32 sub_pool_id)
void PoolMgr::SpawnPool<Pool>(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint32 sub_pool_id)
{
auto it = mPoolPoolGroups.find(pool_id);
if (it != mPoolPoolGroups.end() && !it->second.isEmpty())
it->second.SpawnObject(mSpawnedData, mPoolTemplate[pool_id].MaxLimit, sub_pool_id);
it->second.SpawnObject(spawnedPoolData, mPoolTemplate[pool_id].MaxLimit, sub_pool_id);
}
void PoolMgr::SpawnPool(uint32 pool_id)
void PoolMgr::SpawnPool(SpawnedPoolData& spawnedPoolData, uint32 pool_id)
{
SpawnPool<Pool>(pool_id, 0);
SpawnPool<GameObject>(pool_id, 0);
SpawnPool<Creature>(pool_id, 0);
SpawnPool<Pool>(spawnedPoolData, pool_id, 0);
SpawnPool<GameObject>(spawnedPoolData, pool_id, 0);
SpawnPool<Creature>(spawnedPoolData, pool_id, 0);
}
// Call to despawn a pool, all gameobjects/creatures in this pool are removed
void PoolMgr::DespawnPool(uint32 pool_id, bool alwaysDeleteRespawnTime)
void PoolMgr::DespawnPool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, bool alwaysDeleteRespawnTime)
{
{
auto it = mPoolCreatureGroups.find(pool_id);
if (it != mPoolCreatureGroups.end() && !it->second.isEmpty())
it->second.DespawnObject(mSpawnedData, 0, alwaysDeleteRespawnTime);
it->second.DespawnObject(spawnedPoolData, 0, alwaysDeleteRespawnTime);
}
{
auto it = mPoolGameobjectGroups.find(pool_id);
if (it != mPoolGameobjectGroups.end() && !it->second.isEmpty())
it->second.DespawnObject(mSpawnedData, 0, alwaysDeleteRespawnTime);
it->second.DespawnObject(spawnedPoolData, 0, alwaysDeleteRespawnTime);
}
{
auto it = mPoolPoolGroups.find(pool_id);
if (it != mPoolPoolGroups.end() && !it->second.isEmpty())
it->second.DespawnObject(mSpawnedData, 0, alwaysDeleteRespawnTime);
it->second.DespawnObject(spawnedPoolData, 0, alwaysDeleteRespawnTime);
}
}
@@ -823,6 +867,26 @@ uint32 PoolMgr::IsPartOfAPool(SpawnObjectType type, ObjectGuid::LowType spawnId)
}
}
bool PoolMgr::IsEmpty(uint32 pool_id) const
{
{
auto it = mPoolGameobjectGroups.find(pool_id);
if (it != mPoolGameobjectGroups.end() && !it->second.isEmptyDeepCheck())
return false;
}
{
auto it = mPoolCreatureGroups.find(pool_id);
if (it != mPoolCreatureGroups.end() && !it->second.isEmptyDeepCheck())
return false;
}
{
auto it = mPoolPoolGroups.find(pool_id);
if (it != mPoolPoolGroups.end() && !it->second.isEmptyDeepCheck())
return false;
}
return true;
}
// Method that check chance integrity of the creatures and gameobjects in this pool
bool PoolMgr::CheckPool(uint32 pool_id) const
{
@@ -848,29 +912,44 @@ bool PoolMgr::CheckPool(uint32 pool_id) const
// Here we cache only the creature/gameobject whose guid is passed as parameter
// Then the spawn pool call will use this cache to decide
template<typename T>
void PoolMgr::UpdatePool(uint32 pool_id, uint32 db_guid_or_pool_id)
void PoolMgr::UpdatePool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint32 db_guid_or_pool_id)
{
if (uint32 motherpoolid = IsPartOfAPool<Pool>(pool_id))
SpawnPool<Pool>(motherpoolid, pool_id);
SpawnPool<Pool>(spawnedPoolData, motherpoolid, pool_id);
else
SpawnPool<T>(pool_id, db_guid_or_pool_id);
SpawnPool<T>(spawnedPoolData, pool_id, db_guid_or_pool_id);
}
template void PoolMgr::UpdatePool<Pool>(uint32 pool_id, uint32 db_guid_or_pool_id);
template void PoolMgr::UpdatePool<GameObject>(uint32 pool_id, uint32 db_guid_or_pool_id);
template void PoolMgr::UpdatePool<Creature>(uint32 pool_id, uint32 db_guid_or_pool_id);
template void PoolMgr::UpdatePool<Pool>(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint32 db_guid_or_pool_id);
template void PoolMgr::UpdatePool<GameObject>(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint32 db_guid_or_pool_id);
template void PoolMgr::UpdatePool<Creature>(SpawnedPoolData& spawnedPoolData, uint32 pool_id, uint32 db_guid_or_pool_id);
void PoolMgr::UpdatePool(uint32 pool_id, SpawnObjectType type, uint32 spawnId)
void PoolMgr::UpdatePool(SpawnedPoolData& spawnedPoolData, uint32 pool_id, SpawnObjectType type, uint32 spawnId)
{
switch (type)
{
case SPAWN_TYPE_CREATURE:
UpdatePool<Creature>(pool_id, spawnId);
UpdatePool<Creature>(spawnedPoolData, pool_id, spawnId);
break;
case SPAWN_TYPE_GAMEOBJECT:
UpdatePool<GameObject>(pool_id, spawnId);
UpdatePool<GameObject>(spawnedPoolData, pool_id, spawnId);
break;
default:
ASSERT(false, "Invalid spawn type %u passed to PoolMgr::IsPartOfPool (with spawnId %u)", uint32(type), spawnId);
}
}
std::unique_ptr<SpawnedPoolData> PoolMgr::InitPoolsForMap(Map* map)
{
std::unique_ptr<SpawnedPoolData> spawnedPoolData = std::make_unique<SpawnedPoolData>(map);
if (std::vector<uint32> const* poolIds = Trinity::Containers::MapGetValuePtr(mAutoSpawnPoolsPerMap, spawnedPoolData->GetMap()->GetId()))
for (uint32 poolId : *poolIds)
SpawnPool(*spawnedPoolData, poolId);
return spawnedPoolData;
}
PoolTemplateData const* PoolMgr::GetPoolTemplate(uint16 pool_id) const
{
return Trinity::Containers::MapGetValuePtr(mPoolTemplate, pool_id);
}