Update Vmaps | Mmaps | Recastnav and fixed FleeingMovement

- Fixes getHeight collision (Map height is now calculated properly core-side, extraction of Maps, Vmaps is required)

- Fixes invisible walls causing LoS errores and wrong pathing in some zones.

- Mmaps update, padding is used, now to ensure proper binary-identical mmtiles

- Updated Recastnav to work properly with new updates

- Updated Area Storage

- Implement Map out of Bound (players will pop on closest graveyard if out of bounds)

- FleeingMovementGenerator updated, LoS calc to not go out of bounds or in/under textured when 
fleeing

- Added command .mmap, port from TC (info about mmaps)
This commit is contained in:
sucofog
2017-11-14 15:14:43 +01:00
committed by Yehonal
parent d98ba9cdaa
commit e772b08c68
79 changed files with 5037 additions and 3018 deletions

View File

@@ -12,8 +12,10 @@
file(GLOB_RECURSE sources *.cpp *.h)
set(include_Dirs
${CMAKE_SOURCE_DIR}/modules/worldengine/nucleus/src/Utilities
${CMAKE_SOURCE_DIR}/modules/worldengine/nucleus/src
${CMAKE_SOURCE_DIR}/modules/worldengine/deps/libmpq
${CMAKE_SOURCE_DIR}/modules/worldengine/deps/g3dlite/include
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/loadlib
)

View File

