From 10e271c84ed7100cd2684456064236438cbb5925 Mon Sep 17 00:00:00 2001 From: elexis Date: Mon, 5 Feb 2018 14:08:46 +0000 Subject: [PATCH] When importing a heightmap image in atlas, don't omit the last vertex of each side of the heightmap! Fixes #5021, refs rP12308. (Since there are 4 vertices per tile, there is one more vertex per side than there are tiles / pixels per side.) git-svn-id: https://svn.wildfiregames.com/public/ps/trunk@21111 3db68df2-c116-0410-a063-a993310a9797 --- source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index 645aa359c6..6a4f1adbe2 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -216,25 +216,25 @@ MESSAGEHANDLER(ImportHeightmap) // resize terrain to heightmap size CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); terrain->Resize(terrainSize / PATCH_SIZE); + ENSURE(terrainSize + 1 == g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()); // copy heightmap data into map u16* heightmap = g_Game->GetWorld()->GetTerrain()->GetHeightMap(); - ssize_t hmSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); u8* mapdata = tex.get_data(); ssize_t bytesPP = tex.m_Bpp / 8; ssize_t mapLineSkip = tex.m_Width * bytesPP; - for (ssize_t y = 0; y < terrainSize; ++y) + for (ssize_t y = 0; y < terrainSize + 1; ++y) { - for (ssize_t x = 0; x < terrainSize; ++x) + for (ssize_t x = 0; x < terrainSize + 1; ++x) { - int offset = y * mapLineSkip + x * bytesPP; + // repeat the last pixel of the image for the last vertex of the heightmap + int offset = std::min(y, terrainSize - 1) * mapLineSkip + std::min(x, terrainSize - 1) * bytesPP; // pick color channel with highest value u16 value = std::max(mapdata[offset+bytesPP*2], std::max(mapdata[offset], mapdata[offset+bytesPP])); - - heightmap[(terrainSize-y-1) * hmSize + x] = clamp(value * 256, 0, 65535); + heightmap[(terrainSize - y) * (terrainSize + 1) + x] = clamp(value * 256, 0, 65535); } } -- 2.11.4.GIT