[9146] More poolmgr cleanps.

* Replace mixed values used type args by function template specializations
* More explcilty show fact that poolmgr work only with db guids.
This commit is contained in:
VladimirMangos 2010-01-11 12:20:49 +03:00
parent edfec630e8
commit 4d90a2e1f2
7 changed files with 134 additions and 85 deletions

View file

@ -375,9 +375,9 @@ void Creature::Update(uint32 diff)
//Call AI respawn virtual function
i_AI->JustRespawned();
uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), GetTypeId());
uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool<Creature>(GetDBTableGUIDLow()) : 0;
if (poolid)
sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_UNIT);
sPoolMgr.UpdatePool<Creature>(poolid, GetDBTableGUIDLow());
else
GetMap()->Add(this);
}

View file

@ -580,11 +580,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
}
for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr)
{
sPoolMgr.SpawnPool(*itr, 0, 0);
sPoolMgr.SpawnPool(*itr, 0, TYPEID_GAMEOBJECT);
sPoolMgr.SpawnPool(*itr, 0, TYPEID_UNIT);
}
sPoolMgr.SpawnPool(*itr);
}
void GameEventMgr::GameEventUnspawn(int16 event_id)

View file

@ -258,9 +258,9 @@ void GameObject::Update(uint32 /*p_time*/)
return;
}
// respawn timer
uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT);
uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool<GameObject>(GetDBTableGUIDLow()) : 0;
if (poolid)
sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT);
sPoolMgr.UpdatePool<GameObject>(poolid, GetDBTableGUIDLow());
else
GetMap()->Add(this);
break;
@ -473,9 +473,9 @@ void GameObject::Delete()
SetGoState(GO_STATE_READY);
SetUInt32Value(GAMEOBJECT_FLAGS, GetGOInfo()->flags);
uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT);
uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool<GameObject>(GetDBTableGUIDLow()) : 0;
if (poolid)
sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT);
sPoolMgr.UpdatePool<GameObject>(poolid, GetDBTableGUIDLow());
else
AddObjectToRemoveList();
}

View file

@ -472,8 +472,8 @@ bool ChatHandler::HandleGameObjectTargetCommand(const char* args)
z = fields[4].GetFloat();
o = fields[5].GetFloat();
mapid = fields[6].GetUInt16();
pool_id = sPoolMgr.IsPartOfAPool(lowguid, TYPEID_GAMEOBJECT);
if (!pool_id || (pool_id && sPoolMgr.IsSpawnedObject(pool_id, lowguid, TYPEID_GAMEOBJECT)))
pool_id = sPoolMgr.IsPartOfAPool<GameObject>(lowguid);
if (!pool_id || (pool_id && sPoolMgr.IsSpawnedObject<GameObject>(pool_id, lowguid)))
found = true;
} while( result->NextRow() && (!found) );

View file

@ -303,9 +303,7 @@ bool PoolGroup<GameObject>::Spawn1Object(uint32 guid)
template <>
bool PoolGroup<Pool>::Spawn1Object(uint32 child_pool_id)
{
sPoolMgr.SpawnPool(child_pool_id, 0, 0);
sPoolMgr.SpawnPool(child_pool_id, 0, TYPEID_GAMEOBJECT);
sPoolMgr.SpawnPool(child_pool_id, 0, TYPEID_UNIT);
sPoolMgr.SpawnPool(child_pool_id);
return true;
}
@ -634,9 +632,7 @@ void PoolManager::Initialize()
sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", pool_entry);
continue;
}
SpawnPool(pool_entry, 0, 0);
SpawnPool(pool_entry, 0, TYPEID_GAMEOBJECT);
SpawnPool(pool_entry, 0, TYPEID_UNIT);
SpawnPool(pool_entry);
count++;
} while (result->NextRow());
delete result;
@ -646,23 +642,37 @@ void PoolManager::Initialize()
}
// 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/creature is respawned only (added back to map)
void PoolManager::SpawnPool(uint16 pool_id, uint32 guid, uint32 type)
// If it's same, the creature is respawned only (added back to map)
template<>
void PoolManager::SpawnPool<Creature>(uint16 pool_id, uint32 db_guid)
{
switch (type)
{
case TYPEID_UNIT:
if (!mPoolCreatureGroups[pool_id].isEmpty())
mPoolCreatureGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, guid);
break;
case TYPEID_GAMEOBJECT:
if (!mPoolGameobjectGroups[pool_id].isEmpty())
mPoolGameobjectGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, guid);
break;
default:
if (!mPoolPoolGroups[pool_id].isEmpty())
mPoolPoolGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, guid);
}
if (!mPoolCreatureGroups[pool_id].isEmpty())
mPoolCreatureGroups[pool_id].SpawnObject(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 PoolManager::SpawnPool<GameObject>(uint16 pool_id, uint32 db_guid)
{
if (!mPoolGameobjectGroups[pool_id].isEmpty())
mPoolGameobjectGroups[pool_id].SpawnObject(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 PoolManager::SpawnPool<Pool>(uint16 pool_id, uint32 sub_pool_id)
{
if (!mPoolPoolGroups[pool_id].isEmpty())
mPoolPoolGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, sub_pool_id);
}
void PoolManager::SpawnPool( uint16 pool_id )
{
SpawnPool<Pool>(pool_id, 0);
SpawnPool<GameObject>(pool_id, 0);
SpawnPool<Creature>(pool_id, 0);
}
// Call to despawn a pool, all gameobjects/creatures in this pool are removed
@ -678,41 +688,6 @@ void PoolManager::DespawnPool(uint16 pool_id)
mPoolPoolGroups[pool_id].DespawnObject();
}
// Call to update the pool when a gameobject/creature part of pool [pool_id] is ready to respawn
// Here we cache only the creature/gameobject whose guid is passed as parameter
// Then the spawn pool call will use this cache to decide
void PoolManager::UpdatePool(uint16 pool_id, uint32 guid, uint32 type)
{
if (uint16 motherpoolid = IsPartOfAPool(pool_id, 0))
SpawnPool(motherpoolid, 0, 0);
else
SpawnPool(pool_id, guid, type);
}
// Method that tell if the gameobject/creature is part of a pool and return the pool id if yes
uint16 PoolManager::IsPartOfAPool(uint32 guid, uint32 type) const
{
if (type == 0) // pool of pool
{
SearchMap::const_iterator itr = mPoolSearchMap.find(guid);
if (itr != mPoolSearchMap.end())
return itr->second;
}
else if (type == TYPEID_GAMEOBJECT)
{
SearchMap::const_iterator itr = mGameobjectSearchMap.find(guid);
if (itr != mGameobjectSearchMap.end())
return itr->second;
}
else // creature
{
SearchMap::const_iterator itr = mCreatureSearchMap.find(guid);
if (itr != mCreatureSearchMap.end())
return itr->second;
}
return 0;
}
// Method that check chance integrity of the creatures and gameobjects in this pool
bool PoolManager::CheckPool(uint16 pool_id) const
{
@ -722,15 +697,45 @@ bool PoolManager::CheckPool(uint16 pool_id) const
mPoolPoolGroups[pool_id].CheckPool();
}
// Method that tell if a creature or gameobject in pool_id is spawned currently
bool PoolManager::IsSpawnedObject(uint16 pool_id, uint32 guid, uint32 type) const
// Method that tell if a creature in pool_id is spawned currently
template<>
bool PoolManager::IsSpawnedObject<Creature>(uint16 pool_id, uint32 db_guid) const
{
if (pool_id > max_pool_id)
return false;
if (type == 0)
return mPoolPoolGroups[pool_id].IsSpawnedObject(guid);
else if (type == TYPEID_GAMEOBJECT)
return mPoolGameobjectGroups[pool_id].IsSpawnedObject(guid);
else
return mPoolCreatureGroups[pool_id].IsSpawnedObject(guid);
return mPoolCreatureGroups[pool_id].IsSpawnedObject(db_guid);
}
// Method that tell if a gameobject in pool_id is spawned currently
template<>
bool PoolManager::IsSpawnedObject<GameObject>(uint16 pool_id, uint32 db_guid) const
{
if (pool_id > max_pool_id)
return false;
return mPoolGameobjectGroups[pool_id].IsSpawnedObject(db_guid);
}
// Method that tell if a pool in pool_id is spawned currently
template<>
bool PoolManager::IsSpawnedObject<Pool>(uint16 pool_id, uint32 sub_pool_id) const
{
if (pool_id > max_pool_id)
return false;
return mPoolPoolGroups[pool_id].IsSpawnedObject(sub_pool_id);
}
// Call to update the pool when a gameobject/creature part of pool [pool_id] is ready to respawn
// 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 PoolManager::UpdatePool(uint16 pool_id, uint32 db_guid_or_pool_id)
{
if (uint16 motherpoolid = IsPartOfAPool<Pool>(pool_id))
SpawnPool<Pool>(motherpoolid, 0);
else
SpawnPool<T>(pool_id, db_guid_or_pool_id);
}
template void PoolManager::UpdatePool<Pool>(uint16 pool_id, uint32 db_guid_or_pool_id);
template void PoolManager::UpdatePool<GameObject>(uint16 pool_id, uint32 db_guid_or_pool_id);
template void PoolManager::UpdatePool<Creature>(uint16 pool_id, uint32 db_guid_or_pool_id);

View file

@ -70,16 +70,28 @@ class PoolManager
public:
PoolManager();
~PoolManager() {};
void LoadFromDB();
uint16 IsPartOfAPool(uint32 guid, uint32 type) const;
bool IsSpawnedObject(uint16 pool_id, uint32 guid, uint32 type) const;
bool CheckPool(uint16 pool_id) const;
void SpawnPool(uint16 pool_id, uint32 guid, uint32 type);
void DespawnPool(uint16 pool_id);
void UpdatePool(uint16 pool_id, uint32 guid, uint32 type);
void Initialize();
template<typename T>
uint16 IsPartOfAPool(uint32 db_guid_or_pool_id) const;
template<typename T>
bool IsSpawnedObject(uint16 pool_id, uint32 db_guid_or_pool_id) const;
bool CheckPool(uint16 pool_id) const;
void SpawnPool(uint16 pool_id);
void DespawnPool(uint16 pool_id);
template<typename T>
void UpdatePool(uint16 pool_id, uint32 db_guid_or_pool_id);
protected:
template<typename T>
void SpawnPool(uint16 pool_id, uint32 db_guid_or_pool_id);
uint16 max_pool_id;
typedef std::vector<PoolTemplateData> PoolTemplateDataMap;
typedef std::vector<PoolGroup<Creature> > PoolGroupCreatureMap;
@ -92,6 +104,8 @@ class PoolManager
PoolGroupCreatureMap mPoolCreatureGroups;
PoolGroupGameObjectMap mPoolGameobjectGroups;
PoolGroupPoolMap mPoolPoolGroups;
// static maps DB low guid -> pool id
SearchMap mCreatureSearchMap;
SearchMap mGameobjectSearchMap;
SearchMap mPoolSearchMap;
@ -99,4 +113,38 @@ class PoolManager
};
#define sPoolMgr MaNGOS::Singleton<PoolManager>::Instance()
// Method that tell if the creature is part of a pool and return the pool id if yes
template<>
inline uint16 PoolManager::IsPartOfAPool<Creature>(uint32 db_guid) const
{
SearchMap::const_iterator itr = mCreatureSearchMap.find(db_guid);
if (itr != mCreatureSearchMap.end())
return itr->second;
return 0;
}
// Method that tell if the gameobject is part of a pool and return the pool id if yes
template<>
inline uint16 PoolManager::IsPartOfAPool<GameObject>(uint32 db_guid) const
{
SearchMap::const_iterator itr = mGameobjectSearchMap.find(db_guid);
if (itr != mGameobjectSearchMap.end())
return itr->second;
return 0;
}
// Method that tell if the pool is part of another pool and return the pool id if yes
template<>
inline uint16 PoolManager::IsPartOfAPool<Pool>(uint32 pool_id) const
{
SearchMap::const_iterator itr = mPoolSearchMap.find(pool_id);
if (itr != mPoolSearchMap.end())
return itr->second;
return 0;
}
#endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9145"
#define REVISION_NR "9146"
#endif // __REVISION_NR_H__