mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Maps: Added optional *.tilelist file to map_extractor output which contains a list of existing tiles to speed up map creation in worldserver
This commit is contained in:
@@ -92,6 +92,29 @@ Map::~Map()
|
||||
|
||||
void Map::DiscoverGridMapFiles()
|
||||
{
|
||||
std::string tileListName = Trinity::StringFormat("%smaps/%04u.tilelist", sWorld->GetDataPath().c_str(), GetId());
|
||||
// tile list is optional
|
||||
if (FILE* tileList = fopen(tileListName.c_str(), "rb"))
|
||||
{
|
||||
u_map_magic mapMagic;
|
||||
u_map_magic versionMagic;
|
||||
uint32 build;
|
||||
char tilesData[MAX_NUMBER_OF_GRIDS * MAX_NUMBER_OF_GRIDS];
|
||||
if (fread(&mapMagic.asUInt, sizeof(u_map_magic), 1, tileList) == 1
|
||||
&& mapMagic.asUInt == MapMagic.asUInt
|
||||
&& fread(&versionMagic.asUInt, sizeof(u_map_magic), 1, tileList) == 1
|
||||
&& versionMagic.asUInt == MapVersionMagic.asUInt
|
||||
&& fread(&build, sizeof(build), 1, tileList) == 1
|
||||
&& fread(&tilesData[0], MAX_NUMBER_OF_GRIDS * MAX_NUMBER_OF_GRIDS, 1, tileList) == 1)
|
||||
{
|
||||
i_gridFileExists = std::bitset<MAX_NUMBER_OF_GRIDS * MAX_NUMBER_OF_GRIDS>(tilesData, Trinity::Containers::Size(tilesData));
|
||||
fclose(tileList);
|
||||
return;
|
||||
}
|
||||
|
||||
fclose(tileList);
|
||||
}
|
||||
|
||||
for (uint32 gx = 0; gx < MAX_NUMBER_OF_GRIDS; ++gx)
|
||||
for (uint32 gy = 0; gy < MAX_NUMBER_OF_GRIDS; ++gy)
|
||||
i_gridFileExists[gx * MAX_NUMBER_OF_GRIDS + gy] = ExistMap(GetId(), gx, gy, false);
|
||||
|
||||
@@ -91,7 +91,7 @@ struct map_fileheader
|
||||
{
|
||||
u_map_magic mapMagic;
|
||||
u_map_magic versionMagic;
|
||||
u_map_magic buildMagic;
|
||||
uint32 buildMagic;
|
||||
uint32 areaMapOffset;
|
||||
uint32 areaMapSize;
|
||||
uint32 heightMapOffset;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <CascLib.h>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <bitset>
|
||||
#include <cstdio>
|
||||
#include <deque>
|
||||
#include <fstream>
|
||||
@@ -1121,34 +1122,44 @@ void ExtractMaps(uint32 build)
|
||||
printf("Extract %s (" SZFMTD "/" SZFMTD ") \n", map_ids[z].Name.c_str(), z + 1, map_ids.size());
|
||||
// Loadup map grid data
|
||||
ChunkedFile wdt;
|
||||
if (!wdt.loadFile(CascStorage, map_ids[z].WdtFileDataId, Trinity::StringFormat("WDT for map %u", map_ids[z].Id), false))
|
||||
continue;
|
||||
|
||||
FileChunk* mphd = wdt.GetChunk("MPHD");
|
||||
FileChunk* main = wdt.GetChunk("MAIN");
|
||||
FileChunk* maid = wdt.GetChunk("MAID");
|
||||
for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
|
||||
std::bitset<(WDT_MAP_SIZE) * (WDT_MAP_SIZE)> existingTiles;
|
||||
if (wdt.loadFile(CascStorage, map_ids[z].WdtFileDataId, Trinity::StringFormat("WDT for map %u", map_ids[z].Id), false))
|
||||
{
|
||||
for (uint32 x = 0; x < WDT_MAP_SIZE; ++x)
|
||||
FileChunk* mphd = wdt.GetChunk("MPHD");
|
||||
FileChunk* main = wdt.GetChunk("MAIN");
|
||||
FileChunk* maid = wdt.GetChunk("MAID");
|
||||
for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
|
||||
{
|
||||
if (!(main->As<wdt_MAIN>()->adt_list[y][x].flag & 0x1))
|
||||
continue;
|
||||
for (uint32 x = 0; x < WDT_MAP_SIZE; ++x)
|
||||
{
|
||||
if (!(main->As<wdt_MAIN>()->adt_list[y][x].flag & 0x1))
|
||||
continue;
|
||||
|
||||
outputFileName = Trinity::StringFormat("%s/maps/%04u_%02u_%02u.map", output_path.string().c_str(), map_ids[z].Id, y, x);
|
||||
bool ignoreDeepWater = IsDeepWaterIgnored(map_ids[z].Id, y, x);
|
||||
if (mphd && mphd->As<wdt_MPHD>()->flags & 0x200)
|
||||
{
|
||||
ConvertADT(maid->As<wdt_MAID>()->adt_files[y][x].rootADT, map_ids[z].Name, outputFileName, y, x, build, ignoreDeepWater);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string storagePath = Trinity::StringFormat("World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].Directory.c_str(), map_ids[z].Directory.c_str(), x, y);
|
||||
ConvertADT(storagePath, map_ids[z].Name, outputFileName, y, x, build, ignoreDeepWater);
|
||||
outputFileName = Trinity::StringFormat("%s/maps/%04u_%02u_%02u.map", output_path.string().c_str(), map_ids[z].Id, y, x);
|
||||
bool ignoreDeepWater = IsDeepWaterIgnored(map_ids[z].Id, y, x);
|
||||
if (mphd && mphd->As<wdt_MPHD>()->flags & 0x200)
|
||||
{
|
||||
existingTiles[y * WDT_MAP_SIZE + x] = ConvertADT(maid->As<wdt_MAID>()->adt_files[y][x].rootADT, map_ids[z].Name, outputFileName, y, x, build, ignoreDeepWater);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string storagePath = Trinity::StringFormat(R"(World\Maps\%s\%s_%u_%u.adt)", map_ids[z].Directory.c_str(), map_ids[z].Directory.c_str(), x, y);
|
||||
existingTiles[y * WDT_MAP_SIZE + x] = ConvertADT(storagePath, map_ids[z].Name, outputFileName, y, x, build, ignoreDeepWater);
|
||||
}
|
||||
}
|
||||
|
||||
// draw progress bar
|
||||
printf("Processing........................%d%%\r", (100 * (y + 1)) / WDT_MAP_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
// draw progress bar
|
||||
printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE);
|
||||
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(&build, sizeof(build), 1, tileList);
|
||||
fwrite(existingTiles.to_string().c_str(), 1, existingTiles.size(), tileList);
|
||||
fclose(tileList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user