mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 10:37:03 +00:00
[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:
parent
edfec630e8
commit
4d90a2e1f2
7 changed files with 134 additions and 85 deletions
|
|
@ -375,9 +375,9 @@ void Creature::Update(uint32 diff)
|
||||||
//Call AI respawn virtual function
|
//Call AI respawn virtual function
|
||||||
i_AI->JustRespawned();
|
i_AI->JustRespawned();
|
||||||
|
|
||||||
uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), GetTypeId());
|
uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool<Creature>(GetDBTableGUIDLow()) : 0;
|
||||||
if (poolid)
|
if (poolid)
|
||||||
sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_UNIT);
|
sPoolMgr.UpdatePool<Creature>(poolid, GetDBTableGUIDLow());
|
||||||
else
|
else
|
||||||
GetMap()->Add(this);
|
GetMap()->Add(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr)
|
||||||
{
|
sPoolMgr.SpawnPool(*itr);
|
||||||
sPoolMgr.SpawnPool(*itr, 0, 0);
|
|
||||||
sPoolMgr.SpawnPool(*itr, 0, TYPEID_GAMEOBJECT);
|
|
||||||
sPoolMgr.SpawnPool(*itr, 0, TYPEID_UNIT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventMgr::GameEventUnspawn(int16 event_id)
|
void GameEventMgr::GameEventUnspawn(int16 event_id)
|
||||||
|
|
|
||||||
|
|
@ -258,9 +258,9 @@ void GameObject::Update(uint32 /*p_time*/)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// respawn timer
|
// respawn timer
|
||||||
uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT);
|
uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool<GameObject>(GetDBTableGUIDLow()) : 0;
|
||||||
if (poolid)
|
if (poolid)
|
||||||
sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT);
|
sPoolMgr.UpdatePool<GameObject>(poolid, GetDBTableGUIDLow());
|
||||||
else
|
else
|
||||||
GetMap()->Add(this);
|
GetMap()->Add(this);
|
||||||
break;
|
break;
|
||||||
|
|
@ -473,9 +473,9 @@ void GameObject::Delete()
|
||||||
SetGoState(GO_STATE_READY);
|
SetGoState(GO_STATE_READY);
|
||||||
SetUInt32Value(GAMEOBJECT_FLAGS, GetGOInfo()->flags);
|
SetUInt32Value(GAMEOBJECT_FLAGS, GetGOInfo()->flags);
|
||||||
|
|
||||||
uint16 poolid = sPoolMgr.IsPartOfAPool(GetGUIDLow(), TYPEID_GAMEOBJECT);
|
uint16 poolid = GetDBTableGUIDLow() ? sPoolMgr.IsPartOfAPool<GameObject>(GetDBTableGUIDLow()) : 0;
|
||||||
if (poolid)
|
if (poolid)
|
||||||
sPoolMgr.UpdatePool(poolid, GetGUIDLow(), TYPEID_GAMEOBJECT);
|
sPoolMgr.UpdatePool<GameObject>(poolid, GetDBTableGUIDLow());
|
||||||
else
|
else
|
||||||
AddObjectToRemoveList();
|
AddObjectToRemoveList();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -472,8 +472,8 @@ bool ChatHandler::HandleGameObjectTargetCommand(const char* args)
|
||||||
z = fields[4].GetFloat();
|
z = fields[4].GetFloat();
|
||||||
o = fields[5].GetFloat();
|
o = fields[5].GetFloat();
|
||||||
mapid = fields[6].GetUInt16();
|
mapid = fields[6].GetUInt16();
|
||||||
pool_id = sPoolMgr.IsPartOfAPool(lowguid, TYPEID_GAMEOBJECT);
|
pool_id = sPoolMgr.IsPartOfAPool<GameObject>(lowguid);
|
||||||
if (!pool_id || (pool_id && sPoolMgr.IsSpawnedObject(pool_id, lowguid, TYPEID_GAMEOBJECT)))
|
if (!pool_id || (pool_id && sPoolMgr.IsSpawnedObject<GameObject>(pool_id, lowguid)))
|
||||||
found = true;
|
found = true;
|
||||||
} while( result->NextRow() && (!found) );
|
} while( result->NextRow() && (!found) );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -303,9 +303,7 @@ bool PoolGroup<GameObject>::Spawn1Object(uint32 guid)
|
||||||
template <>
|
template <>
|
||||||
bool PoolGroup<Pool>::Spawn1Object(uint32 child_pool_id)
|
bool PoolGroup<Pool>::Spawn1Object(uint32 child_pool_id)
|
||||||
{
|
{
|
||||||
sPoolMgr.SpawnPool(child_pool_id, 0, 0);
|
sPoolMgr.SpawnPool(child_pool_id);
|
||||||
sPoolMgr.SpawnPool(child_pool_id, 0, TYPEID_GAMEOBJECT);
|
|
||||||
sPoolMgr.SpawnPool(child_pool_id, 0, TYPEID_UNIT);
|
|
||||||
return true;
|
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);
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
SpawnPool(pool_entry, 0, 0);
|
SpawnPool(pool_entry);
|
||||||
SpawnPool(pool_entry, 0, TYPEID_GAMEOBJECT);
|
|
||||||
SpawnPool(pool_entry, 0, TYPEID_UNIT);
|
|
||||||
count++;
|
count++;
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
delete result;
|
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
|
// 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)
|
// If it's same, the creature is respawned only (added back to map)
|
||||||
void PoolManager::SpawnPool(uint16 pool_id, uint32 guid, uint32 type)
|
template<>
|
||||||
|
void PoolManager::SpawnPool<Creature>(uint16 pool_id, uint32 db_guid)
|
||||||
{
|
{
|
||||||
switch (type)
|
if (!mPoolCreatureGroups[pool_id].isEmpty())
|
||||||
{
|
mPoolCreatureGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, db_guid);
|
||||||
case TYPEID_UNIT:
|
}
|
||||||
if (!mPoolCreatureGroups[pool_id].isEmpty())
|
|
||||||
mPoolCreatureGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, guid);
|
// Call to spawn a pool, if cache if true the method will spawn only if cached entry is different
|
||||||
break;
|
// If it's same, the gameobject is respawned only (added back to map)
|
||||||
case TYPEID_GAMEOBJECT:
|
template<>
|
||||||
if (!mPoolGameobjectGroups[pool_id].isEmpty())
|
void PoolManager::SpawnPool<GameObject>(uint16 pool_id, uint32 db_guid)
|
||||||
mPoolGameobjectGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, guid);
|
{
|
||||||
break;
|
if (!mPoolGameobjectGroups[pool_id].isEmpty())
|
||||||
default:
|
mPoolGameobjectGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, db_guid);
|
||||||
if (!mPoolPoolGroups[pool_id].isEmpty())
|
}
|
||||||
mPoolPoolGroups[pool_id].SpawnObject(mPoolTemplate[pool_id].MaxLimit, 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
|
// 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();
|
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
|
// Method that check chance integrity of the creatures and gameobjects in this pool
|
||||||
bool PoolManager::CheckPool(uint16 pool_id) const
|
bool PoolManager::CheckPool(uint16 pool_id) const
|
||||||
{
|
{
|
||||||
|
|
@ -722,15 +697,45 @@ bool PoolManager::CheckPool(uint16 pool_id) const
|
||||||
mPoolPoolGroups[pool_id].CheckPool();
|
mPoolPoolGroups[pool_id].CheckPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method that tell if a creature or gameobject in pool_id is spawned currently
|
// Method that tell if a creature in pool_id is spawned currently
|
||||||
bool PoolManager::IsSpawnedObject(uint16 pool_id, uint32 guid, uint32 type) const
|
template<>
|
||||||
|
bool PoolManager::IsSpawnedObject<Creature>(uint16 pool_id, uint32 db_guid) const
|
||||||
{
|
{
|
||||||
if (pool_id > max_pool_id)
|
if (pool_id > max_pool_id)
|
||||||
return false;
|
return false;
|
||||||
if (type == 0)
|
return mPoolCreatureGroups[pool_id].IsSpawnedObject(db_guid);
|
||||||
return mPoolPoolGroups[pool_id].IsSpawnedObject(guid);
|
|
||||||
else if (type == TYPEID_GAMEOBJECT)
|
|
||||||
return mPoolGameobjectGroups[pool_id].IsSpawnedObject(guid);
|
|
||||||
else
|
|
||||||
return mPoolCreatureGroups[pool_id].IsSpawnedObject(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);
|
||||||
|
|
|
||||||
|
|
@ -70,16 +70,28 @@ class PoolManager
|
||||||
public:
|
public:
|
||||||
PoolManager();
|
PoolManager();
|
||||||
~PoolManager() {};
|
~PoolManager() {};
|
||||||
|
|
||||||
void LoadFromDB();
|
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();
|
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:
|
protected:
|
||||||
|
template<typename T>
|
||||||
|
void SpawnPool(uint16 pool_id, uint32 db_guid_or_pool_id);
|
||||||
|
|
||||||
uint16 max_pool_id;
|
uint16 max_pool_id;
|
||||||
typedef std::vector<PoolTemplateData> PoolTemplateDataMap;
|
typedef std::vector<PoolTemplateData> PoolTemplateDataMap;
|
||||||
typedef std::vector<PoolGroup<Creature> > PoolGroupCreatureMap;
|
typedef std::vector<PoolGroup<Creature> > PoolGroupCreatureMap;
|
||||||
|
|
@ -92,6 +104,8 @@ class PoolManager
|
||||||
PoolGroupCreatureMap mPoolCreatureGroups;
|
PoolGroupCreatureMap mPoolCreatureGroups;
|
||||||
PoolGroupGameObjectMap mPoolGameobjectGroups;
|
PoolGroupGameObjectMap mPoolGameobjectGroups;
|
||||||
PoolGroupPoolMap mPoolPoolGroups;
|
PoolGroupPoolMap mPoolPoolGroups;
|
||||||
|
|
||||||
|
// static maps DB low guid -> pool id
|
||||||
SearchMap mCreatureSearchMap;
|
SearchMap mCreatureSearchMap;
|
||||||
SearchMap mGameobjectSearchMap;
|
SearchMap mGameobjectSearchMap;
|
||||||
SearchMap mPoolSearchMap;
|
SearchMap mPoolSearchMap;
|
||||||
|
|
@ -99,4 +113,38 @@ class PoolManager
|
||||||
};
|
};
|
||||||
|
|
||||||
#define sPoolMgr MaNGOS::Singleton<PoolManager>::Instance()
|
#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
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "9145"
|
#define REVISION_NR "9146"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue