aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2018-03-31 17:09:47 +0200
committerShauren <shauren.trinity@gmail.com>2018-03-31 17:09:47 +0200
commitf31d907112daf52c4f8ec53030bc7f28990d3d68 (patch)
tree7ed4c042b68ad3684bc90ae6f31a912264f5631c
parent2e648f9eb9a4f2079dce99e3f0c64f37d57a04a3 (diff)
Core/Maps: Fixed map min height calculation
-rw-r--r--src/server/game/Maps/Map.cpp108
-rw-r--r--src/server/game/Maps/Map.h4
2 files changed, 56 insertions, 56 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 6268b542931..fb36f4c1e4d 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -1912,8 +1912,7 @@ GridMap::GridMap()
_gridIntHeightMultiplier = 0;
m_V9 = nullptr;
m_V8 = nullptr;
- _maxHeight = nullptr;
- _minHeight = nullptr;
+ _minHeightPlanes = nullptr;
// Liquid data
_liquidType = 0;
_liquidOffX = 0;
@@ -1988,16 +1987,14 @@ void GridMap::unloadData()
delete[] _areaMap;
delete[] m_V9;
delete[] m_V8;
- delete[] _maxHeight;
- delete[] _minHeight;
+ delete[] _minHeightPlanes;
delete[] _liquidEntry;
delete[] _liquidFlags;
delete[] _liquidMap;
_areaMap = nullptr;
m_V9 = nullptr;
m_V8 = nullptr;
- _maxHeight = nullptr;
- _minHeight = nullptr;
+ _minHeightPlanes = nullptr;
_liquidEntry = nullptr;
_liquidFlags = nullptr;
_liquidMap = nullptr;
@@ -2069,11 +2066,44 @@ bool GridMap::loadHeightData(FILE* in, uint32 offset, uint32 /*size*/)
if (header.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
{
- _maxHeight = new int16[3 * 3];
- _minHeight = new int16[3 * 3];
- if (fread(_maxHeight, sizeof(int16), 3 * 3, in) != 3 * 3 ||
- fread(_minHeight, sizeof(int16), 3 * 3, in) != 3 * 3)
+ std::array<int16, 9> maxHeights;
+ std::array<int16, 9> minHeights;
+ if (fread(maxHeights.data(), sizeof(int16), maxHeights.size(), in) != maxHeights.size() ||
+ fread(minHeights.data(), sizeof(int16), minHeights.size(), in) != minHeights.size())
return false;
+
+ static uint32 constexpr indices[8][3] =
+ {
+ { 3, 0, 4 },
+ { 0, 1, 4 },
+ { 1, 2, 4 },
+ { 2, 5, 4 },
+ { 5, 8, 4 },
+ { 8, 7, 4 },
+ { 7, 6, 4 },
+ { 6, 3, 4 }
+ };
+
+ static float constexpr boundGridCoords[9][2] =
+ {
+ { 0.0f, 0.0f },
+ { 0.0f, -266.66666f },
+ { 0.0f, -533.33331f },
+ { -266.66666f, 0.0f },
+ { -266.66666f, -266.66666f },
+ { -266.66666f, -533.33331f },
+ { -533.33331f, 0.0f },
+ { -533.33331f, -266.66666f },
+ { -533.33331f, -533.33331f }
+ };
+
+ _minHeightPlanes = new G3D::Plane[8];
+ for (uint32 quarterIndex = 0; quarterIndex < 8; ++quarterIndex)
+ _minHeightPlanes[quarterIndex] = G3D::Plane(
+ G3D::Vector3(boundGridCoords[indices[quarterIndex][0]][0], boundGridCoords[indices[quarterIndex][0]][1], minHeights[indices[quarterIndex][0]]),
+ G3D::Vector3(boundGridCoords[indices[quarterIndex][1]][0], boundGridCoords[indices[quarterIndex][1]][1], minHeights[indices[quarterIndex][1]]),
+ G3D::Vector3(boundGridCoords[indices[quarterIndex][2]][0], boundGridCoords[indices[quarterIndex][2]][1], minHeights[indices[quarterIndex][2]])
+ );
}
return true;
@@ -2348,62 +2378,32 @@ float GridMap::getHeightFromUint16(float x, float y) const
float GridMap::getMinHeight(float x, float y) const
{
- if (!_minHeight)
+ if (!_minHeightPlanes)
return -500.0f;
- static uint32 const indices[] =
- {
- 3, 0, 4,
- 0, 1, 4,
- 1, 2, 4,
- 2, 5, 4,
- 5, 8, 4,
- 8, 7, 4,
- 7, 6, 4,
- 6, 3, 4
- };
-
- static float const boundGridCoords[] =
- {
- 0.0f, 0.0f,
- 0.0f, -266.66666f,
- 0.0f, -533.33331f,
- -266.66666f, 0.0f,
- -266.66666f, -266.66666f,
- -266.66666f, -533.33331f,
- -533.33331f, 0.0f,
- -533.33331f, -266.66666f,
- -533.33331f, -533.33331f
- };
-
- Cell cell(x, y);
- float gx = x - (int32(cell.GridX()) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
- float gy = y - (int32(cell.GridY()) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
+ GridCoord gridCoord = Trinity::ComputeGridCoord(x, y);
+
+ int32 doubleGridX = int32(std::floor(-(x - MAP_HALFSIZE) / CENTER_GRID_OFFSET));
+ int32 doubleGridY = int32(std::floor(-(y - MAP_HALFSIZE) / CENTER_GRID_OFFSET));
+
+ float gx = x - (int32(gridCoord.x_coord) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
+ float gy = y - (int32(gridCoord.y_coord) - CENTER_GRID_ID + 1) * SIZE_OF_GRIDS;
uint32 quarterIndex = 0;
- if (cell.CellY() < MAX_NUMBER_OF_CELLS / 2)
+ if (doubleGridY & 1)
{
- if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2)
- {
- quarterIndex = 4 + (gy > gx);
- }
+ if (doubleGridX & 1)
+ quarterIndex = 4 + (gx <= gy);
else
quarterIndex = 2 + ((-SIZE_OF_GRIDS - gx) > gy);
}
- else if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2)
- {
+ else if (doubleGridX & 1)
quarterIndex = 6 + ((-SIZE_OF_GRIDS - gx) <= gy);
- }
else
quarterIndex = gx > gy;
- quarterIndex *= 3;
-
- return G3D::Plane(
- G3D::Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], _minHeight[indices[quarterIndex + 0]]),
- G3D::Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], _minHeight[indices[quarterIndex + 1]]),
- G3D::Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], _minHeight[indices[quarterIndex + 2]])
- ).distance(G3D::Vector3(gx, gy, 0.0f));
+ G3D::Ray ray = G3D::Ray::fromOriginAndDirection(G3D::Vector3(gx, gy, 0.0f), G3D::Vector3::unitZ());
+ return ray.intersection(_minHeightPlanes[quarterIndex]).z;
}
float GridMap::getLiquidLevel(float x, float y) const
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
index 58f175a1328..302252acaac 100644
--- a/src/server/game/Maps/Map.h
+++ b/src/server/game/Maps/Map.h
@@ -66,6 +66,7 @@ enum Difficulty : uint8;
enum WeatherState : uint32;
namespace Trinity { struct ObjectUpdater; }
+namespace G3D { class Plane; }
struct ScriptAction
{
@@ -178,8 +179,7 @@ class TC_GAME_API GridMap
uint16* m_uint16_V8;
uint8* m_uint8_V8;
};
- int16* _maxHeight;
- int16* _minHeight;
+ G3D::Plane* _minHeightPlanes;
// Height level data
float _gridHeight;
float _gridIntHeightMultiplier;