fix(editor): recompute chunk positions after ADT coord override

When loading ADT tiles, the editor overrides terrain_.coord with the
filename-derived tile coordinates (instanced maps have arbitrary
internal values). But it wasn't recomputing the per-chunk world
positions to match, causing terrain to render at wrong coordinates.

Now recalculates all 256 chunk positions from the corrected tile
coordinates using the standard WoW formula:
  chunkX = (32 - tileX) * 533.33 - cx * 33.33
  chunkY = (32 - tileY) * 533.33 - cy * 33.33

This fixes terrain appearing at the wrong location in the editor
when loading instanced maps or tiles with mismatched internal coords.
This commit is contained in:
Kelsi 2026-05-05 22:05:43 -07:00
parent 9d14bc19cb
commit d84ad82e26

View file

@ -702,6 +702,19 @@ void EditorApp::loadADT(const std::string& mapName, int tileX, int tileY) {
// (instanced maps have arbitrary internal coord values)
terrain_.coord = {tileX, tileY};
// Recompute chunk world positions from tile coordinates
// This fixes instanced maps where internal MCNK positions are wrong
float tileSize = 533.33333f;
float chunkSize = tileSize / 16.0f;
for (int cy = 0; cy < 16; cy++) {
for (int cx = 0; cx < 16; cx++) {
auto& chunk = terrain_.chunks[cy * 16 + cx];
if (!chunk.hasHeightMap()) continue;
chunk.position[0] = (32.0f - static_cast<float>(tileX)) * tileSize - cx * chunkSize;
chunk.position[1] = (32.0f - static_cast<float>(tileY)) * tileSize - cy * chunkSize;
}
}
terrainEditor_.setTerrain(&terrain_);
terrainEditor_.history().clear();
texturePainter_.setTerrain(&terrain_);