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:
Shauren
2020-07-06 17:45:53 +02:00
committed by Ovahlord
parent 1ce5cc7a20
commit 0f3590ebb4
3 changed files with 50 additions and 14 deletions

View File

@@ -98,6 +98,29 @@ Map::~Map()
void Map::DiscoverGridMapFiles()
{
std::string tileListName = Trinity::StringFormat("%smaps/%03u.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);

View File

@@ -89,7 +89,7 @@ struct map_fileheader
{
u_map_magic mapMagic;
u_map_magic versionMagic;
u_map_magic buildMagic;
uint32 buildMagic;
uint32 areaMapOffset;
uint32 areaMapSize;
uint32 heightMapOffset;

View File

@@ -15,8 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StringFormat.h"
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <bitset>
#include <cstdio>
#include <deque>
#include <fstream>
@@ -1122,25 +1124,36 @@ void ExtractMapsFromMpq(uint32 build)
// Loadup map grid data
sprintf(mpq_map_name, "World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
ChunkedFile wdt;
if (!wdt.loadFile(WorldMpq, mpq_map_name, false))
continue;
FileChunk* chunk = wdt.GetChunk("MAIN");
for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
std::bitset<(WDT_MAP_SIZE)* (WDT_MAP_SIZE)> existingTiles;
if (wdt.loadFile(WorldMpq, mpq_map_name, false))
{
for (uint32 x = 0; x < WDT_MAP_SIZE; ++x)
FileChunk* main = wdt.GetChunk("MAIN");
for (uint32 y = 0; y < WDT_MAP_SIZE; ++y)
{
if (!(chunk->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;
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);
bool ignoreDeepWater = IsDeepWaterIgnored(map_ids[z].id, y, x);
ConvertADT(mpq_filename, output_filename, y, x, build, ignoreDeepWater);
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);
bool ignoreDeepWater = IsDeepWaterIgnored(map_ids[z].id, y, x);
existingTiles[y * WDT_MAP_SIZE + x] = ConvertADT(mpq_filename, output_filename, 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/%03u.tilelist", output_path, 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);
}
}