Core/Maps: ported all master branch changes for map extractor including height map extraction

* new maps, and mmaps are required
This commit is contained in:
Ovahlord committed 2019-02-25 07:37:47 +01:00
1 parent c10573f1d0
commit fe7bcac696
14 files changed
+597 -699

No files matched your search

+84 -1
View File
@@ -51,7 +51,7 @@
#include <vector>
u_map_magic MapMagic = { {'M','A','P','S'} };
u_map_magic MapVersionMagic = { {'v','1','.','7'} };
u_map_magic MapVersionMagic = { {'v','1','.','8'} };
u_map_magic MapAreaMagic = { {'A','R','E','A'} };
u_map_magic MapHeightMagic = { {'M','H','G','T'} };
u_map_magic MapLiquidMagic = { {'M','L','I','Q'} };
@@ -1812,6 +1812,7 @@ GridMap::GridMap()
_gridIntHeightMultiplier = 0;
m_V9 = nullptr;
m_V8 = nullptr;
_minHeightPlanes = nullptr;
// Liquid data
_liquidGlobalEntry = 0;
_liquidGlobalFlags = 0;
@@ -1896,6 +1897,7 @@ void GridMap::unloadData()
delete[] _areaMap;
delete[] m_V9;
delete[] m_V8;
delete[] _minHeightPlanes;
delete[] _liquidEntry;
delete[] _liquidFlags;
delete[] _liquidMap;
@@ -1903,6 +1905,7 @@ void GridMap::unloadData()
_areaMap = nullptr;
m_V9 = nullptr;
m_V8 = nullptr;
_minHeightPlanes = nullptr;
_liquidEntry = nullptr;
_liquidFlags = nullptr;
_liquidMap = nullptr;
@@ -1973,6 +1976,48 @@ bool GridMap::loadHeightData(FILE* in, uint32 offset, uint32 /*size*/)
else
_gridGetHeight = &GridMap::getHeightFromFlat;
if (header.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
{
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;
}
@@ -2265,6 +2310,36 @@ float GridMap::getHeightFromUint16(float x, float y) const
return (float)((a * x) + (b * y) + c)*_gridIntHeightMultiplier + _gridHeight;
}
float GridMap::getMinHeight(float x, float y) const
{
if (!_minHeightPlanes)
return -500.0f;
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 (doubleGridY & 1)
{
if (doubleGridX & 1)
quarterIndex = 4 + (gx <= gy);
else
quarterIndex = 2 + ((-SIZE_OF_GRIDS - gx) > gy);
}
else if (doubleGridX & 1)
quarterIndex = 6 + ((-SIZE_OF_GRIDS - gx) <= gy);
else
quarterIndex = gx > gy;
G3D::Ray ray = G3D::Ray::fromOriginAndDirection(G3D::Vector3(gx, gy, 0.0f), G3D::Vector3::unitZ());
return ray.intersection(_minHeightPlanes[quarterIndex]).z;
}
bool GridMap::isHole(int row, int col) const
{
if (!_holes)
@@ -2492,6 +2567,14 @@ float Map::GetStaticHeight(PhaseShift const& phaseShift, float x, float y, float
return mapHeight; // explicitly use map data
}
float Map::GetMinHeight(float x, float y) const
{
if (GridMap const* grid = const_cast<Map*>(this)->GetGrid(x, y))
return grid->getMinHeight(x, y);
return -500.0f;
}
float Map::GetGridHeight(uint32 mapId, float x, float y) const
{
if (GridMap* gmap = m_parentTerrainMap->GetGrid(mapId, x, y))