Core/Maps & Extractors: Move copypasted map file headers into a single shared file and replace #defines with enums

This commit is contained in:
Shauren
2021-05-29 21:21:37 +02:00
parent 2de6e56d29
commit 6ecfe58cae
13 changed files with 289 additions and 335 deletions
+46 -113
View File
@@ -22,6 +22,7 @@
#include "DB2Meta.h"
#include "DBFilesClientList.h"
#include "ExtractorDB2LoadInfo.h"
#include "MapDefines.h"
#include "StringFormat.h"
#include "adt.h"
#include "wdt.h"
@@ -390,74 +391,6 @@ bool ReadCinematicCameraDBC()
// Adt file convertor function and data
//
// Map file format data
static char const* MAP_MAGIC = "MAPS";
static char const* MAP_VERSION_MAGIC = "v1.9";
static char const* MAP_AREA_MAGIC = "AREA";
static char const* MAP_HEIGHT_MAGIC = "MHGT";
static char const* MAP_LIQUID_MAGIC = "MLIQ";
struct map_fileheader
{
uint32 mapMagic;
uint32 versionMagic;
uint32 buildMagic;
uint32 areaMapOffset;
uint32 areaMapSize;
uint32 heightMapOffset;
uint32 heightMapSize;
uint32 liquidMapOffset;
uint32 liquidMapSize;
uint32 holesOffset;
uint32 holesSize;
};
#define MAP_AREA_NO_AREA 0x0001
struct map_areaHeader
{
uint32 fourcc;
uint16 flags;
uint16 gridArea;
};
#define MAP_HEIGHT_NO_HEIGHT 0x0001
#define MAP_HEIGHT_AS_INT16 0x0002
#define MAP_HEIGHT_AS_INT8 0x0004
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS 0x0008
struct map_heightHeader
{
uint32 fourcc;
uint32 flags;
float gridHeight;
float gridMaxHeight;
};
#define MAP_LIQUID_TYPE_NO_WATER 0x00
#define MAP_LIQUID_TYPE_WATER 0x01
#define MAP_LIQUID_TYPE_OCEAN 0x02
#define MAP_LIQUID_TYPE_MAGMA 0x04
#define MAP_LIQUID_TYPE_SLIME 0x08
#define MAP_LIQUID_TYPE_DARK_WATER 0x10
#define MAP_LIQUID_NO_TYPE 0x0001
#define MAP_LIQUID_NO_HEIGHT 0x0002
struct map_liquidHeader
{
uint32 fourcc;
uint8 flags;
uint8 liquidFlags;
uint16 liquidType;
uint8 offsetX;
uint8 offsetY;
uint8 width;
uint8 height;
float liquidLevel;
};
float selectUInt8StepStore(float maxDiff)
{
return 255 / maxDiff;
@@ -478,7 +411,7 @@ uint8 uint8_V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
uint8 uint8_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
uint16 liquid_entry[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
map_liquidHeaderTypeFlags liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
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];
@@ -523,9 +456,9 @@ bool TransformToHighRes(uint16 lowResHoles, uint8 hiResHoles[8])
bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const& outputPath, int gx, int gy, uint32 build, bool ignoreDeepWater)
{
// Prepare map header
map_fileheader map;
map.mapMagic = *reinterpret_cast<uint32 const*>(MAP_MAGIC);
map.versionMagic = *reinterpret_cast<uint32 const*>(MAP_VERSION_MAGIC);
map_fileheader map{};
map.mapMagic = MapMagic;
map.versionMagic = MapVersionMagic;
map.buildMagic = build;
// Get area flags data
@@ -630,7 +563,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
{
liquid_show[cy][cx] = true;
if (!ignoreDeepWater && liquid->flags[y][x] & (1 << 7))
liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_DARK_WATER;
liquid_flags[mcnk->iy][mcnk->ix] |= map_liquidHeaderTypeFlags::DarkWater;
++count;
}
}
@@ -640,20 +573,20 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
if (c_flag & (1 << 2))
{
liquid_entry[mcnk->iy][mcnk->ix] = 1;
liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_WATER; // water
liquid_flags[mcnk->iy][mcnk->ix] |= map_liquidHeaderTypeFlags::Water; // water
}
if (c_flag & (1 << 3))
{
liquid_entry[mcnk->iy][mcnk->ix] = 2;
liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_OCEAN; // ocean
liquid_flags[mcnk->iy][mcnk->ix] |= map_liquidHeaderTypeFlags::Ocean; // ocean
}
if (c_flag & (1 << 4))
{
liquid_entry[mcnk->iy][mcnk->ix] = 3;
liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_MAGMA; // magma/slime
liquid_flags[mcnk->iy][mcnk->ix] |= map_liquidHeaderTypeFlags::Magma; // magma/slime
}
if (!count && liquid_flags[mcnk->iy][mcnk->ix])
if (!count && liquid_flags[mcnk->iy][mcnk->ix] != map_liquidHeaderTypeFlags::NoWater)
fprintf(stderr, "Wrong liquid detect in MCLQ chunk");
for (int y = 0; y <= ADT_CELL_SIZE; ++y)
@@ -717,16 +650,16 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
liquid_entry[i][j] = h2o->GetLiquidType(h);
switch (LiquidTypes.at(liquid_entry[i][j]).SoundBank)
{
case LIQUID_TYPE_WATER: liquid_flags[i][j] |= MAP_LIQUID_TYPE_WATER; break;
case LIQUID_TYPE_OCEAN: liquid_flags[i][j] |= MAP_LIQUID_TYPE_OCEAN; if (!ignoreDeepWater && attrs.Deep) liquid_flags[i][j] |= MAP_LIQUID_TYPE_DARK_WATER; break;
case LIQUID_TYPE_MAGMA: liquid_flags[i][j] |= MAP_LIQUID_TYPE_MAGMA; break;
case LIQUID_TYPE_SLIME: liquid_flags[i][j] |= MAP_LIQUID_TYPE_SLIME; break;
case LIQUID_TYPE_WATER: liquid_flags[i][j] |= map_liquidHeaderTypeFlags::Water; break;
case LIQUID_TYPE_OCEAN: liquid_flags[i][j] |= map_liquidHeaderTypeFlags::Ocean; if (!ignoreDeepWater && attrs.Deep) liquid_flags[i][j] |= map_liquidHeaderTypeFlags::DarkWater; break;
case LIQUID_TYPE_MAGMA: liquid_flags[i][j] |= map_liquidHeaderTypeFlags::Magma; break;
case LIQUID_TYPE_SLIME: liquid_flags[i][j] |= map_liquidHeaderTypeFlags::Slime; break;
default:
printf("\nCan't find Liquid type %u for map %s [%u,%u]\nchunk %d,%d\n", h->LiquidType, mapName.c_str(), gx, gy, i, j);
break;
}
if (!count && liquid_flags[i][j])
if (!count && liquid_flags[i][j] != map_liquidHeaderTypeFlags::NoWater)
printf("Wrong liquid detect in MH2O chunk");
int32 pos = 0;
@@ -773,8 +706,8 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
map.areaMapSize = sizeof(map_areaHeader);
map_areaHeader areaHeader;
areaHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_AREA_MAGIC);
areaHeader.flags = 0;
areaHeader.areaMagic = MapAreaMagic;
areaHeader.flags = map_areaHeaderFlags::None;
if (fullAreaData)
{
areaHeader.gridArea = 0;
@@ -782,7 +715,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
}
else
{
areaHeader.flags |= MAP_AREA_NO_AREA;
areaHeader.flags |= map_areaHeaderFlags::NoArea;
areaHeader.gridArea = static_cast<uint16>(areaId);
}
@@ -831,26 +764,26 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
map.heightMapSize = sizeof(map_heightHeader);
map_heightHeader heightHeader;
heightHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_HEIGHT_MAGIC);
heightHeader.flags = 0;
heightHeader.heightMagic = MapHeightMagic;
heightHeader.flags = map_heightHeaderFlags::None;
heightHeader.gridHeight = minHeight;
heightHeader.gridMaxHeight = maxHeight;
if (maxHeight == minHeight)
heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
heightHeader.flags |= map_heightHeaderFlags::NoHeight;
// Not need store if flat surface
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_height_delta_limit)
heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
heightHeader.flags |= map_heightHeaderFlags::NoHeight;
if (hasFlightBox)
{
heightHeader.flags |= MAP_HEIGHT_HAS_FLIGHT_BOUNDS;
heightHeader.flags |= map_heightHeaderFlags::HasFlightBounds;
map.heightMapSize += sizeof(flight_box_max) + sizeof(flight_box_min);
}
// Try store as packed in uint16 or uint8 values
if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT))
if (!heightHeader.flags.HasFlag(map_heightHeaderFlags::NoHeight))
{
float step = 0;
// Try Store as uint values
@@ -859,18 +792,18 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
float diff = maxHeight - minHeight;
if (diff < CONF_float_to_int8_limit) // As uint8 (max accuracy = CONF_float_to_int8_limit/256)
{
heightHeader.flags |= MAP_HEIGHT_AS_INT8;
heightHeader.flags |= map_heightHeaderFlags::HeightAsInt8;
step = selectUInt8StepStore(diff);
}
else if (diff < CONF_float_to_int16_limit) // As uint16 (max accuracy = CONF_float_to_int16_limit/65536)
{
heightHeader.flags |= MAP_HEIGHT_AS_INT16;
heightHeader.flags |= map_heightHeaderFlags::HeightAsInt16;
step = selectUInt16StepStore(diff);
}
}
// Pack it to int values if need
if (heightHeader.flags&MAP_HEIGHT_AS_INT8)
if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt8))
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
@@ -880,7 +813,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
uint8_V9[y][x] = uint8((V9[y][x] - minHeight) * step + 0.5f);
map.heightMapSize+= sizeof(uint8_V9) + sizeof(uint8_V8);
}
else if (heightHeader.flags&MAP_HEIGHT_AS_INT16)
else if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt16))
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
@@ -898,7 +831,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
// Pack liquid data
//============================================
uint16 firstLiquidType = liquid_entry[0][0];
uint8 firstLiquidFlag = liquid_flags[0][0];
map_liquidHeaderTypeFlags firstLiquidFlag = liquid_flags[0][0];
bool fullType = false;
for (int y = 0; y < ADT_CELLS_PER_GRID; y++)
{
@@ -916,7 +849,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
map_liquidHeader liquidHeader;
// no water data (if all grid have 0 liquid type)
if (firstLiquidFlag == 0 && !fullType)
if (firstLiquidFlag == map_liquidHeaderTypeFlags::NoWater && !fullType)
{
// No liquid data
map.liquidMapOffset = 0;
@@ -948,8 +881,8 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
}
map.liquidMapOffset = map.heightMapOffset + map.heightMapSize;
map.liquidMapSize = sizeof(map_liquidHeader);
liquidHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_LIQUID_MAGIC);
liquidHeader.flags = 0;
liquidHeader.liquidMagic = MapLiquidMagic;
liquidHeader.flags = map_liquidHeaderFlags::None;
liquidHeader.liquidType = 0;
liquidHeader.offsetX = minX;
liquidHeader.offsetY = minY;
@@ -958,16 +891,16 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
liquidHeader.liquidLevel = minHeight;
if (maxHeight == minHeight)
liquidHeader.flags |= MAP_LIQUID_NO_HEIGHT;
liquidHeader.flags |= map_liquidHeaderFlags::NoHeight;
// Not need store if flat surface
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_liquid_delta_limit)
liquidHeader.flags |= MAP_LIQUID_NO_HEIGHT;
liquidHeader.flags |= map_liquidHeaderFlags::NoHeight;
if (!fullType)
liquidHeader.flags |= MAP_LIQUID_NO_TYPE;
liquidHeader.flags |= map_liquidHeaderFlags::NoType;
if (liquidHeader.flags & MAP_LIQUID_NO_TYPE)
if (liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoType))
{
liquidHeader.liquidFlags = firstLiquidFlag;
liquidHeader.liquidType = firstLiquidType;
@@ -975,7 +908,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
else
map.liquidMapSize += sizeof(liquid_entry) + sizeof(liquid_flags);
if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
if (!liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoHeight))
map.liquidMapSize += sizeof(float)*liquidHeader.width*liquidHeader.height;
}
@@ -1005,19 +938,19 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
outFile.write(reinterpret_cast<char const*>(&map), sizeof(map));
// Store area data
outFile.write(reinterpret_cast<char const*>(&areaHeader), sizeof(areaHeader));
if (!(areaHeader.flags & MAP_AREA_NO_AREA))
if (!areaHeader.flags.HasFlag(map_areaHeaderFlags::NoArea))
outFile.write(reinterpret_cast<char const*>(area_ids), sizeof(area_ids));
// Store height data
outFile.write(reinterpret_cast<char const*>(&heightHeader), sizeof(heightHeader));
if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT))
if (!heightHeader.flags.HasFlag(map_heightHeaderFlags::NoHeight))
{
if (heightHeader.flags & MAP_HEIGHT_AS_INT16)
if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt16))
{
outFile.write(reinterpret_cast<char const*>(uint16_V9), sizeof(uint16_V9));
outFile.write(reinterpret_cast<char const*>(uint16_V8), sizeof(uint16_V8));
}
else if (heightHeader.flags & MAP_HEIGHT_AS_INT8)
else if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt8))
{
outFile.write(reinterpret_cast<char const*>(uint8_V9), sizeof(uint8_V9));
outFile.write(reinterpret_cast<char const*>(uint8_V8), sizeof(uint8_V8));
@@ -1029,7 +962,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
}
}
if (heightHeader.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HasFlightBounds))
{
outFile.write(reinterpret_cast<char*>(flight_box_max), sizeof(flight_box_max));
outFile.write(reinterpret_cast<char*>(flight_box_min), sizeof(flight_box_min));
@@ -1039,13 +972,13 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
if (map.liquidMapOffset)
{
outFile.write(reinterpret_cast<char const*>(&liquidHeader), sizeof(liquidHeader));
if (!(liquidHeader.flags & MAP_LIQUID_NO_TYPE))
if (!liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoType))
{
outFile.write(reinterpret_cast<char const*>(liquid_entry), sizeof(liquid_entry));
outFile.write(reinterpret_cast<char const*>(liquid_flags), sizeof(liquid_flags));
}
if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
if (!liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoHeight))
{
for (int y = 0; y < liquidHeader.height; y++)
outFile.write(reinterpret_cast<char const*>(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX]), sizeof(float) * liquidHeader.width);
@@ -1162,8 +1095,8 @@ void ExtractMaps(uint32 build)
if (FILE* tileList = fopen(Trinity::StringFormat("%s/maps/%04u.tilelist", output_path.string().c_str(), map_ids[z].Id).c_str(), "wb"))
{
fwrite(MAP_MAGIC, 1, strlen(MAP_MAGIC), tileList);
fwrite(MAP_VERSION_MAGIC, 1, strlen(MAP_VERSION_MAGIC), tileList);
fwrite(MapMagic.data(), 1, MapMagic.size(), tileList);
fwrite(MapVersionMagic.data(), 1, MapVersionMagic.size(), tileList);
fwrite(&build, sizeof(build), 1, tileList);
fwrite(existingTiles.to_string().c_str(), 1, existingTiles.size(), tileList);
fclose(tileList);