aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-10-17 00:37:59 +0200
committerShauren <shauren.trinity@gmail.com>2025-10-17 00:37:59 +0200
commit979c722b81be4f21b8a1299c637cafd77a176f70 (patch)
treecbc1b34e47e4d14935ce2c918e7146c242d2e412 /src
parenta0c8e0255c41b3f91a712acc5327234bad7bb2ed (diff)
Core/Maps: Tiny optimization for TerrainInfo::CleanUpGrids
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Maps/Map.cpp13
-rw-r--r--src/server/game/Maps/TerrainMgr.cpp17
-rw-r--r--src/server/game/Maps/TerrainMgr.h5
3 files changed, 13 insertions, 22 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index b95bd2b9359..e9e4748b440 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -138,20 +138,9 @@ i_mapEntry(sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode), i_InstanceId(Inst
m_unloadTimer(0), m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE), m_mapRefIter(m_mapRefManager.end()),
m_VisibilityNotifyPeriod(DEFAULT_VISIBILITY_NOTIFY_PERIOD),
m_activeNonPlayersIter(m_activeNonPlayers.end()), _transportsUpdateIter(_transports.end()),
-i_gridExpiry(expiry), m_terrain(sTerrainMgr.LoadTerrain(id)), m_forceEnabledNavMeshFilterFlags(0), m_forceDisabledNavMeshFilterFlags(0),
+i_gridExpiry(expiry), m_terrain(sTerrainMgr.LoadTerrain(id)), m_forceEnabledNavMeshFilterFlags(0), m_forceDisabledNavMeshFilterFlags(0), i_grids(),
i_scriptLock(false), _respawnTimes(std::make_unique<RespawnListContainer>()), _respawnCheckTimer(0), _vignetteUpdateTimer(5200, 5200)
{
- for (uint32 x = 0; x < MAX_NUMBER_OF_GRIDS; ++x)
- {
- for (uint32 y = 0; y < MAX_NUMBER_OF_GRIDS; ++y)
- {
- //z code
- setNGrid(nullptr, x, y);
- }
- }
-
- _zonePlayerCountMap.clear();
-
//lets initialize visibility distance for map
Map::InitVisibilityDistance();
diff --git a/src/server/game/Maps/TerrainMgr.cpp b/src/server/game/Maps/TerrainMgr.cpp
index 65655e6e84b..7dc70479a96 100644
--- a/src/server/game/Maps/TerrainMgr.cpp
+++ b/src/server/game/Maps/TerrainMgr.cpp
@@ -32,7 +32,7 @@
#include "World.h"
#include <G3D/g3dmath.h>
-TerrainInfo::TerrainInfo(uint32 mapId) : _mapId(mapId), _parentTerrain(nullptr), _cleanupTimer(randtime(CleanupInterval / 2, CleanupInterval))
+TerrainInfo::TerrainInfo(uint32 mapId) : _mapId(mapId), _parentTerrain(nullptr), _loadedGrids(), _cleanupTimer(randtime(CleanupInterval / 2, CleanupInterval))
{
}
@@ -180,7 +180,7 @@ void TerrainInfo::LoadMapAndVMapImpl(int32 gx, int32 gy)
for (std::shared_ptr<TerrainInfo> const& childTerrain : _childTerrain)
childTerrain->LoadMapAndVMapImpl(gx, gy);
- _loadedGrids[GetBitsetIndex(gx, gy)] = true;
+ _loadedGrids[gx] |= UI64LIT(1) << gy;
}
void TerrainInfo::LoadMMapInstanceImpl(uint32 mapId, uint32 instanceId)
@@ -279,7 +279,7 @@ void TerrainInfo::UnloadMapImpl(int32 gx, int32 gy)
for (std::shared_ptr<TerrainInfo> const& childTerrain : _childTerrain)
childTerrain->UnloadMapImpl(gx, gy);
- _loadedGrids[GetBitsetIndex(gx, gy)] = false;
+ _loadedGrids[gx] &= ~(UI64LIT(1) << gy);
}
void TerrainInfo::UnloadMMapInstanceImpl(uint32 mapId, uint32 instanceId)
@@ -294,7 +294,7 @@ GridMap* TerrainInfo::GetGrid(uint32 mapId, float x, float y, bool loadIfMissing
int32 gy = (int)(CENTER_GRID_ID - y / SIZE_OF_GRIDS); //grid y
// ensure GridMap is loaded
- if (!_loadedGrids[GetBitsetIndex(gx, gy)] && loadIfMissing)
+ if (!(_loadedGrids[gx] & (UI64LIT(1) << gy)) && loadIfMissing)
{
std::lock_guard<std::mutex> lock(_loadMutex);
LoadMapAndVMapImpl(gx, gy);
@@ -303,7 +303,7 @@ GridMap* TerrainInfo::GetGrid(uint32 mapId, float x, float y, bool loadIfMissing
GridMap* grid = _gridMap[gx][gy].get();
if (mapId != GetId())
{
- auto childMapItr = std::find_if(_childTerrain.begin(), _childTerrain.end(), [mapId](std::shared_ptr<TerrainInfo> const& childTerrain) { return childTerrain->GetId() == mapId; });
+ auto childMapItr = std::ranges::find(_childTerrain, mapId, [](std::shared_ptr<TerrainInfo> const& childTerrain) { return childTerrain->GetId(); });
if (childMapItr != _childTerrain.end() && (*childMapItr)->_gridMap[gx][gy])
grid = (*childMapItr)->GetGrid(mapId, x, y, false);
}
@@ -319,9 +319,10 @@ void TerrainInfo::CleanUpGrids(uint32 diff)
// delete those GridMap objects which have refcount = 0
for (int32 x = 0; x < MAX_NUMBER_OF_GRIDS; ++x)
- for (int32 y = 0; y < MAX_NUMBER_OF_GRIDS; ++y)
- if (_loadedGrids[GetBitsetIndex(x, y)] && !_referenceCountFromMap[x][y])
- UnloadMapImpl(x, y);
+ if (_loadedGrids[x])
+ for (int32 y = 0; y < MAX_NUMBER_OF_GRIDS; ++y)
+ if ((_loadedGrids[x] & (UI64LIT(1) << y)) && !_referenceCountFromMap[x][y])
+ UnloadMapImpl(x, y);
_cleanupTimer.Reset(CleanupInterval);
}
diff --git a/src/server/game/Maps/TerrainMgr.h b/src/server/game/Maps/TerrainMgr.h
index 6d3879043b5..ccd06b67e42 100644
--- a/src/server/game/Maps/TerrainMgr.h
+++ b/src/server/game/Maps/TerrainMgr.h
@@ -23,6 +23,7 @@
#include "MapDefines.h"
#include "Position.h"
#include "Timer.h"
+#include <array>
#include <atomic>
#include <bitset>
#include <memory>
@@ -111,8 +112,8 @@ private:
std::mutex _loadMutex;
std::unique_ptr<GridMap> _gridMap[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
std::atomic<uint16> _referenceCountFromMap[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
- std::bitset<MAX_NUMBER_OF_GRIDS* MAX_NUMBER_OF_GRIDS> _loadedGrids;
- std::bitset<MAX_NUMBER_OF_GRIDS* MAX_NUMBER_OF_GRIDS> _gridFileExists; // cache what grids are available for this map (not including parent/child maps)
+ std::array<uint64, (MAX_NUMBER_OF_GRIDS * MAX_NUMBER_OF_GRIDS + 63) / 64> _loadedGrids;
+ std::bitset<MAX_NUMBER_OF_GRIDS * MAX_NUMBER_OF_GRIDS> _gridFileExists; // cache what grids are available for this map (not including parent/child maps)
static constexpr Milliseconds CleanupInterval = 1min;