diff options
author | Shauren <shauren.trinity@gmail.com> | 2018-05-06 00:39:13 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2018-05-06 00:39:13 +0200 |
commit | b773d9997bdd723cad8c646170e025a48f140f1d (patch) | |
tree | c7d3114226103a2489627f36ea3aed0060a94c4f | |
parent | 136269a5851a6755f644295a0171e4bc6c2bef17 (diff) |
Core/Maps: Fixed loading vmaps and mmaps in instances
-rw-r--r-- | src/server/game/Grids/NGrid.cpp | 4 | ||||
-rw-r--r-- | src/server/game/Grids/NGrid.h | 5 | ||||
-rw-r--r-- | src/server/game/Maps/Map.cpp | 86 | ||||
-rw-r--r-- | src/server/game/Maps/Map.h | 7 | ||||
-rw-r--r-- | src/server/game/Maps/MapInstanced.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Maps/MapInstanced.h | 15 |
6 files changed, 40 insertions, 79 deletions
diff --git a/src/server/game/Grids/NGrid.cpp b/src/server/game/Grids/NGrid.cpp index 857e5e4bdc1..67462f9f6dd 100644 --- a/src/server/game/Grids/NGrid.cpp +++ b/src/server/game/Grids/NGrid.cpp @@ -19,11 +19,11 @@ #include "Random.h" GridInfo::GridInfo() : i_timer(0), vis_Update(0, irand(0, DEFAULT_VISIBILITY_NOTIFY_PERIOD)), - i_unloadActiveLockCount(0), i_unloadExplicitLock(false), i_unloadReferenceLock(false) + i_unloadActiveLockCount(0), i_unloadExplicitLock(false) { } GridInfo::GridInfo(time_t expiry, bool unload /*= true */) : i_timer(expiry), vis_Update(0, irand(0, DEFAULT_VISIBILITY_NOTIFY_PERIOD)), - i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload), i_unloadReferenceLock(false) + i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload) { } diff --git a/src/server/game/Grids/NGrid.h b/src/server/game/Grids/NGrid.h index d4959aa63f8..c38b19d2038 100644 --- a/src/server/game/Grids/NGrid.h +++ b/src/server/game/Grids/NGrid.h @@ -35,9 +35,8 @@ public: GridInfo(); GridInfo(time_t expiry, bool unload = true ); const TimeTracker& getTimeTracker() const { return i_timer; } - bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock || i_unloadReferenceLock; } + bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock; } void setUnloadExplicitLock(bool on) { i_unloadExplicitLock = on; } - void setUnloadReferenceLock(bool on) { i_unloadReferenceLock = on; } void incUnloadActiveLock() { ++i_unloadActiveLockCount; } void decUnloadActiveLock() { if (i_unloadActiveLockCount) --i_unloadActiveLockCount; } @@ -51,7 +50,6 @@ private: uint16 i_unloadActiveLockCount : 16; // lock from active object spawn points (prevent clone loading) bool i_unloadExplicitLock : 1; // explicit manual lock or config setting - bool i_unloadReferenceLock : 1; // lock from instance map copy }; typedef enum @@ -109,7 +107,6 @@ class NGrid const TimeTracker& getTimeTracker() const { return i_GridInfo.getTimeTracker(); } bool getUnloadLock() const { return i_GridInfo.getUnloadLock(); } void setUnloadExplicitLock(bool on) { i_GridInfo.setUnloadExplicitLock(on); } - void setUnloadReferenceLock(bool on) { i_GridInfo.setUnloadReferenceLock(on); } void incUnloadActiveLock() { i_GridInfo.incUnloadActiveLock(); } void decUnloadActiveLock() { i_GridInfo.decUnloadActiveLock(); } void ResetTimeTracker(time_t interval) { i_GridInfo.ResetTimeTracker(interval); } diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 9588a69f932..2b8b453a44d 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -172,41 +172,30 @@ void Map::LoadVMap(int gx, int gy) } } -void Map::LoadMap(int gx, int gy, bool reload) +void Map::LoadMap(int gx, int gy) { - LoadMapImpl(this, gx, gy, reload); + LoadMapImpl(this, gx, gy); for (Map* childBaseMap : *m_childTerrainMaps) - childBaseMap->LoadMap(gx, gy, reload); + childBaseMap->LoadMap(gx, gy); } -void Map::LoadMapImpl(Map* map, int gx, int gy, bool reload) +void Map::LoadMapImpl(Map* map, int gx, int gy) { - if (map->i_InstanceId != 0) - { - if (map->GridMaps[gx][gy]) - return; - - // load grid map for base map - GridCoord ngridCoord = GridCoord((MAX_NUMBER_OF_GRIDS - 1) - gx, (MAX_NUMBER_OF_GRIDS - 1) - gy); - if (!map->m_parentMap->getNGrid(ngridCoord.x_coord, ngridCoord.y_coord)) - map->m_parentMap->EnsureGridCreated(ngridCoord); - - static_cast<MapInstanced*>(map->m_parentMap)->AddGridMapReference(GridCoord(gx, gy)); - map->GridMaps[gx][gy] = map->m_parentMap->GridMaps[gx][gy]; + if (map->GridMaps[gx][gy]) return; - } - if (map->GridMaps[gx][gy] && !reload) - return; + Map* parent = map->m_parentMap; + ++parent->GridMapReference[gx][gy]; - //map already load, delete it before reloading (Is it necessary? Do we really need the ability the reload maps during runtime?) - if (map->GridMaps[gx][gy]) + // load grid map for base map + if (parent != map) { - TC_LOG_DEBUG("maps", "Unloading previously loaded map %u before reloading.", map->GetId()); - sScriptMgr->OnUnloadGridMap(map, map->GridMaps[gx][gy], gx, gy); + GridCoord ngridCoord = GridCoord((MAX_NUMBER_OF_GRIDS - 1) - gx, (MAX_NUMBER_OF_GRIDS - 1) - gy); + if (!parent->GridMaps[gx][gy]) + parent->EnsureGridCreated(ngridCoord); - delete map->GridMaps[gx][gy]; - map->GridMaps[gx][gy] = nullptr; + map->GridMaps[gx][gy] = parent->GridMaps[gx][gy]; + return; } // map file name @@ -230,29 +219,25 @@ void Map::UnloadMap(int gx, int gy) void Map::UnloadMapImpl(Map* map, int gx, int gy) { - if (map->i_InstanceId == 0) + if (map->GridMaps[gx][gy]) { - if (map->GridMaps[gx][gy]) + Map* parent = map->m_parentMap; + if (!--parent->GridMapReference[gx][gy]) { - map->GridMaps[gx][gy]->unloadData(); - delete map->GridMaps[gx][gy]; + parent->GridMaps[gx][gy]->unloadData(); + delete parent->GridMaps[gx][gy]; + parent->GridMaps[gx][gy] = nullptr; } } - else - static_cast<MapInstanced*>(map->m_parentMap)->RemoveGridMapReference(GridCoord(gx, gy)); map->GridMaps[gx][gy] = nullptr; } void Map::LoadMapAndVMap(int gx, int gy) { - m_parentTerrainMap->LoadMap(gx, gy); - // Only load the data for the base map - if (i_InstanceId == 0) - { - LoadVMap(gx, gy); - LoadMMap(gx, gy); - } + LoadMap(gx, gy); + LoadVMap(gx, gy); + LoadMMap(gx, gy); } void Map::LoadAllCells() @@ -306,6 +291,7 @@ i_scriptLock(false), _defaultLight(DB2Manager::GetDefaultMapLight(id)) { //z code GridMaps[x][y] = nullptr; + GridMapReference[x][y] = 0; setNGrid(nullptr, x, y); } } @@ -525,20 +511,20 @@ void Map::EnsureGridCreated_i(const GridCoord &p) { TC_LOG_DEBUG("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); + NGridType* ngrid = 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)); + setNGrid(ngrid, p.x_coord, p.y_coord); // build a linkage between this map and NGridType - buildNGridLinkage(getNGrid(p.x_coord, p.y_coord)); + buildNGridLinkage(ngrid); - getNGrid(p.x_coord, p.y_coord)->SetGridState(GRID_STATE_IDLE); + ngrid->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; if (!GridMaps[gx][gy]) - LoadMapAndVMap(gx, gy); + m_parentTerrainMap->LoadMapAndVMap(gx, gy); } } @@ -1829,17 +1815,13 @@ bool Map::UnloadGrid(NGridType& ngrid, bool unloadAll) int gy = (MAX_NUMBER_OF_GRIDS - 1) - y; // delete grid map, but don't delete if it is from parent map (and thus only reference) - //+++if (GridMaps[gx][gy]) don't check for GridMaps[gx][gy], we might have to unload vmaps + if (GridMaps[gx][gy]) { - if (m_parentTerrainMap == this) - m_parentTerrainMap->UnloadMap(gx, gy); - - if (i_InstanceId == 0) - { - VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(GetId(), gx, gy); - MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(GetId(), gx, gy); - } + m_parentTerrainMap->UnloadMap(gx, gy); + VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(m_parentTerrainMap->GetId(), gx, gy); + MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(m_parentTerrainMap->GetId(), gx, gy); } + TC_LOG_DEBUG("maps", "Unloading grid[%u, %u] for map %u finished", x, y, GetId()); return true; } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 5f7c391a794..8140d60c4a7 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -332,7 +332,6 @@ class TC_GAME_API Map : public GridRefManager<NGridType> static void InitStateMachine(); static void DeleteStateMachine(); - Map const* GetParent() const { return m_parentMap; } void AddChildTerrainMap(Map* map) { m_childTerrainMaps->push_back(map); map->m_parentTerrainMap = this; } void UnlinkAllChildTerrainMaps() { m_childTerrainMaps->clear(); } @@ -575,8 +574,8 @@ class TC_GAME_API Map : public GridRefManager<NGridType> private: void LoadMapAndVMap(int gx, int gy); void LoadVMap(int gx, int gy); - void LoadMap(int gx, int gy, bool reload = false); - static void LoadMapImpl(Map* map, int gx, int gy, bool reload); + void LoadMap(int gx, int gy); + static void LoadMapImpl(Map* map, int gx, int gy); void UnloadMap(int gx, int gy); static void UnloadMapImpl(Map* map, int gx, int gy); void LoadMMap(int gx, int gy); @@ -637,7 +636,6 @@ class TC_GAME_API Map : public GridRefManager<NGridType> void SendObjectUpdates(); protected: - void SetUnloadReferenceLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); } virtual void LoadGridObjects(NGridType* grid, Cell const& cell); std::mutex _mapLock; @@ -684,6 +682,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType> NGridType* i_grids[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]; GridMap* GridMaps[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]; + uint16 GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]; std::bitset<TOTAL_NUMBER_OF_CELLS_PER_MAP*TOTAL_NUMBER_OF_CELLS_PER_MAP> marked_cells; //these functions used to process player/mob aggro reactions and diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp index aafd0f75b19..f4ba5ca9612 100644 --- a/src/server/game/Maps/MapInstanced.cpp +++ b/src/server/game/Maps/MapInstanced.cpp @@ -33,8 +33,6 @@ MapInstanced::MapInstanced(uint32 id, time_t expiry) : Map(id, expiry, 0, DIFFICULTY_NORMAL) { - // fill with zero - memset(&GridMapReference, 0, MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_GRIDS*sizeof(uint16)); } void MapInstanced::InitVisibilityDistance() diff --git a/src/server/game/Maps/MapInstanced.h b/src/server/game/Maps/MapInstanced.h index 6ff2751343a..8b150b8e53a 100644 --- a/src/server/game/Maps/MapInstanced.h +++ b/src/server/game/Maps/MapInstanced.h @@ -49,19 +49,6 @@ class TC_GAME_API MapInstanced : public Map } bool DestroyInstance(InstancedMaps::iterator &itr); - void AddGridMapReference(const GridCoord &p) - { - ++GridMapReference[p.x_coord][p.y_coord]; - SetUnloadReferenceLock(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - p.x_coord, (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord), true); - } - - void RemoveGridMapReference(GridCoord const& p) - { - --GridMapReference[p.x_coord][p.y_coord]; - if (!GridMapReference[p.x_coord][p.y_coord]) - SetUnloadReferenceLock(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - p.x_coord, (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord), false); - } - InstancedMaps &GetInstancedMaps() { return m_InstancedMaps; } virtual void InitVisibilityDistance() override; @@ -71,7 +58,5 @@ class TC_GAME_API MapInstanced : public Map GarrisonMap* CreateGarrison(uint32 instanceId, Player* owner); InstancedMaps m_InstancedMaps; - - uint16 GridMapReference[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]; }; #endif |