@@ -20,9 +20,12 @@
#include "dbcfile.h"
#include "mpq_libmpq04.h"
#include "StringFormat.h"
#include "adt.h"
#include "wdt.h"
#include "G3D/Plane.h"
#include <fcntl.h>
#if defined( __GNUC__ )
@@ -49,11 +52,10 @@ typedef struct
} map_id;
map_id *map_ids;
uint16 *areas;
uint16 *LiqType;
char output_path[128] = ".";
char input_path[128] = ".";
uint32 maxAreaId = 0;
#define MAX_PATH_LENGTH 128
char output_path[MAX_PATH_LENGTH] = ".";
char input_path[MAX_PATH_LENGTH] = ".";
// **************************************************
// Extractor options
@@ -244,30 +246,6 @@ uint32 ReadMapDBC()
return map_count;
}
void ReadAreaTableDBC()
{
printf("Read AreaTable.dbc file...");
DBCFile dbc("DBFilesClient\\AreaTable.dbc");
if(!dbc.open())
{
printf("Fatal error: Invalid AreaTable.dbc file format!\n");
exit(1);
}
size_t area_count = dbc.getRecordCount();
size_t maxid = dbc.getMaxId();
areas = new uint16[maxid + 1];
memset(areas, 0xff, (maxid + 1) * sizeof(uint16));
for(uint32 x = 0; x < area_count; ++x)
areas[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
maxAreaId = dbc.getMaxId();
printf("Done! (%u areas loaded)\n", (uint32)area_count);
}
void ReadLiquidTypeTableDBC()
{
printf("Read LiquidType.dbc file...");
@@ -295,7 +273,7 @@ void ReadLiquidTypeTableDBC()
// Map file format data
static char const* MAP_MAGIC = "MAPS";
static char const* MAP_VERSION_MAGIC = "v1.3";
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";
@@ -324,9 +302,10 @@ struct map_areaHeader
uint16 gridArea;
};
#define MAP_HEIGHT_NO_HEIGHT 0x0001
#define MAP_HEIGHT_AS_INT16 0x0002
#define MAP_HEIGHT_AS_INT8 0x0004
#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
{
@@ -371,7 +350,7 @@ float selectUInt16StepStore(float maxDiff)
return 65535 / maxDiff;
}
// Temporary grid data store
uint16 area_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
uint16 area_ids[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
float V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
@@ -385,17 +364,20 @@ uint8 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];
bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/, uint32 build)
int16 flight_box_max[3][3];
int16 flight_box_min[3][3];
bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int /*cell_y*/, int /*cell_x*/, uint32 build)
{
ADT_file adt;
if (!adt.loadFile(filename))
if (!adt.loadFile(inputPath))
return false;
adt_MCIN *cells = adt.a_grid->getMCIN();
if (!cells)
{
printf("Can't find cells in '%s'\n", filename);
printf("Can't find cells in '%s'\n", inputPath.c_str());
return false;
}
@@ -405,39 +387,25 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
// Prepare map header
map_fileheader map;
map.mapMagic = *(uint32 const*)MAP_MAGIC;
map.versionMagic = *(uint32 const*)MAP_VERSION_MAGIC;
map.mapMagic = *reinterpret_cast<uint32 const*>(MAP_MAGIC);
map.versionMagic = *reinterpret_cast<uint32 const*>(MAP_VERSION_MAGIC);
map.buildMagic = build;
// Get area flags data
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
{
adt_MCNK * cell = cells->getMCNK(i,j);
uint32 areaid = cell->areaid;
if(areaid && areaid <= maxAreaId)
{
if(areas[areaid] != 0xffff)
{
area_flags[i][j] = areas[areaid];
continue;
}
printf("File: %s\nCan't find area flag for areaid %u [%d, %d].\n", filename, areaid, cell->ix, cell->iy);
}
area_flags[i][j] = 0xffff;
}
}
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
area_ids[i][j] = cells->getMCNK(i, j)->areaid;
//============================================
// Try pack area data
//============================================
bool fullAreaData = false;
uint32 areaflag = area_flags[0][0];
for (int y=0;y<ADT_CELLS_PER_GRID;y++)
uint32 areaId = area_ids[0][0];
for (int y = 0; y < ADT_CELLS_PER_GRID; ++y)
{
for(int x=0;x<ADT_CELLS_PER_GRID;x++)
for (int x = 0; x < ADT_CELLS_PER_GRID; ++x)
{
if(area_flags[y][x]!=areaflag)
if (area_ids[y][x] != areaId)
{
fullAreaData = true;
break;
@@ -449,27 +417,27 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
map.areaMapSize = sizeof(map_areaHeader);
map_areaHeader areaHeader;
areaHeader.fourcc = *(uint32 const*)MAP_AREA_MAGIC;
areaHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_AREA_MAGIC);
areaHeader.flags = 0;
if (fullAreaData)
{
areaHeader.gridArea = 0;
map.areaMapSize+=sizeof(area_flags);
map.areaMapSize += sizeof(area_ids);
}
else
{
areaHeader.flags |= MAP_AREA_NO_AREA;
areaHeader.gridArea = (uint16)areaflag;
areaHeader.gridArea = static_cast<uint16>(areaId);
}
//
// Get Height map from grid
//
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
for (int i = 0; i<ADT_CELLS_PER_GRID; i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
for (int j = 0; j<ADT_CELLS_PER_GRID; j++)
{
adt_MCNK * cell = cells->getMCNK(i,j);
adt_MCNK * cell = cells->getMCNK(i, j);
if (!cell)
continue;
// Height values for triangles stored in order:
@@ -489,22 +457,22 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
// . . . . . . . .
// Set map height as grid height
for (int y=0; y <= ADT_CELL_SIZE; y++)
for (int y = 0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x <= ADT_CELL_SIZE; x++)
for (int x = 0; x <= ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V9[cy][cx]=cell->ypos;
V9[cy][cx] = cell->ypos;
}
}
for (int y=0; y < ADT_CELL_SIZE; y++)
for (int y = 0; y < ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x < ADT_CELL_SIZE; x++)
for (int x = 0; x < ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V8[cy][cx]=cell->ypos;
V8[cy][cx] = cell->ypos;
}
}
// Get custom height
@@ -512,23 +480,23 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
if (!v)
continue;
// get V9 height map
for (int y=0; y <= ADT_CELL_SIZE; y++)
for (int y = 0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x <= ADT_CELL_SIZE; x++)
for (int x = 0; x <= ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V9[cy][cx]+=v->height_map[y*(ADT_CELL_SIZE*2+1)+x];
V9[cy][cx] += v->height_map[y*(ADT_CELL_SIZE * 2 + 1) + x];
}
}
// get V8 height map
for (int y=0; y < ADT_CELL_SIZE; y++)
for (int y = 0; y < ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x < ADT_CELL_SIZE; x++)
for (int x = 0; x < ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V8[cy][cx]+=v->height_map[y*(ADT_CELL_SIZE*2+1)+ADT_CELL_SIZE+1+x];
V8[cy][cx] += v->height_map[y*(ADT_CELL_SIZE * 2 + 1) + ADT_CELL_SIZE + 1 + x];
}
}
}
@@ -538,18 +506,18 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
//============================================
float maxHeight = -20000;
float minHeight = 20000;
for (int y=0; y<ADT_GRID_SIZE; y++)
for (int y = 0; y<ADT_GRID_SIZE; y++)
{
for(int x=0;x<ADT_GRID_SIZE;x++)
for (int x = 0; x<ADT_GRID_SIZE; x++)
{
float h = V8[y][x];
if (maxHeight < h) maxHeight = h;
if (minHeight > h) minHeight = h;
}
}
for (int y=0; y<=ADT_GRID_SIZE; y++)
for (int y = 0; y <= ADT_GRID_SIZE; y++)
{
for(int x=0;x<=ADT_GRID_SIZE;x++)
for(int x = 0; x<= ADT_GRID_SIZE; x++)
{
float h = V9[y][x];
if (maxHeight < h) maxHeight = h;
@@ -560,12 +528,12 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
// Check for allow limit minimum height (not store height in deep ochean - allow save some memory)
if (CONF_allow_height_limit && minHeight < CONF_use_minHeight)
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
for (int y = 0; y<ADT_GRID_SIZE; y++)
for (int x = 0; x<ADT_GRID_SIZE; x++)
if (V8[y][x] < CONF_use_minHeight)
V8[y][x] = CONF_use_minHeight;
for (int y=0; y<=ADT_GRID_SIZE; y++)
for(int x=0;x<=ADT_GRID_SIZE;x++)
for (int y = 0; y <= ADT_GRID_SIZE; y++)
for (int x = 0; x <= ADT_GRID_SIZE; x++)
if (V9[y][x] < CONF_use_minHeight)
V9[y][x] = CONF_use_minHeight;
if (minHeight < CONF_use_minHeight)
@@ -574,11 +542,19 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
maxHeight = CONF_use_minHeight;
}
bool hasFlightBox = false;
if (adt_MFBO* mfbo = adt.a_grid->getMFBO())
{
memcpy(flight_box_max, &mfbo->max, sizeof(flight_box_max));
memcpy(flight_box_min, &mfbo->min, sizeof(flight_box_min));
hasFlightBox = true;
}
map.heightMapOffset = map.areaMapOffset + map.areaMapSize;
map.heightMapSize = sizeof(map_heightHeader);
map_heightHeader heightHeader;
heightHeader.fourcc = *(uint32 const*)MAP_HEIGHT_MAGIC;
heightHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_HEIGHT_MAGIC);
heightHeader.flags = 0;
heightHeader.gridHeight = minHeight;
heightHeader.gridMaxHeight = maxHeight;
@@ -589,6 +565,12 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
// 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;
if (hasFlightBox)
{
heightHeader.flags |= MAP_HEIGHT_HAS_FLIGHT_BOUNDS;
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))
@@ -600,12 +582,12 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
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_HEIGHT_AS_INT8;
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_HEIGHT_AS_INT16;
step = selectUInt16StepStore(diff);
}
}
@@ -613,32 +595,32 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
// Pack it to int values if need
if (heightHeader.flags&MAP_HEIGHT_AS_INT8)
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
for (int y = 0; y<ADT_GRID_SIZE; y++)
for (int x = 0; x<ADT_GRID_SIZE; x++)
uint8_V8[y][x] = uint8((V8[y][x] - minHeight) * step + 0.5f);
for (int y=0; y<=ADT_GRID_SIZE; y++)
for(int x=0;x<=ADT_GRID_SIZE;x++)
for (int y = 0; y <= ADT_GRID_SIZE; y++)
for (int x = 0; x <= ADT_GRID_SIZE; x++)
uint8_V9[y][x] = uint8((V9[y][x] - minHeight) * step + 0.5f);
map.heightMapSize+= sizeof(uint8_V9) + sizeof(uint8_V8);
map.heightMapSize += sizeof(uint8_V9) + sizeof(uint8_V8);
}
else if (heightHeader.flags&MAP_HEIGHT_AS_INT16)
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
for (int y = 0; y<ADT_GRID_SIZE; y++)
for (int x = 0; x<ADT_GRID_SIZE; x++)
uint16_V8[y][x] = uint16((V8[y][x] - minHeight) * step + 0.5f);
for (int y=0; y<=ADT_GRID_SIZE; y++)
for(int x=0;x<=ADT_GRID_SIZE;x++)
for (int y = 0; y <= ADT_GRID_SIZE; y++)
for (int x = 0; x <= ADT_GRID_SIZE; x++)
uint16_V9[y][x] = uint16((V9[y][x] - minHeight) * step + 0.5f);
map.heightMapSize+= sizeof(uint16_V9) + sizeof(uint16_V8);
map.heightMapSize += sizeof(uint16_V9) + sizeof(uint16_V8);
}
else
map.heightMapSize+= sizeof(V9) + sizeof(V8);
map.heightMapSize += sizeof(V9) + sizeof(V8);
}
// Get from MCLQ chunk (old)
for (int i = 0; i < ADT_CELLS_PER_GRID; i++)
{
for(int j = 0; j < ADT_CELLS_PER_GRID; j++)
for (int j = 0; j < ADT_CELLS_PER_GRID; j++)
{
adt_MCNK *cell = cells->getMCNK(i, j);
if (!cell)
@@ -658,7 +640,7 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
if (liquid->flags[y][x] != 0x0F)
{
liquid_show[cy][cx] = true;
if (liquid->flags[y][x] & (1<<7))
if (liquid->flags[y][x] & (1 << 7))
liquid_flags[i][j] |= MAP_LIQUID_TYPE_DARK_WATER;
++count;
}
@@ -666,17 +648,17 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
}
uint32 c_flag = cell->flags;
if (c_flag & (1<<2))
if (c_flag & (1 << 2))
{
liquid_entry[i][j] = 1;
liquid_flags[i][j] |= MAP_LIQUID_TYPE_WATER; // water
}
if (c_flag & (1<<3))
if (c_flag & (1 << 3))
{
liquid_entry[i][j] = 2;
liquid_flags[i][j] |= MAP_LIQUID_TYPE_OCEAN; // ocean
}
if (c_flag & (1<<4))
if (c_flag & (1 << 4))
{
liquid_entry[i][j] = 3;
liquid_flags[i][j] |= MAP_LIQUID_TYPE_MAGMA; // magma/slime
@@ -734,7 +716,7 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
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, filename, i, j);
printf("\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->liquidType, inputPath.c_str(), i, j);
break;
}
// Dark water detect
@@ -877,17 +859,17 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
map.holesSize = 0;
// Ok all data prepared - store it
FILE* output = fopen(filename2, "wb");
FILE* output = fopen(outputPath.c_str(), "wb");
if (!output)
{
printf("Can't create the output file '%s'\n", filename2);
printf("Can't create the output file '%s'\n", outputPath.c_str());
return false;
}
fwrite(&map, sizeof(map), 1, output);
// Store area data
fwrite(&areaHeader, sizeof(areaHeader), 1, output);
if (!(areaHeader.flags&MAP_AREA_NO_AREA))
fwrite(area_flags, sizeof(area_flags), 1, output);
fwrite(area_ids, sizeof(area_ids), 1, output);
// Store height data
fwrite(&heightHeader, sizeof(heightHeader), 1, output);
@@ -910,6 +892,12 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
}
}
if (heightHeader.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
{
fwrite(flight_box_max, sizeof(flight_box_max), 1, output);
fwrite(flight_box_min, sizeof(flight_box_min), 1, output);
}
// Store liquid data if need
if (map.liquidMapOffset)
{
@@ -937,15 +925,14 @@ bool ConvertADT(char *filename, char *filename2, int /*cell_y*/, int /*cell_x*/,
void ExtractMapsFromMpq(uint32 build)
{
char mpq_filename[1024];
char output_filename[1024];
char mpq_map_name[1024];
std::string mpqFileName;
std::string outputFileName;
std::string mpqMapName;
printf("Extracting maps...\n");
uint32 map_count = ReadMapDBC();
ReadAreaTableDBC();
ReadLiquidTypeTableDBC();
std::string path = output_path;
@@ -957,9 +944,9 @@ void ExtractMapsFromMpq(uint32 build)
{
printf("Extract %s (%d/%u) \n", map_ids[z].name, z+1, map_count);
// Loadup map grid data
sprintf(mpq_map_name, "World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
mpqMapName = Trinity::StringFormat("World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
WDT_file wdt;
if (!wdt.loadFile(mpq_map_name, false))
if (!wdt.loadFile(mpqMapName, false))
{
// printf("Error loading %s map wdt data\n", map_ids[z].name);
continue;
@@ -971,17 +958,16 @@ void ExtractMapsFromMpq(uint32 build)
{
if (!wdt.main->adt_list[y][x].exist)
continue;
sprintf(mpq_filename, "World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y);
sprintf(output_filename, "%s/maps/%03u%02u%02u.map", output_path, map_ids[z].id, y, x);
ConvertADT(mpq_filename, output_filename, y, x, build);
mpqFileName = Trinity::StringFormat("World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y);
outputFileName = Trinity::StringFormat("%s/maps/%03u%02u%02u.map", output_path, map_ids[z].id, y, x);
ConvertADT(mpqFileName, outputFileName, y, x, build);
}
// draw progress bar
printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE);
}
}
printf("\n");
delete [] areas;
delete [] map_ids;
delete[] map_ids;
}
bool ExtractFile( char const* mpq_name, std::string const& filename )

View File

@@ -9,15 +9,16 @@
#include "adt.h"
// Helper
int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888};
int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000};
int holetab_h[4] = { 0x1111, 0x2222, 0x4444, 0x8888 };
int holetab_v[4] = { 0x000F, 0x00F0, 0x0F00, 0xF000 };
u_map_fcc MHDRMagic = { {'R','D','H','M'} };
u_map_fcc MCINMagic = { {'N','I','C','M'} };
u_map_fcc MH2OMagic = { {'O','2','H','M'} };
u_map_fcc MCNKMagic = { {'K','N','C','M'} };
u_map_fcc MCVTMagic = { {'T','V','C','M'} };
u_map_fcc MCLQMagic = { {'Q','L','C','M'} };
u_map_fcc MHDRMagic = { { 'R','D','H','M' } };
u_map_fcc MCINMagic = { { 'N','I','C','M' } };
u_map_fcc MH2OMagic = { { 'O','2','H','M' } };
u_map_fcc MCNKMagic = { { 'K','N','C','M' } };
u_map_fcc MCVTMagic = { { 'T','V','C','M' } };
u_map_fcc MCLQMagic = { { 'Q','L','C','M' } };
u_map_fcc MFBOMagic = { { 'O','B','F','M' } };
bool isHole(int holes, int i, int j)
{
@@ -69,7 +70,7 @@ bool adt_MHDR::prepareLoadedData()
if (fcc != MHDRMagic.fcc)
return false;
if (size!=sizeof(adt_MHDR)-8)
if (size != sizeof(adt_MHDR) - 8)
return false;
// Check and prepare MCIN
@@ -80,6 +81,9 @@ bool adt_MHDR::prepareLoadedData()
if (offsMH2O && !getMH2O()->prepareLoadedData())
return false;
if (offsMFBO && flags & 1 && !getMFBO()->prepareLoadedData())
return false;
return true;
}
@@ -142,3 +146,8 @@ bool adt_MCLQ::prepareLoadedData()
return true;
}
bool adt_MFBO::prepareLoadedData()
{
return fcc == MFBOMagic.fcc;
}

View File

@@ -248,6 +248,27 @@ public:
};
// Adt file min/max height chunk
//
class adt_MFBO
{
union
{
uint32 fcc;
char fcc_txt[4];
};
public:
uint32 size;
struct plane
{
int16 coords[9];
};
plane max;
plane min;
bool prepareLoadedData();
};
//
// Adt file header chunk
//
@@ -260,12 +281,12 @@ class adt_MHDR
public:
uint32 size;
uint32 pad;
uint32 flags;
uint32 offsMCIN; // MCIN
uint32 offsTex; // MTEX
uint32 offsModels; // MMDX
uint32 offsModelsIds; // MMID
uint32 offsMapObejcts; // MWMO
uint32 offsTex; // MTEX
uint32 offsModels; // MMDX
uint32 offsModelsIds; // MMID
uint32 offsMapObejcts; // MWMO
uint32 offsMapObejctsIds; // MWID
uint32 offsDoodsDef; // MDDF
uint32 offsObjectsDef; // MODF
@@ -278,9 +299,22 @@ public:
uint32 data5;
public:
bool prepareLoadedData();
adt_MCIN *getMCIN(){ return (adt_MCIN *)((uint8 *)&pad+offsMCIN);}
adt_MH2O *getMH2O(){ return offsMH2O ? (adt_MH2O *)((uint8 *)&pad+offsMH2O) : 0;}
adt_MCIN* getMCIN()
{
return reinterpret_cast<adt_MCIN*>(reinterpret_cast<uint8*>(&flags) + offsMCIN);
}
adt_MH2O* getMH2O()
{
if (offsMH2O)
return reinterpret_cast<adt_MH2O*>(reinterpret_cast<uint8*>(&flags) + offsMH2O);
return nullptr;
}
adt_MFBO* getMFBO()
{
if (flags & 1 && offsMFBO)
return reinterpret_cast<adt_MFBO*>(reinterpret_cast<uint8*>(&flags) + offsMFBO);
return nullptr;
}
};
class ADT_file : public FileLoader{

View File

@@ -26,14 +26,14 @@ FileLoader::~FileLoader()
free();
}
bool FileLoader::loadFile(char *filename, bool log)
bool FileLoader::loadFile(std::string const& fileName, bool log)
{
free();
MPQFile mf(filename);
MPQFile mf(fileName.c_str());
if(mf.isEof())
{
if (log)
printf("No such file %s\n", filename);
printf("No such file %s\n", fileName.c_str());
return false;
}
@@ -45,7 +45,7 @@ bool FileLoader::loadFile(char *filename, bool log)
if (prepareLoadedData())
return true;
printf("Error loading %s", filename);
printf("Error loading %s", fileName.c_str());
mf.close();
free();
return false;

View File

@@ -7,6 +7,8 @@
#ifndef LOAD_LIB_H
#define LOAD_LIB_H
#include <string>
#ifdef _WIN32
typedef __int64 int64;
typedef __int32 int32;
@@ -65,7 +67,7 @@ public:
file_MVER *version;
FileLoader();
~FileLoader();
bool loadFile(char *filename, bool log = true);
bool loadFile(std::string const& filename, bool log = true);
virtual void free();
};
#endif

View File

@@ -341,7 +341,7 @@ public:
};
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 3
#define MMAP_VERSION 6
struct MmapTileHeader
{

View File

@@ -24,7 +24,7 @@ namespace DisableMgr
}
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 3
#define MMAP_VERSION 6
struct MmapTileHeader
{
@@ -32,12 +32,22 @@ struct MmapTileHeader
uint32 dtVersion;
uint32 mmapVersion;
uint32 size;
bool usesLiquids : 1;
char usesLiquids;
char padding[3];
MmapTileHeader() : mmapMagic(MMAP_MAGIC), dtVersion(DT_NAVMESH_VERSION),
mmapVersion(MMAP_VERSION), size(0), usesLiquids(true) {}
mmapVersion(MMAP_VERSION), size(0), usesLiquids(true), padding() {}
};
// All padding fields must be handled and initialized to ensure mmaps_generator will produce binary-identical *.mmtile files
static_assert(sizeof(MmapTileHeader) == 20, "MmapTileHeader size is not correct, adjust the padding field size");
static_assert(sizeof(MmapTileHeader) == (sizeof(MmapTileHeader::mmapMagic) +
sizeof(MmapTileHeader::dtVersion) +
sizeof(MmapTileHeader::mmapVersion) +
sizeof(MmapTileHeader::size) +
sizeof(MmapTileHeader::usesLiquids) +
sizeof(MmapTileHeader::padding)), "MmapTileHeader has uninitialized padding fields");
namespace MMAP
{
MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid,
@@ -57,6 +67,10 @@ namespace MMAP
m_rcContext = new rcContext(false);
// percentageDone - Initializing
m_totalTiles = 0;
m_totalTilesBuilt = 0;
discoverTiles();
}
@@ -65,8 +79,8 @@ namespace MMAP
{
for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
{
(*it).second->clear();
delete (*it).second;
(*it).m_tiles->clear();
delete (*it).m_tiles;
}
delete m_terrainBuilder;
@@ -85,9 +99,9 @@ namespace MMAP
for (uint32 i = 0; i < files.size(); ++i)
{
mapID = uint32(atoi(files[i].substr(0,3).c_str()));
if (m_tiles.find(mapID) == m_tiles.end())
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
{
m_tiles.insert(std::pair<uint32, std::set<uint32>*>(mapID, new std::set<uint32>));
m_tiles.emplace_back(MapTiles(mapID, new std::set<uint32>));
count++;
}
}
@@ -97,8 +111,11 @@ namespace MMAP
for (uint32 i = 0; i < files.size(); ++i)
{
mapID = uint32(atoi(files[i].substr(0,3).c_str()));
m_tiles.insert(std::pair<uint32, std::set<uint32>*>(mapID, new std::set<uint32>));
count++;
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
{
m_tiles.emplace_back(MapTiles(mapID, new std::set<uint32>));
count++;
}
}
printf("found %u.\n", count);
@@ -106,8 +123,8 @@ namespace MMAP
printf("Discovering tiles... ");
for (TileList::iterator itr = m_tiles.begin(); itr != m_tiles.end(); ++itr)
{
std::set<uint32>* tiles = (*itr).second;
mapID = (*itr).first;
std::set<uint32>* tiles = (*itr).m_tiles;
mapID = (*itr).m_mapId;
sprintf(filter, "%03u*.vmtile", mapID);
files.clear();
@@ -136,17 +153,20 @@ namespace MMAP
}
}
printf("found %u.\n\n", count);
// percentageDone - total tiles to process
m_totalTiles = count;
}
/**************************************************************************/
std::set<uint32>* MapBuilder::getTileList(uint32 mapID)
{
TileList::iterator itr = m_tiles.find(mapID);
TileList::iterator itr = std::find(m_tiles.begin(), m_tiles.end(), mapID);
if (itr != m_tiles.end())
return (*itr).second;
return (*itr).m_tiles;
std::set<uint32>* tiles = new std::set<uint32>();
m_tiles.insert(std::pair<uint32, std::set<uint32>*>(mapID, tiles));
m_tiles.emplace_back(MapTiles(mapID, tiles));
return tiles;
}
@@ -157,9 +177,14 @@ namespace MMAP
BuilderThreadPool* pool = threads > 0 ? new BuilderThreadPool() : NULL;
m_tiles.sort([](MapTiles a, MapTiles b)
{
return a.m_tiles->size() > b.m_tiles->size();
});
for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
{
uint32 mapID = it->first;
uint32 mapID = it->m_mapId;
if (!shouldSkipMap(mapID))
{
if (threads > 0)
@@ -382,7 +407,8 @@ namespace MMAP
/**************************************************************************/
void MapBuilder::buildTile(uint32 mapID, uint32 tileX, uint32 tileY, dtNavMesh* navMesh)
{
printf("[Map %03i] Building tile [%02u,%02u]\n", mapID, tileX, tileY);
// percentageDone - added, now it will show addional reference percentage done of the overall process
printf("%u%% [Map %03i] Building tile [%02u,%02u]\n", percentageDone(m_totalTiles, m_totalTilesBuilt), mapID, tileX, tileY);
MeshData meshData;
@@ -416,6 +442,9 @@ namespace MMAP
// build navmesh tile
buildMoveMapTile(mapID, tileX, tileY, meshData, bmin, bmax, navMesh);
// percentageDone - increment tiles built
m_totalTilesBuilt++;
}
/**************************************************************************/
@@ -970,5 +999,13 @@ namespace MMAP
return true;
}
/**************************************************************************/
uint32 MapBuilder::percentageDone(uint32 totalTiles, uint32 totalTilesBuilt)
{
if (totalTiles)
return totalTilesBuilt * 100 / totalTiles;
return 0;
}
}

