mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 10:37:02 +00:00
[11133] Implement template functions for call functor for all Map/MapPersistentState with some map id.
This commit is contained in:
parent
f4a2a582d9
commit
da1b616312
5 changed files with 76 additions and 7 deletions
|
|
@ -1353,6 +1353,19 @@ bool Creature::HasInvolvedQuest(uint32 quest_id) const
|
||||||
return false;
|
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()
|
void Creature::DeleteFromDB()
|
||||||
{
|
{
|
||||||
if (!m_DBTableGuid)
|
if (!m_DBTableGuid)
|
||||||
|
|
@ -1361,9 +1374,7 @@ void Creature::DeleteFromDB()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this not safe for another map copies can be
|
sMapPersistentStateMgr.DoForAllStatesWithMapId(GetMapId(), CreatureRespawnDeleteWorker(m_DBTableGuid));
|
||||||
if (MapPersistentState* save = sMapPersistentStateMgr.GetPersistentState(GetMapId(), GetInstanceId()))
|
|
||||||
save->SaveCreatureRespawnTime(m_DBTableGuid, 0);
|
|
||||||
|
|
||||||
sObjectMgr.DeleteCreatureData(m_DBTableGuid);
|
sObjectMgr.DeleteCreatureData(m_DBTableGuid);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -618,11 +618,28 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
|
||||||
return true;
|
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()
|
void GameObject::DeleteFromDB()
|
||||||
{
|
{
|
||||||
// FIXME: this can be not safe in case multiply loaded instance copies
|
if (!m_DBTableGuid)
|
||||||
if (MapPersistentState* save = sMapPersistentStateMgr.GetPersistentState(GetMapId(), GetInstanceId()))
|
{
|
||||||
save->SaveGORespawnTime(m_DBTableGuid, 0);
|
DEBUG_LOG("Trying to delete not saved gameobject!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sMapPersistentStateMgr.DoForAllStatesWithMapId(GetMapId(), GameObjectRespawnDeleteWorker(m_DBTableGuid));
|
||||||
|
|
||||||
sObjectMgr.DeleteGOData(m_DBTableGuid);
|
sObjectMgr.DeleteGOData(m_DBTableGuid);
|
||||||
WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
|
WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid);
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,9 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
|
||||||
//get list of all maps
|
//get list of all maps
|
||||||
const MapMapType& Maps() const { return i_maps; }
|
const MapMapType& Maps() const { return i_maps; }
|
||||||
|
|
||||||
|
template<typename Do>
|
||||||
|
void DoForAllMapsWithMapId(uint32 mapId, Do& _do);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// debugging code, should be deleted some day
|
// debugging code, should be deleted some day
|
||||||
|
|
@ -176,6 +179,16 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
|
||||||
IntervalTimer i_timer;
|
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()
|
#define sMapMgr MapManager::Instance()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -297,6 +297,9 @@ class MANGOS_DLL_DECL MapPersistentStateManager : public MaNGOS::Singleton<MapPe
|
||||||
|
|
||||||
void RemovePersistentState(uint32 mapId, uint32 instanceId);
|
void RemovePersistentState(uint32 mapId, uint32 instanceId);
|
||||||
|
|
||||||
|
template<typename Do>
|
||||||
|
void DoForAllStatesWithMapId(uint32 mapId, Do& _do);
|
||||||
|
|
||||||
public: // DungeonPersistentState specific
|
public: // DungeonPersistentState specific
|
||||||
void CleanupInstances();
|
void CleanupInstances();
|
||||||
void PackInstances();
|
void PackInstances();
|
||||||
|
|
@ -329,5 +332,30 @@ class MANGOS_DLL_DECL MapPersistentStateManager : public MaNGOS::Singleton<MapPe
|
||||||
DungeonResetScheduler m_Scheduler;
|
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()
|
#define sMapPersistentStateMgr MaNGOS::Singleton<MapPersistentStateManager>::Instance()
|
||||||
#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 "11132"
|
#define REVISION_NR "11133"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue