Core/Grids: Replace some magic numbers with constants

(P.S.: That's why! @cs_misc.cpp)
This commit is contained in:
Shocker
2014-09-19 18:03:49 +03:00
parent c678eaa71e
commit 80f77977f1
4 changed files with 24 additions and 25 deletions

View File

@@ -159,7 +159,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(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - gx, (MAX_NUMBER_OF_GRIDS - 1) - gy));
((MapInstanced*)(m_parentMap))->AddGridMapReference(GridCoord(gx, gy));
GridMaps[gx][gy] = m_parentMap->GridMaps[gx][gy];
@@ -1755,8 +1755,8 @@ uint16 GridMap::getArea(float x, float y) const
if (!_areaMap)
return _gridArea;
x = 16 * (32 - x/SIZE_OF_GRIDS);
y = 16 * (32 - y/SIZE_OF_GRIDS);
x = 16 * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
y = 16 * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
int lx = (int)x & 15;
int ly = (int)y & 15;
return _areaMap[lx*16 + ly];
@@ -1772,8 +1772,8 @@ float GridMap::getHeightFromFloat(float x, float y) const
if (!m_V8 || !m_V9)
return _gridHeight;
x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
x = MAP_RESOLUTION * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
y = MAP_RESOLUTION * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
int x_int = (int)x;
int y_int = (int)y;
@@ -1854,8 +1854,8 @@ float GridMap::getHeightFromUint8(float x, float y) const
if (!m_uint8_V8 || !m_uint8_V9)
return _gridHeight;
x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
x = MAP_RESOLUTION * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
y = MAP_RESOLUTION * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
int x_int = (int)x;
int y_int = (int)y;
@@ -1921,8 +1921,8 @@ float GridMap::getHeightFromUint16(float x, float y) const
if (!m_uint16_V8 || !m_uint16_V9)
return _gridHeight;
x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
x = MAP_RESOLUTION * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
y = MAP_RESOLUTION * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
int x_int = (int)x;
int y_int = (int)y;
@@ -1988,8 +1988,8 @@ float GridMap::getLiquidLevel(float x, float y) const
if (!_liquidMap)
return _liquidLevel;
x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
x = MAP_RESOLUTION * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
y = MAP_RESOLUTION * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
int cx_int = ((int)x & (MAP_RESOLUTION-1)) - _liquidOffY;
int cy_int = ((int)y & (MAP_RESOLUTION-1)) - _liquidOffX;
@@ -2008,8 +2008,8 @@ uint8 GridMap::getTerrainType(float x, float y) const
if (!_liquidFlags)
return 0;
x = 16 * (32 - x/SIZE_OF_GRIDS);
y = 16 * (32 - y/SIZE_OF_GRIDS);
x = 16 * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
y = 16 * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
int lx = (int)x & 15;
int ly = (int)y & 15;
return _liquidFlags[lx*16 + ly];
@@ -2023,8 +2023,8 @@ inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 R
return LIQUID_MAP_NO_WATER;
// Get cell
float cx = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
float cy = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
float cx = MAP_RESOLUTION * (CENTER_GRID_ID - x/SIZE_OF_GRIDS);
float cy = MAP_RESOLUTION * (CENTER_GRID_ID - y/SIZE_OF_GRIDS);
int x_int = (int)cx & (MAP_RESOLUTION-1);
int y_int = (int)cy & (MAP_RESOLUTION-1);
@@ -2114,11 +2114,11 @@ inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 R
inline GridMap* Map::GetGrid(float x, float y)
{
// half opt method
int gx=(int)(32-x/SIZE_OF_GRIDS); //grid x
int gy=(int)(32-y/SIZE_OF_GRIDS); //grid y
int gx=(int)(CENTER_GRID_ID - x/SIZE_OF_GRIDS); //grid x
int gy=(int)(CENTER_GRID_ID - y/SIZE_OF_GRIDS); //grid y
// ensure GridMap is loaded
EnsureGridCreated(GridCoord(63-gx, 63-gy));
EnsureGridCreated(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - gx, (MAX_NUMBER_OF_GRIDS - 1) - gy));
return GridMaps[gx][gy];
}

View File

@@ -50,14 +50,14 @@ class MapInstanced : public Map
void AddGridMapReference(const GridCoord &p)
{
++GridMapReference[p.x_coord][p.y_coord];
SetUnloadReferenceLock(GridCoord(63-p.x_coord, 63-p.y_coord), true);
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(63-p.x_coord, 63-p.y_coord), false);
SetUnloadReferenceLock(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - p.x_coord, (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord), false);
}
InstancedMaps &GetInstancedMaps() { return m_InstancedMaps; }

View File

@@ -261,8 +261,8 @@ bool MapManager::ExistMapAndVMap(uint32 mapid, float x, float y)
{
GridCoord p = Trinity::ComputeGridCoord(x, y);
int gx=63-p.x_coord;
int gy=63-p.y_coord;
int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord;
int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord;
return Map::ExistMap(mapid, gx, gy) && Map::ExistVMap(mapid, gx, gy);
}

View File

@@ -181,9 +181,8 @@ public:
GridCoord gridCoord = Trinity::ComputeGridCoord(object->GetPositionX(), object->GetPositionY());
// 63? WHY?
int gridX = 63 - gridCoord.x_coord;
int gridY = 63 - gridCoord.y_coord;
int gridX = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord;
int gridY = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord;
uint32 haveMap = Map::ExistMap(mapId, gridX, gridY) ? 1 : 0;
uint32 haveVMap = Map::ExistVMap(mapId, gridX, gridY) ? 1 : 0;