View File

@@ -9,7 +9,9 @@
#include <vector>
#include <set>
#include <atomic>
#include <map>
#include <list>
#include "TerrainBuilder.h"
#include "IntermediateValues.h"
@@ -27,7 +29,24 @@ using namespace VMAP;
namespace MMAP
{
typedef std::map<uint32, std::set<uint32>*> TileList;
struct MapTiles
{
MapTiles() : m_mapId(uint32(-1)), m_tiles(NULL) {}
MapTiles(uint32 id, std::set<uint32>* tiles) : m_mapId(id), m_tiles(tiles) {}
~MapTiles() {}
uint32 m_mapId;
std::set<uint32>* m_tiles;
bool operator==(uint32 id)
{
return m_mapId == id;
}
};
typedef std::list<MapTiles> TileList;
struct Tile
{
Tile() : chf(NULL), solid(NULL), cset(NULL), pmesh(NULL), dmesh(NULL) {}
@@ -96,6 +115,8 @@ namespace MMAP
bool shouldSkipMap(uint32 mapID);
bool isTransportMap(uint32 mapID);
bool shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY);
// percentageDone - method to calculate percentage
uint32 percentageDone(uint32 totalTiles, uint32 totalTilesDone);
TerrainBuilder* m_terrainBuilder;
TileList m_tiles;
@@ -109,6 +130,9 @@ namespace MMAP
float m_maxWalkableAngle;
bool m_bigBaseUnit;
// percentageDone - variables to calculate percentage
uint32 m_totalTiles;
std::atomic<uint32> m_totalTilesBuilt;
// build performance - not really used for now
rcContext* m_rcContext;

View File

@@ -9,9 +9,8 @@
#include <string>
#include <vector>
#include <ace/OS_NS_sys_time.h>
#include "Define.h"
#include "Common.h"
#ifndef _WIN32
#include <stddef.h>
@@ -125,26 +124,6 @@ namespace MMAP
return LISTFILE_OK;
}
inline uint32 getMSTime()
{
static const ACE_Time_Value ApplicationStartTime = ACE_OS::gettimeofday();
return (ACE_OS::gettimeofday() - ApplicationStartTime).msec();
}
inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
{
// getMSTime() have limited data range and this is case when it overflow in this tick
if (oldMSTime > newMSTime)
return (0xFFFFFFFF - oldMSTime) + newMSTime;
else
return newMSTime - oldMSTime;
}
inline uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
{
return getMSTimeDiff(oldMSTime, getMSTime());
}
}
#endif

