mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[9996] Remove grid state debugging code and move state machine to MapManager.
This commit is contained in:
parent
28c3de5093
commit
aa62225c68
6 changed files with 42 additions and 85 deletions
|
|
@ -24,21 +24,7 @@
|
||||||
class MANGOS_DLL_DECL GridState
|
class MANGOS_DLL_DECL GridState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#ifdef MANGOS_DEBUG
|
|
||||||
#define MAGIC_TESTVAL 0xFBE823BA
|
|
||||||
GridState() { i_Magic = MAGIC_TESTVAL; }
|
|
||||||
bool checkMagic()
|
|
||||||
{
|
|
||||||
if(i_Magic != MAGIC_TESTVAL)
|
|
||||||
{
|
|
||||||
sLog.outError("!!! GridState: Magic value gone !!!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
void setMagic() { i_Magic = MAGIC_TESTVAL; }
|
|
||||||
unsigned int i_Magic;
|
|
||||||
#endif
|
|
||||||
virtual void Update(Map &, NGridType&, GridInfo &, const uint32 &x, const uint32 &y, const uint32 &t_diff) const = 0;
|
virtual void Update(Map &, NGridType&, GridInfo &, const uint32 &x, const uint32 &y, const uint32 &t_diff) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -69,4 +55,5 @@ class MANGOS_DLL_DECL RemovalState : public GridState
|
||||||
|
|
||||||
void Update(Map &, NGridType &, GridInfo &, const uint32 &x, const uint32 &y, const uint32 &t_diff) const;
|
void Update(Map &, NGridType &, GridInfo &, const uint32 &x, const uint32 &y, const uint32 &t_diff) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@
|
||||||
#include "VMapFactory.h"
|
#include "VMapFactory.h"
|
||||||
#include "BattleGroundMgr.h"
|
#include "BattleGroundMgr.h"
|
||||||
|
|
||||||
GridState* si_GridStates[MAX_GRID_STATE];
|
|
||||||
|
|
||||||
struct ScriptAction
|
struct ScriptAction
|
||||||
{
|
{
|
||||||
uint64 sourceGUID;
|
uint64 sourceGUID;
|
||||||
|
|
@ -126,22 +124,6 @@ void Map::LoadMapAndVMap(int gx,int gy)
|
||||||
LoadVMap(gx, gy); // Only load the data for the base map
|
LoadVMap(gx, gy); // Only load the data for the base map
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::InitStateMachine()
|
|
||||||
{
|
|
||||||
si_GridStates[GRID_STATE_INVALID] = new InvalidState;
|
|
||||||
si_GridStates[GRID_STATE_ACTIVE] = new ActiveState;
|
|
||||||
si_GridStates[GRID_STATE_IDLE] = new IdleState;
|
|
||||||
si_GridStates[GRID_STATE_REMOVAL] = new RemovalState;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Map::DeleteStateMachine()
|
|
||||||
{
|
|
||||||
delete si_GridStates[GRID_STATE_INVALID];
|
|
||||||
delete si_GridStates[GRID_STATE_ACTIVE];
|
|
||||||
delete si_GridStates[GRID_STATE_IDLE];
|
|
||||||
delete si_GridStates[GRID_STATE_REMOVAL];
|
|
||||||
}
|
|
||||||
|
|
||||||
Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent)
|
Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent)
|
||||||
: i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode),
|
: i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode),
|
||||||
i_id(id), i_InstanceId(InstanceId), m_unloadTimer(0),
|
i_id(id), i_InstanceId(InstanceId), m_unloadTimer(0),
|
||||||
|
|
@ -648,7 +630,7 @@ void Map::Update(const uint32 &t_diff)
|
||||||
GridInfo *info = i->getSource()->getGridInfoRef();
|
GridInfo *info = i->getSource()->getGridInfoRef();
|
||||||
++i; // The update might delete the map and we need the next map before the iterator gets invalid
|
++i; // The update might delete the map and we need the next map before the iterator gets invalid
|
||||||
ASSERT(grid->GetGridState() >= 0 && grid->GetGridState() < MAX_GRID_STATE);
|
ASSERT(grid->GetGridState() >= 0 && grid->GetGridState() < MAX_GRID_STATE);
|
||||||
si_GridStates[grid->GetGridState()]->Update(*this, *grid, *info, grid->getX(), grid->getY(), t_diff);
|
sMapMgr.UpdateGridState(grid->GetGridState(), *this, *grid, *info, grid->getX(), grid->getY(), t_diff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,9 +144,6 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
|
||||||
time_t GetGridExpiry(void) const { return i_gridExpiry; }
|
time_t GetGridExpiry(void) const { return i_gridExpiry; }
|
||||||
uint32 GetId(void) const { return i_id; }
|
uint32 GetId(void) const { return i_id; }
|
||||||
|
|
||||||
static void InitStateMachine();
|
|
||||||
static void DeleteStateMachine();
|
|
||||||
|
|
||||||
Map const * GetParent() const { return m_parentMap; }
|
Map const * GetParent() const { return m_parentMap; }
|
||||||
|
|
||||||
// some calls like isInWater should not use vmaps due to processor power
|
// some calls like isInWater should not use vmaps due to processor power
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,8 @@
|
||||||
INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK);
|
INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK);
|
||||||
INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Thread_Mutex);
|
INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Thread_Mutex);
|
||||||
|
|
||||||
extern GridState* si_GridStates[]; // debugging code, should be deleted some day
|
MapManager::MapManager()
|
||||||
|
: i_gridCleanUpDelay(sWorld.getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN))
|
||||||
MapManager::MapManager() : i_gridCleanUpDelay(sWorld.getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN))
|
|
||||||
{
|
{
|
||||||
i_timer.SetInterval(sWorld.getConfig(CONFIG_UINT32_INTERVAL_MAPUPDATE));
|
i_timer.SetInterval(sWorld.getConfig(CONFIG_UINT32_INTERVAL_MAPUPDATE));
|
||||||
}
|
}
|
||||||
|
|
@ -49,59 +48,47 @@ MapManager::~MapManager()
|
||||||
for(TransportSet::iterator i = m_Transports.begin(); i != m_Transports.end(); ++i)
|
for(TransportSet::iterator i = m_Transports.begin(); i != m_Transports.end(); ++i)
|
||||||
delete *i;
|
delete *i;
|
||||||
|
|
||||||
Map::DeleteStateMachine();
|
DeleteStateMachine();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MapManager::Initialize()
|
MapManager::Initialize()
|
||||||
{
|
{
|
||||||
Map::InitStateMachine();
|
InitStateMachine();
|
||||||
|
|
||||||
// debugging code, should be deleted some day
|
|
||||||
{
|
|
||||||
for(int i=0;i<MAX_GRID_STATE; i++)
|
|
||||||
{
|
|
||||||
i_GridStates[i] = si_GridStates[i];
|
|
||||||
}
|
|
||||||
i_GridStateErrorCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
InitMaxInstanceId();
|
InitMaxInstanceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapManager::InitStateMachine()
|
||||||
|
{
|
||||||
|
si_GridStates[GRID_STATE_INVALID] = new InvalidState;
|
||||||
|
si_GridStates[GRID_STATE_ACTIVE] = new ActiveState;
|
||||||
|
si_GridStates[GRID_STATE_IDLE] = new IdleState;
|
||||||
|
si_GridStates[GRID_STATE_REMOVAL] = new RemovalState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapManager::DeleteStateMachine()
|
||||||
|
{
|
||||||
|
delete si_GridStates[GRID_STATE_INVALID];
|
||||||
|
delete si_GridStates[GRID_STATE_ACTIVE];
|
||||||
|
delete si_GridStates[GRID_STATE_IDLE];
|
||||||
|
delete si_GridStates[GRID_STATE_REMOVAL];
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapManager::UpdateGridState(grid_state_t state, Map& map, NGridType& ngrid, GridInfo& ginfo, const uint32 &x, const uint32 &y, const uint32 &t_diff)
|
||||||
|
{
|
||||||
|
// TODO: The grid state array itself is static and therefore 100% safe, however, the data
|
||||||
|
// the state classes in it accesses is not, since grids are shared across maps (for example
|
||||||
|
// in instances), so some sort of locking will be necessary later.
|
||||||
|
|
||||||
|
si_GridStates[state]->Update(map, ngrid, ginfo, x, y, t_diff);
|
||||||
|
}
|
||||||
|
|
||||||
void MapManager::InitializeVisibilityDistanceInfo()
|
void MapManager::InitializeVisibilityDistanceInfo()
|
||||||
{
|
{
|
||||||
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
|
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
|
||||||
(*iter).second->InitVisibilityDistance();
|
(*iter).second->InitVisibilityDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
// debugging code, should be deleted some day
|
|
||||||
void MapManager::checkAndCorrectGridStatesArray()
|
|
||||||
{
|
|
||||||
bool ok = true;
|
|
||||||
for(int i=0;i<MAX_GRID_STATE; i++)
|
|
||||||
{
|
|
||||||
if(i_GridStates[i] != si_GridStates[i])
|
|
||||||
{
|
|
||||||
sLog.outError("MapManager::checkGridStates(), GridState: si_GridStates is currupt !!!");
|
|
||||||
ok = false;
|
|
||||||
si_GridStates[i] = i_GridStates[i];
|
|
||||||
}
|
|
||||||
#ifdef MANGOS_DEBUG
|
|
||||||
// inner class checking only when compiled with debug
|
|
||||||
if(!si_GridStates[i]->checkMagic())
|
|
||||||
{
|
|
||||||
ok = false;
|
|
||||||
si_GridStates[i]->setMagic();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if(!ok)
|
|
||||||
++i_GridStateErrorCount;
|
|
||||||
if(i_GridStateErrorCount > 2)
|
|
||||||
ASSERT(false); // force a crash. Too many errors
|
|
||||||
}
|
|
||||||
|
|
||||||
Map*
|
Map*
|
||||||
MapManager::_createBaseMap(uint32 id)
|
MapManager::_createBaseMap(uint32 id)
|
||||||
{
|
{
|
||||||
|
|
@ -259,10 +246,7 @@ MapManager::Update(uint32 diff)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
|
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
|
||||||
{
|
|
||||||
checkAndCorrectGridStatesArray(); // debugging code, should be deleted some day
|
|
||||||
iter->second->Update((uint32)i_timer.GetCurrent());
|
iter->second->Update((uint32)i_timer.GetCurrent());
|
||||||
}
|
|
||||||
|
|
||||||
for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
|
for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
|
||||||
(*iter)->Update(i_timer.GetCurrent());
|
(*iter)->Update(i_timer.GetCurrent());
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
|
||||||
Map const* CreateBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_createBaseMap(id); }
|
Map const* CreateBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_createBaseMap(id); }
|
||||||
Map* FindMap(uint32 mapid, uint32 instanceId = 0) const;
|
Map* FindMap(uint32 mapid, uint32 instanceId = 0) const;
|
||||||
|
|
||||||
|
void UpdateGridState(grid_state_t state, Map& map, NGridType& ngrid, GridInfo& ginfo, const uint32 &x, const uint32 &y, const uint32 &t_diff);
|
||||||
|
|
||||||
// only const version for outer users
|
// only const version for outer users
|
||||||
void DeleteInstance(uint32 mapid, uint32 instanceId);
|
void DeleteInstance(uint32 mapid, uint32 instanceId);
|
||||||
|
|
||||||
|
|
@ -130,17 +132,22 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
|
||||||
uint32 GetNumPlayersInInstances();
|
uint32 GetNumPlayersInInstances();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// debugging code, should be deleted some day
|
// debugging code, should be deleted some day
|
||||||
void checkAndCorrectGridStatesArray(); // just for debugging to find some memory overwrites
|
GridState* si_GridStates[MAX_GRID_STATE];
|
||||||
GridState* i_GridStates[MAX_GRID_STATE]; // shadow entries to the global array in Map.cpp
|
|
||||||
int i_GridStateErrorCount;
|
int i_GridStateErrorCount;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
MapManager();
|
MapManager();
|
||||||
~MapManager();
|
~MapManager();
|
||||||
|
|
||||||
MapManager(const MapManager &);
|
MapManager(const MapManager &);
|
||||||
MapManager& operator=(const MapManager &);
|
MapManager& operator=(const MapManager &);
|
||||||
|
|
||||||
|
void InitStateMachine();
|
||||||
|
void DeleteStateMachine();
|
||||||
|
|
||||||
Map* _createBaseMap(uint32 id);
|
Map* _createBaseMap(uint32 id);
|
||||||
Map* _findMap(uint32 id) const
|
Map* _findMap(uint32 id) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "9995"
|
#define REVISION_NR "9996"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue