Skip to content

Commit

Permalink
[9996] Remove grid state debugging code and move state machine to Map…
Browse files Browse the repository at this point in the history
…Manager.
  • Loading branch information
XTZGZoReX committed May 28, 2010
1 parent c0f1724 commit 08f02cd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 84 deletions.
17 changes: 2 additions & 15 deletions src/game/GridStates.h
Expand Up @@ -24,21 +24,7 @@
class MANGOS_DLL_DECL GridState
{
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;
};

Expand Down Expand Up @@ -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;
};

#endif
20 changes: 1 addition & 19 deletions src/game/Map.cpp
Expand Up @@ -40,8 +40,6 @@
#include "VMapFactory.h"
#include "BattleGroundMgr.h"

GridState* si_GridStates[MAX_GRID_STATE];

struct ScriptAction
{
uint64 sourceGUID;
Expand Down Expand Up @@ -126,22 +124,6 @@ void Map::LoadMapAndVMap(int gx,int gy)
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)
: i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode),
i_id(id), i_InstanceId(InstanceId), m_unloadTimer(0),
Expand Down Expand Up @@ -648,7 +630,7 @@ void Map::Update(const uint32 &t_diff)
GridInfo *info = i->getSource()->getGridInfoRef();
++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);
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);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/game/Map.h
Expand Up @@ -144,9 +144,6 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
time_t GetGridExpiry(void) const { return i_gridExpiry; }
uint32 GetId(void) const { return i_id; }

static void InitStateMachine();
static void DeleteStateMachine();

Map const * GetParent() const { return m_parentMap; }

// some calls like isInWater should not use vmaps due to processor power
Expand Down
72 changes: 28 additions & 44 deletions src/game/MapManager.cpp
Expand Up @@ -34,9 +34,8 @@
INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK);
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));
}
Expand All @@ -49,57 +48,45 @@ MapManager::~MapManager()
for(TransportSet::iterator i = m_Transports.begin(); i != m_Transports.end(); ++i)
delete *i;

Map::DeleteStateMachine();
DeleteStateMachine();
}

void
MapManager::Initialize()
{
Map::InitStateMachine();
InitStateMachine();
InitMaxInstanceId();
}

// 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;
}
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;
}

InitMaxInstanceId();
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::InitializeVisibilityDistanceInfo()
void MapManager::UpdateGridState(grid_state_t state, Map& map, NGridType& ngrid, GridInfo& ginfo, const uint32 &x, const uint32 &y, const uint32 &t_diff)
{
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
(*iter).second->InitVisibilityDistance();
// 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);
}

// debugging code, should be deleted some day
void MapManager::checkAndCorrectGridStatesArray()
void MapManager::InitializeVisibilityDistanceInfo()
{
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
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
(*iter).second->InitVisibilityDistance();
}

Map*
Expand Down Expand Up @@ -259,10 +246,7 @@ MapManager::Update(uint32 diff)
return;

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());
}

for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
(*iter)->Update(i_timer.GetCurrent());
Expand Down
11 changes: 9 additions & 2 deletions src/game/MapManager.h
Expand Up @@ -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* 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
void DeleteInstance(uint32 mapid, uint32 instanceId);

Expand Down Expand Up @@ -130,17 +132,22 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
uint32 GetNumPlayersInInstances();

private:

// debugging code, should be deleted some day
void checkAndCorrectGridStatesArray(); // just for debugging to find some memory overwrites
GridState* i_GridStates[MAX_GRID_STATE]; // shadow entries to the global array in Map.cpp
GridState* si_GridStates[MAX_GRID_STATE];
int i_GridStateErrorCount;

private:

MapManager();
~MapManager();

MapManager(const MapManager &);
MapManager& operator=(const MapManager &);

void InitStateMachine();
void DeleteStateMachine();

Map* _createBaseMap(uint32 id);
Map* _findMap(uint32 id) const
{
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9995"
#define REVISION_NR "9996"
#endif // __REVISION_NR_H__

0 comments on commit 08f02cd

Please sign in to comment.