Skip to content

Commit 1277997

Browse files
authored
[Core] Open mmtiles with the axes the baker named them by (#311)
Recast X is world Y, so the navmesh baker writes a tile at grid (gx, gy) as navTileX = gy, navTileY = gx. NavMeshBuilder.hpp states the contract outright: "the runtime opens mmaps/%04u%02i%02i.mmtile with (mapId, y, x); see MMapManager::loadMap". loadMap passes (x, y) straight through, so every off-diagonal tile is looked up transposed and fails to open -- only the gx == gy diagonal loads. Stormwind is ADT Azeroth_30_48: the baker emits 00003048.mmtile and loadMap asks for 00004830.mmtile. mangoszero, mangosone and mangostwo all carry this swap in loadMap; mangosthree and mangosfour are the two that do not. This adds it here, matching mangostwo's naming and its convention of using the swapped pair only for messages that name the file -- the already-loaded warning keeps the grid position, which is what it is reporting. Also of note: the .mmap GM command in this tree already prints the swapped order, so the loader was the only place still disagreeing.
1 parent 6ef0236 commit 1277997

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/game/WorldHandlers/MoveMap.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,13 @@ namespace MMAP
323323
return false;
324324
}
325325

326+
/// Recast X is world Y, so the baker names a tile with the axes swapped
327+
/// relative to the grid position. See NavMeshBuilder.hpp.
328+
const int32 filenameTileX = y;
329+
const int32 filenameTileY = x;
330+
326331
// load this tile :: mmaps/MMMMXXYY.mmtile
327-
const std::string fileName = MMapTileFileName(mapId, x, y);
332+
const std::string fileName = MMapTileFileName(mapId, filenameTileX, filenameTileY);
328333

329334
FILE* file = fopen(fileName.c_str(), "rb");
330335
if (!file)
@@ -339,15 +344,15 @@ namespace MMAP
339344

340345
if (fileHeader.mmapMagic != MMAP_MAGIC)
341346
{
342-
sLog.outError("MMAP:loadMap: Bad header in mmap %04u%02i%02i.mmtile", mapId, x, y);
347+
sLog.outError("MMAP:loadMap: Bad header in mmap %04u%02i%02i.mmtile", mapId, filenameTileX, filenameTileY);
343348
fclose(file);
344349
return false;
345350
}
346351

347352
if (fileHeader.mmapVersion != MMAP_VERSION)
348353
{
349354
sLog.outError("MMAP:loadMap: %04u%02i%02i.mmtile was built with generator v%i, expected v%i",
350-
mapId, x, y, fileHeader.mmapVersion, MMAP_VERSION);
355+
mapId, filenameTileX, filenameTileY, fileHeader.mmapVersion, MMAP_VERSION);
351356
fclose(file);
352357
return false;
353358
}
@@ -358,7 +363,7 @@ namespace MMAP
358363
size_t result = fread(data, fileHeader.size, 1, file);
359364
if (!result)
360365
{
361-
sLog.outError("MMAP:loadMap: Bad header or data in mmap %04u%02i%02i.mmtile", mapId, x, y);
366+
sLog.outError("MMAP:loadMap: Bad header or data in mmap %04u%02i%02i.mmtile", mapId, filenameTileX, filenameTileY);
362367
fclose(file);
363368
return false;
364369
}
@@ -371,7 +376,7 @@ namespace MMAP
371376
// memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
372377
if (mmap->navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef) != DT_SUCCESS)
373378
{
374-
sLog.outError("MMAP:loadMap: Could not load %04u%02i%02i.mmtile into navmesh", mapId, x, y);
379+
sLog.outError("MMAP:loadMap: Could not load %04u%02i%02i.mmtile into navmesh", mapId, filenameTileX, filenameTileY);
375380
dtFree(data);
376381
return false;
377382
}

0 commit comments

Comments
 (0)