From a14fad13ed6dda49e8c5a93b08b7f9d5893b33b5 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 2 Oct 2014 17:32:45 +0000 Subject: (svn r26945) -Fix-ish: better scaling of the "cells" in which variety distribution happens for non-square maps (attempt to make reasonably square areas) --- src/tgp.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/tgp.cpp b/src/tgp.cpp index f12d15505..4a865ed55 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -511,9 +511,10 @@ static void HeightMapCurves(uint level) height_t ht[lengthof(_curve_maps)]; MemSetT(ht, 0, lengthof(ht)); - /* Set up a grid to choose curve maps based on location */ - uint sx = Clamp(1 << level, 2, 32); - uint sy = Clamp(1 << level, 2, 32); + /* Set up a grid to choose curve maps based on location; attempt to get a somewhat square grid */ + float factor = sqrt((float)_height_map.size_x / (float)_height_map.size_y); + uint sx = Clamp(round((1 << level) * factor), 1, 128); + uint sy = Clamp(round((1 << level) / factor), 1, 128); byte *c = AllocaM(byte, sx * sy); for (uint i = 0; i < sx * sy; i++) { @@ -524,7 +525,7 @@ static void HeightMapCurves(uint level) for (uint x = 0; x < _height_map.size_x; x++) { /* Get our X grid positions and bi-linear ratio */ - float fx = (float)(sx * x) / _height_map.size_x + 0.5f; + float fx = (float)(sx * x) / _height_map.size_x + 1.0f; uint x1 = (uint)fx; uint x2 = x1; float xr = 2.0f * (fx - x1) - 1.0f; @@ -541,7 +542,7 @@ static void HeightMapCurves(uint level) for (uint y = 0; y < _height_map.size_y; y++) { /* Get our Y grid position and bi-linear ratio */ - float fy = (float)(sy * y) / _height_map.size_y + 0.5f; + float fy = (float)(sy * y) / _height_map.size_y + 1.0f; uint y1 = (uint)fy; uint y2 = y1; float yr = 2.0f * (fy - y1) - 1.0f; -- cgit v1.2.3-70-g09d2