Core/Maps & Extractors: Move copypasted map file headers into a single shared file and replace #defines with enums
This commit is contained in:
1 parent
8c447da29d
commit
21e9854686
13 files changed
+285
-332
No files matched your search
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
#include "StringFormat.h"
|
||||
#include "MapDefines.h"
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <bitset>
|
||||
@@ -449,75 +450,6 @@ void ReadLiquidTypeTable()
|
||||
// Adt file convertor function and data
|
||||
//
|
||||
|
||||
// Map file format data
|
||||
static char const* MAP_MAGIC = "MAPS";
|
||||
static uint32 const MAP_VERSION_MAGIC = 10;
|
||||
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;
|
||||
@@ -538,7 +470,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];
|
||||
uint16 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
|
||||
@@ -573,9 +505,9 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
return false;
|
||||
|
||||
// Prepare map header
|
||||
map_fileheader map;
|
||||
map.mapMagic = *reinterpret_cast<uint32 const*>(MAP_MAGIC);
|
||||
map.versionMagic = MAP_VERSION_MAGIC;
|
||||
map_fileheader map{ };
|
||||
map.mapMagic = MapMagic;
|
||||
map.versionMagic = MapVersionMagic;
|
||||
map.buildMagic = build;
|
||||
|
||||
// Get area flags data
|
||||
@@ -680,7 +612,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -690,20 +622,20 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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)
|
||||
@@ -758,16 +690,16 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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;
|
||||
default:
|
||||
printf("\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->LiquidType, inputPath.c_str(), i, j);
|
||||
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\nchunk %d,%d\n", h->LiquidType, inputPath.c_str(), 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;
|
||||
@@ -814,8 +746,8 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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;
|
||||
@@ -823,7 +755,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
}
|
||||
else
|
||||
{
|
||||
areaHeader.flags |= MAP_AREA_NO_AREA;
|
||||
areaHeader.flags |= map_areaHeaderFlags::NoArea;
|
||||
areaHeader.gridArea = static_cast<uint16>(areaId);
|
||||
}
|
||||
|
||||
@@ -873,26 +805,26 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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
|
||||
@@ -901,18 +833,18 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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++)
|
||||
@@ -922,7 +854,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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++)
|
||||
@@ -940,7 +872,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
// 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++)
|
||||
{
|
||||
@@ -958,7 +890,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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;
|
||||
@@ -993,8 +925,8 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
}
|
||||
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;
|
||||
@@ -1003,16 +935,16 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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;
|
||||
@@ -1020,7 +952,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1050,19 +982,19 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
outFile.write(reinterpret_cast<const char*>(&map), sizeof(map));
|
||||
// Store area data
|
||||
outFile.write(reinterpret_cast<const char*>(&areaHeader), sizeof(areaHeader));
|
||||
if (!(areaHeader.flags & MAP_AREA_NO_AREA))
|
||||
if (!areaHeader.flags.HasFlag(map_areaHeaderFlags::NoArea))
|
||||
outFile.write(reinterpret_cast<const char*>(area_ids), sizeof(area_ids));
|
||||
|
||||
// Store height data
|
||||
outFile.write(reinterpret_cast<const char*>(&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<const char*>(uint16_V9), sizeof(uint16_V9));
|
||||
outFile.write(reinterpret_cast<const char*>(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<const char*>(uint8_V9), sizeof(uint8_V9));
|
||||
outFile.write(reinterpret_cast<const char*>(uint8_V8), sizeof(uint8_V8));
|
||||
@@ -1074,7 +1006,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
@@ -1084,13 +1016,13 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
|
||||
if (map.liquidMapOffset)
|
||||
{
|
||||
outFile.write(reinterpret_cast<const char*>(&liquidHeader), sizeof(liquidHeader));
|
||||
if (!(liquidHeader.flags & MAP_LIQUID_NO_TYPE))
|
||||
if (!liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoType))
|
||||
{
|
||||
outFile.write(reinterpret_cast<const char*>(liquid_entry), sizeof(liquid_entry));
|
||||
outFile.write(reinterpret_cast<const char*>(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<const char*>(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX]), sizeof(float) * liquidHeader.width);
|
||||
@@ -1183,8 +1115,8 @@ void ExtractMapsFromMpq(uint32 build)
|
||||
|
||||
if (FILE* tileList = fopen(Trinity::StringFormat("%s/maps/%03u.tilelist", output_path, map_ids[z].id).c_str(), "wb"))
|
||||
{
|
||||
fwrite(MAP_MAGIC, 1, strlen(MAP_MAGIC), tileList);
|
||||
fwrite(&MAP_VERSION_MAGIC, sizeof(MAP_VERSION_MAGIC), 1, tileList);
|
||||
fwrite(MapMagic.data(), 1, MapMagic.size(), tileList);
|
||||
fwrite(&MapVersionMagic, 1, sizeof(MapVersionMagic), tileList);
|
||||
fwrite(&build, sizeof(build), 1, tileList);
|
||||
fwrite(existingTiles.to_string().c_str(), 1, existingTiles.size(), tileList);
|
||||
fclose(tileList);
|
||||
|
||||
Reference in new issue
Block a user