AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
MapGridManager Class Reference

#include "MapGridManager.h"

Public Member Functions

 MapGridManager (Map *map)
 
void CreateGrid (uint16 const x, uint16 const y)
 
bool LoadGrid (uint16 const x, uint16 const y)
 
void UnloadGrid (uint16 const x, uint16 const y)
 
bool IsGridCreated (uint16 const x, uint16 const y) const
 
bool IsGridLoaded (uint16 const x, uint16 const y) const
 
MapGridTypeGetGrid (uint16 const x, uint16 const y)
 
uint32 GetCreatedGridsCount ()
 
uint32 GetLoadedGridsCount ()
 
uint32 GetCreatedCellsInGridCount (uint16 const x, uint16 const y)
 
uint32 GetCreatedCellsInMapCount ()
 
bool IsGridsFullyCreated () const
 
bool IsGridsFullyLoaded () const
 

Static Public Member Functions

static bool IsValidGridCoordinates (uint16 const x, uint16 const y)
 

Private Attributes

Map_map
 
uint32 _createdGridsCount
 
uint32 _loadedGridsCount
 
std::mutex _gridLock
 
std::unique_ptr< MapGridType_mapGrid [MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
 

Detailed Description

Constructor & Destructor Documentation

◆ MapGridManager()

MapGridManager::MapGridManager ( Map map)
inline
Map * _map
Definition MapGridManager.h:53
uint32 _loadedGridsCount
Definition MapGridManager.h:56
uint32 _createdGridsCount
Definition MapGridManager.h:55

Member Function Documentation

◆ CreateGrid()

void MapGridManager::CreateGrid ( uint16 const  x,
uint16 const  y 
)
6{
7 std::lock_guard<std::mutex> guard(_gridLock);
8 if (IsGridCreated(x, y))
9 return;
10
11 // If we are an instance, ensure parent map has already created the grid before proceeding.
12 // Note: grid loading is locked and is safe across multiple map threads in the
13 // event of multiple child maps attempting to create the same parent map grid
14 if (_map->GetInstanceId() != 0)
15 {
16 Map* parentMap = const_cast<Map*>(_map->GetParent());
17 parentMap->EnsureGridCreated(GridCoord(x, y));
18 }
19
20 std::unique_ptr<MapGridType> grid = std::make_unique<MapGridType>(x, y);
21 grid->link(_map);
22
23 // Terrain is loading during create (should/can we move this to LoadGrid?)
24 GridTerrainLoader loader(*grid, _map);
25 loader.LoadTerrain();
26
27 _mapGrid[x][y] = std::move(grid);
28
30}
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
Definition GridDefines.h:171
Definition GridTerrainLoader.h:26
bool IsGridCreated(uint16 const x, uint16 const y) const
Definition MapGridManager.cpp:72
std::mutex _gridLock
Definition MapGridManager.h:58
std::unique_ptr< MapGridType > _mapGrid[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
Definition MapGridManager.h:59
Definition Map.h:164
void EnsureGridCreated(GridCoord const &gridCoord)
Definition Map.cpp:179
Map const * GetParent() const
Definition Map.h:232
uint32 GetInstanceId() const
Definition Map.h:266

References _createdGridsCount, _gridLock, _map, _mapGrid, Map::EnsureGridCreated(), Map::GetInstanceId(), Map::GetParent(), IsGridCreated(), and GridTerrainLoader::LoadTerrain().

Referenced by Map::EnsureGridCreated().

◆ GetCreatedCellsInGridCount()

uint32 MapGridManager::GetCreatedCellsInGridCount ( uint16 const  x,
uint16 const  y 
)
107{
108 MapGridType* grid = GetGrid(x, y);
109 if (grid)
110 return grid->GetCreatedCellsCount();
111
112 return 0;
113}
MapGridType * GetGrid(uint16 const x, uint16 const y)
Definition MapGridManager.cpp:88
Definition MapGrid.h:32
uint32 GetCreatedCellsCount()
Definition MapGrid.h:104

References MapGrid< GRID_OBJECT_TYPES, FAR_VISIBLE_OBJECT_TYPES >::GetCreatedCellsCount(), and GetGrid().

Referenced by Map::GetCreatedCellsInGridCount().

◆ GetCreatedCellsInMapCount()

uint32 MapGridManager::GetCreatedCellsInMapCount ( )
116{
117 uint32 count = 0;
118 for (uint32 gridX = 0; gridX < MAX_NUMBER_OF_GRIDS; ++gridX)
119 {
120 for (uint32 gridY = 0; gridY < MAX_NUMBER_OF_GRIDS; ++gridY)
121 {
122 if (MapGridType* grid = GetGrid(gridX, gridY))
123 count += grid->GetCreatedCellsCount();
124 }
125 }
126 return count;
127}
std::uint32_t uint32
Definition Define.h:107
#define MAX_NUMBER_OF_GRIDS
Definition MapDefines.h:24

References GetGrid(), and MAX_NUMBER_OF_GRIDS.

Referenced by Map::GetCreatedCellsInMapCount().

◆ GetCreatedGridsCount()

uint32 MapGridManager::GetCreatedGridsCount ( )
97{
98 return _createdGridsCount;
99}

References _createdGridsCount.

Referenced by Map::GetCreatedGridsCount().

◆ GetGrid()

MapGridType * MapGridManager::GetGrid ( uint16 const  x,
uint16 const  y 
)
89{
91 return nullptr;
92
93 return _mapGrid[x][y].get();
94}
static bool IsValidGridCoordinates(uint16 const x, uint16 const y)
Definition MapGridManager.h:42

References _mapGrid, and IsValidGridCoordinates().

Referenced by GetCreatedCellsInGridCount(), GetCreatedCellsInMapCount(), Map::GetGridTerrainData(), Map::GetGridTerrainDataSharedPtr(), Map::GetMapGrid(), LoadGrid(), and UnloadGrid().

◆ GetLoadedGridsCount()

uint32 MapGridManager::GetLoadedGridsCount ( )
102{
103 return _loadedGridsCount;
104}

References _loadedGridsCount.

Referenced by Map::GetLoadedGridsCount().

◆ IsGridCreated()

bool MapGridManager::IsGridCreated ( uint16 const  x,
uint16 const  y 
) const
73{
75 return false;
76
77 return _mapGrid[x][y].get();
78}

References _mapGrid, and IsValidGridCoordinates().

Referenced by CreateGrid(), and Map::IsGridCreated().

◆ IsGridLoaded()

bool MapGridManager::IsGridLoaded ( uint16 const  x,
uint16 const  y 
) const
81{
83 return false;
84
85 return _mapGrid[x][y].get() && _mapGrid[x][y]->IsObjectDataLoaded();
86}

References _mapGrid, and IsValidGridCoordinates().

Referenced by Map::IsGridLoaded().

◆ IsGridsFullyCreated()

bool MapGridManager::IsGridsFullyCreated ( ) const

◆ IsGridsFullyLoaded()

bool MapGridManager::IsGridsFullyLoaded ( ) const

◆ IsValidGridCoordinates()

static bool MapGridManager::IsValidGridCoordinates ( uint16 const  x,
uint16 const  y 
)
inlinestatic

◆ LoadGrid()

bool MapGridManager::LoadGrid ( uint16 const  x,
uint16 const  y 
)
34{
35 MapGridType* grid = GetGrid(x, y);
36 if (!grid || grid->IsObjectDataLoaded())
37 return false;
38
39 // Must mark as loaded first, as GridObjectLoader spawning objects can attempt to recursively load the grid
40 grid->SetObjectDataLoaded();
41
42 GridObjectLoader loader(*grid, _map);
43 loader.LoadAllCellsInGrid();
44
46 return true;
47}
Definition GridObjectLoader.h:27
void SetObjectDataLoaded()
Definition MapGrid.h:46
bool IsObjectDataLoaded() const
Definition MapGrid.h:45

References _loadedGridsCount, _map, GetGrid(), MapGrid< GRID_OBJECT_TYPES, FAR_VISIBLE_OBJECT_TYPES >::IsObjectDataLoaded(), GridObjectLoader::LoadAllCellsInGrid(), and MapGrid< GRID_OBJECT_TYPES, FAR_VISIBLE_OBJECT_TYPES >::SetObjectDataLoaded().

Referenced by Map::EnsureGridLoaded().

◆ UnloadGrid()

void MapGridManager::UnloadGrid ( uint16 const  x,
uint16 const  y 
)
50{
51 MapGridType* grid = GetGrid(x, y);
52 if (!grid)
53 return;
54
55 {
56 GridObjectCleaner worker;
58 grid->VisitAllCells(visitor);
59 }
60
62
63 {
64 GridObjectUnloader worker;
66 grid->VisitAllCells(visitor);
67 }
68
69 _mapGrid[x][y] = nullptr;
70}
Definition GridObjectLoader.h:47
Definition GridObjectLoader.h:55
void VisitAllCells(TypeContainerVisitor< T, TT > &visitor)
Definition MapGrid.h:70
void RemoveAllObjectsInRemoveList()
Definition Map.cpp:1772
Definition TypeContainerVisitor.h:105

References _map, _mapGrid, GetGrid(), Map::RemoveAllObjectsInRemoveList(), and MapGrid< GRID_OBJECT_TYPES, FAR_VISIBLE_OBJECT_TYPES >::VisitAllCells().

Referenced by Map::UnloadGrid().

Member Data Documentation

◆ _createdGridsCount

uint32 MapGridManager::_createdGridsCount
private

◆ _gridLock

std::mutex MapGridManager::_gridLock
private

Referenced by CreateGrid().

◆ _loadedGridsCount

uint32 MapGridManager::_loadedGridsCount
private

◆ _map

Map* MapGridManager::_map
private

Referenced by CreateGrid(), LoadGrid(), and UnloadGrid().

◆ _mapGrid

std::unique_ptr<MapGridType> MapGridManager::_mapGrid[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS]
private

The documentation for this class was generated from the following files: