From d84ad82e2624cec63d2da177da81ec20072ec667 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 5 May 2026 22:05:43 -0700 Subject: [PATCH] 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. --- tools/editor/editor_app.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/editor/editor_app.cpp b/tools/editor/editor_app.cpp index f124e165..138e1770 100644 --- a/tools/editor/editor_app.cpp +++ b/tools/editor/editor_app.cpp @@ -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(tileX)) * tileSize - cx * chunkSize; + chunk.position[1] = (32.0f - static_cast(tileY)) * tileSize - cy * chunkSize; + } + } + terrainEditor_.setTerrain(&terrain_); terrainEditor_.history().clear(); texturePainter_.setTerrain(&terrain_);