View File

@@ -6,6 +6,7 @@
#include "PathCommon.h"
#include "MapBuilder.h"
#include "Timer.h"
using namespace MMAP;

View File

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

View File

@@ -7,6 +7,8 @@
#ifndef LOAD_LIB_H
#define LOAD_LIB_H
#include <string>
#ifdef WIN32
typedef __int64 int64;
typedef __int32 int32;
@@ -59,7 +61,7 @@ public:
file_MVER *version;
FileLoader();
~FileLoader();
bool loadFile(char *filename, bool log = true);
bool loadFile(std::string const& filename, bool log = true);
virtual void free();
};
#endif

View File

@@ -84,17 +84,31 @@ bool Model::ConvertToVMAPModel(const char * outfilename)
wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes;
fwrite(&wsize, sizeof(int), 1, output);
fwrite(&nIndexes, sizeof(uint32), 1, output);
if (nIndexes >0)
if (nIndexes > 0)
{
for (uint32 i = 0; i < nIndexes; ++i)
{
if ((i % 3) - 1 == 0 && i + 1 < nIndexes)
{
uint16 tmp = indices[i];
indices[i] = indices[i + 1];
indices[i + 1] = tmp;
}
}
fwrite(indices, sizeof(unsigned short), nIndexes, output);
}
fwrite("VERT", 4, 1, output);
wsize = sizeof(int) + sizeof(float) * 3 * nVertices;
fwrite(&wsize, sizeof(int), 1, output);
fwrite(&nVertices, sizeof(int), 1, output);
if (nVertices >0)
{
for(uint32 vpos=0; vpos <nVertices; ++vpos)
std::swap(vertices[vpos].y, vertices[vpos].z);
for (uint32 vpos = 0; vpos < nVertices; ++vpos)
{
float tmp = vertices[vpos].y;
vertices[vpos].y = -vertices[vpos].z;
vertices[vpos].z = tmp;
}
fwrite(vertices, sizeof(float)*3, nVertices, output);
}
@@ -169,7 +183,6 @@ ModelInstance::ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID
int realy1 = (int) ((float) pos.z / 533.333333f);
int realx2 = (int) ((float) pos.x / 533.333333f);
int realy2 = (int) ((float) pos.z / 533.333333f);
fprintf(pDirfile,"%s/%s %f,%f,%f_%f,%f,%f %f %d %d %d,%d %d\n",
MapName,
ModelInstName,