diff options
author | ille <ille@ille> | 2012-11-03 15:48:27 +0100 |
---|---|---|
committer | ille <ille@ille> | 2012-11-03 15:48:27 +0100 |
commit | 9ee32331d7083a19ebfd17b32ec6779426140618 (patch) | |
tree | c5b26de90884726d138cba4234e9ae8a623eeb4f | |
parent | e587d8c1afdf28e62bb51accdc57d3f1c405fa4a (diff) |
use Thread-Safe Interface design pattern to allow recursive calls on non windows os
described here http://wiki.hsr.ch/PnProg/files/ThreadSafeInterface.pdf
http://www.aoc.nrao.edu/php/tjuerges/ALMA/ACE-5.5.2/html/ace/classACE__Thread__Mutex.html#_details
recursion in :
EnsureGridCreated() -> LoadMapAndVMap() -> LoadMap() -> EnsureGridCreated()
-rwxr-xr-x | src/server/game/Maps/Map.cpp | 36 | ||||
-rwxr-xr-x | src/server/game/Maps/Map.h | 1 |
2 files changed, 20 insertions, 17 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 5ef0769e5c2..934aa1dc4bc 100755 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -144,7 +144,7 @@ void Map::LoadMap(int gx, int gy, bool reload) // load grid map for base map if (!m_parentMap->GridMaps[gx][gy]) - m_parentMap->EnsureGridCreated(GridCoord(63-gx, 63-gy)); + m_parentMap->EnsureGridCreated_i(GridCoord(63-gx, 63-gy)); ((MapInstanced*)(m_parentMap))->AddGridMapReference(GridCoord(gx, gy)); GridMaps[gx][gy] = m_parentMap->GridMaps[gx][gy]; @@ -307,32 +307,34 @@ void Map::DeleteFromWorld(Player* player) delete player; } +void Map::EnsureGridCreated(const GridCoord &p) +{ + TRINITY_GUARD(ACE_Thread_Mutex, Lock); + EnsureGridCreated_i(p); +} + //Create NGrid so the object can be added to it //But object data is not loaded here -void Map::EnsureGridCreated(const GridCoord &p) +void Map::EnsureGridCreated_i(const GridCoord &p) { if (!getNGrid(p.x_coord, p.y_coord)) { - TRINITY_GUARD(ACE_Thread_Mutex, Lock); - if (!getNGrid(p.x_coord, p.y_coord)) - { - sLog->outDebug(LOG_FILTER_MAPS, "Creating grid[%u, %u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId); + sLog->outDebug(LOG_FILTER_MAPS, "Creating grid[%u, %u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId); - setNGrid(new NGridType(p.x_coord*MAX_NUMBER_OF_GRIDS + p.y_coord, p.x_coord, p.y_coord, i_gridExpiry, sWorld->getBoolConfig(CONFIG_GRID_UNLOAD)), - p.x_coord, p.y_coord); + setNGrid(new NGridType(p.x_coord*MAX_NUMBER_OF_GRIDS + p.y_coord, p.x_coord, p.y_coord, i_gridExpiry, sWorld->getBoolConfig(CONFIG_GRID_UNLOAD)), + p.x_coord, p.y_coord); - // build a linkage between this map and NGridType - buildNGridLinkage(getNGrid(p.x_coord, p.y_coord)); + // build a linkage between this map and NGridType + buildNGridLinkage(getNGrid(p.x_coord, p.y_coord)); - getNGrid(p.x_coord, p.y_coord)->SetGridState(GRID_STATE_IDLE); + getNGrid(p.x_coord, p.y_coord)->SetGridState(GRID_STATE_IDLE); - //z coord - int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord; - int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord; + //z coord + int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord; + int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord; - if (!GridMaps[gx][gy]) - LoadMapAndVMap(gx, gy); - } + if (!GridMaps[gx][gy]) + LoadMapAndVMap(gx, gy); } } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 0743c4e545f..4e4b638faa4 100755 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -499,6 +499,7 @@ class Map : public GridRefManager<NGridType> bool IsGridLoaded(const GridCoord &) const; void EnsureGridCreated(const GridCoord &); + void EnsureGridCreated_i(const GridCoord &); bool EnsureGridLoaded(Cell const&); void EnsureGridLoadedForActiveObject(Cell const&, WorldObject* object); |