[11133] Implement template functions for call functor for all Map/MapPersistentState with some map id.

This commit is contained in:
VladimirMangos 2011-02-11 04:02:19 +03:00
parent f4a2a582d9
commit da1b616312
5 changed files with 76 additions and 7 deletions

View file

@ -1353,6 +1353,19 @@ bool Creature::HasInvolvedQuest(uint32 quest_id) const
return false;
}
struct CreatureRespawnDeleteWorker
{
explicit CreatureRespawnDeleteWorker(uint32 guid) : i_guid(guid) {}
void operator() (MapPersistentState* state)
{
state->SaveCreatureRespawnTime(i_guid, 0);
}
uint32 i_guid;
};
void Creature::DeleteFromDB()
{
if (!m_DBTableGuid)
@ -1361,9 +1374,7 @@ void Creature::DeleteFromDB()
return;
}
// FIXME: this not safe for another map copies can be
if (MapPersistentState* save = sMapPersistentStateMgr.GetPersistentState(GetMapId(), GetInstanceId()))
save->SaveCreatureRespawnTime(m_DBTableGuid, 0);
sMapPersistentStateMgr.DoForAllStatesWithMapId(GetMapId(), CreatureRespawnDeleteWorker(m_DBTableGuid));
sObjectMgr.DeleteCreatureData(m_DBTableGuid);

View file

@ -618,11 +618,28 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
return true;
}
struct GameObjectRespawnDeleteWorker
{
explicit GameObjectRespawnDeleteWorker(uint32 guid) : i_guid(guid) {}
void operator() (MapPersistentState* state)
{
state->SaveGORespawnTime(i_guid, 0);
}
uint32 i_guid;
};
void GameObject::DeleteFromDB()
{
// FIXME: this can be not safe in case multiply loaded instance copies
if (MapPersistentState* save = sMapPersistentStateMgr.GetPersistentState(GetMapId(), GetInstanceId()))
save->SaveGORespawnTime(m_DBTableGuid, 0);
if (!m_DBTableGuid)
{
DEBUG_LOG("Trying to delete not saved gameobject!");
return;
}
sMapPersistentStateMgr.DoForAllStatesWithMapId(GetMapId(), GameObjectRespawnDeleteWorker(m_DBTableGuid));
sObjectMgr.DeleteGOData(m_DBTableGuid);
WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);

View file

@ -150,6 +150,9 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
//get list of all maps
const MapMapType& Maps() const { return i_maps; }
template<typename Do>
void DoForAllMapsWithMapId(uint32 mapId, Do& _do);
private:
// debugging code, should be deleted some day
@ -176,6 +179,16 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
IntervalTimer i_timer;
};
template<typename Do>
inline void MapManager::DoForAllMapsWithMapId(uint32 mapId, Do& _do)
{
MapMapType::const_iterator start = i_maps.lower_bound(MapID(mapId,0));
MapMapType::const_iterator end = i_maps.lower_bound(MapID(mapId+1,0));
for(MapMapType::const_iterator itr = start; itr != end; ++itr)
_do(itr->second);
}
#define sMapMgr MapManager::Instance()
#endif

View file

@ -297,6 +297,9 @@ class MANGOS_DLL_DECL MapPersistentStateManager : public MaNGOS::Singleton<MapPe
void RemovePersistentState(uint32 mapId, uint32 instanceId);
template<typename Do>
void DoForAllStatesWithMapId(uint32 mapId, Do& _do);
public: // DungeonPersistentState specific
void CleanupInstances();
void PackInstances();
@ -329,5 +332,30 @@ class MANGOS_DLL_DECL MapPersistentStateManager : public MaNGOS::Singleton<MapPe
DungeonResetScheduler m_Scheduler;
};
template<typename Do>
inline void MapPersistentStateManager::DoForAllStatesWithMapId(uint32 mapId, Do& _do)
{
MapEntry const* mapEntry = sMapStore.LookupEntry(mapId);
if (!mapEntry)
return;
if (mapEntry->Instanceable())
{
for(PersistentStateMap::iterator itr = m_instanceSaveByInstanceId.begin(); itr != m_instanceSaveByInstanceId.end();)
{
if (itr->second->GetMapId() == mapId)
_do((itr++)->second);
else
++itr;
}
}
else
{
if (MapPersistentState* state = GetPersistentState(mapId, 0))
_do(state);
}
}
#define sMapPersistentStateMgr MaNGOS::Singleton<MapPersistentStateManager>::Instance()
#endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11132"
#define REVISION_NR "11133"
#endif // __REVISION_NR_H__