Core/Maps: Moved min height calculation to worldserver for more precise results

Closes #16530
This commit is contained in:
Shauren
2016-02-10 21:25:28 +01:00
parent fdfa210b46
commit c09f72a2c8
4 changed files with 66 additions and 87 deletions

View File

@@ -40,7 +40,7 @@
#include "Weather.h"
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'} };
@@ -1816,10 +1816,10 @@ bool GridMap::loadHeightData(FILE* in, uint32 offset, uint32 /*size*/)
if (header.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
{
_maxHeight = new float[16 * 16];
_minHeight = new float[16 * 16];
if (fread(_maxHeight, sizeof(float), 16 * 16, in) != 16 * 16 ||
fread(_minHeight, sizeof(float), 16 * 16, in) != 16 * 16)
_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)
return false;
}
@@ -2098,11 +2098,59 @@ float GridMap::getMinHeight(float x, float y) const
if (!_minHeight)
return -500.0f;
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 _minHeight[lx * 16 + ly];
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;
uint32 quarterIndex = 0;
if (cell.CellY() < MAX_NUMBER_OF_CELLS / 2)
{
if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2)
{
quarterIndex = 4 + (gy > gx);
}
else
quarterIndex = 2 + ((-SIZE_OF_GRIDS - gx) > gy);
}
else if (cell.CellX() < MAX_NUMBER_OF_CELLS / 2)
{
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));
}
float GridMap::getLiquidLevel(float x, float y) const

View File

@@ -169,8 +169,8 @@ class GridMap
uint16* m_uint16_V8;
uint8* m_uint8_V8;
};
float* _maxHeight;
float* _minHeight;
int16* _maxHeight;
int16* _minHeight;
// Height level data
float _gridHeight;
float _gridIntHeightMultiplier;

View File

@@ -353,7 +353,7 @@ void ReadLiquidTypeTableDBC()
// Map file format data
static char const* MAP_MAGIC = "MAPS";
static char const* MAP_VERSION_MAGIC = "v1.7";
static char const* MAP_VERSION_MAGIC = "v1.8";
static char const* MAP_AREA_MAGIC = "AREA";
static char const* MAP_HEIGHT_MAGIC = "MHGT";
static char const* MAP_LIQUID_MAGIC = "MLIQ";
@@ -445,8 +445,8 @@ bool liquid_show[ADT_GRID_SIZE][ADT_GRID_SIZE];
float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
uint8 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID][8];
float flight_box_max[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
float flight_box_min[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
int16 flight_box_max[3][3];
int16 flight_box_min[3][3];
bool TransformToHighRes(uint16 lowResHoles, uint8 hiResHoles[8])
{
@@ -705,77 +705,8 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
if (FileChunk* chunk = adt.GetChunk("MFBO"))
{
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
};
adt_MFBO* mfbo = chunk->As<adt_MFBO>();
for (int gy = 0; gy < ADT_CELLS_PER_GRID; ++gy)
{
for (int gx = 0; gx < ADT_CELLS_PER_GRID; ++gx)
{
int32 quarterIndex = 0;
if (gy > ADT_CELLS_PER_GRID / 2)
{
if (gx > ADT_CELLS_PER_GRID / 2)
{
quarterIndex = 4 + gx < gy;
}
else
quarterIndex = 2;
}
else if (gx > ADT_CELLS_PER_GRID / 2)
{
quarterIndex = 7;
}
else
quarterIndex = gx > gy;
quarterIndex *= 3;
G3D::Plane planeMax(
G3D::Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], mfbo->max.coords[indices[quarterIndex + 0]]),
G3D::Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], mfbo->max.coords[indices[quarterIndex + 1]]),
G3D::Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], mfbo->max.coords[indices[quarterIndex + 2]])
);
G3D::Plane planeMin(
G3D::Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], mfbo->min.coords[indices[quarterIndex + 0]]),
G3D::Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], mfbo->min.coords[indices[quarterIndex + 1]]),
G3D::Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], mfbo->min.coords[indices[quarterIndex + 2]])
);
auto non_nan_distance = [](G3D::Plane const& plane){
auto d = plane.distance(G3D::Vector3(0.0f, 0.0f, 0.0f));
assert(!G3D::isNaN(d));
return d;
};
flight_box_max[gy][gx] = non_nan_distance(planeMax);
flight_box_min[gy][gx] = non_nan_distance(planeMin);
}
}
memcpy(flight_box_max, &mfbo->max, sizeof(flight_box_max));
memcpy(flight_box_min, &mfbo->min, sizeof(flight_box_min));
hasFlightBox = true;
}

View File

@@ -80,7 +80,7 @@ struct map_liquidHeader
namespace MMAP
{
char const* MAP_VERSION_MAGIC = "v1.7";
char const* MAP_VERSION_MAGIC = "v1.8";
TerrainBuilder::TerrainBuilder(bool skipLiquid) : m_skipLiquid (skipLiquid){ }
TerrainBuilder::~TerrainBuilder() { }