From 206c68813ea098b05a6cb04dbe259b6e78bc862a Mon Sep 17 00:00:00 2001 From: Gael-de-Sailly Date: Sun, 26 Apr 2020 18:10:23 +0200 Subject: [PATCH] Switch again to using river direction and flux instead of table of bounds --- .gitignore | 1 + polygons.lua | 48 +++++++++++++++++++---------------------------- terrain_rivers.py | 9 ++++----- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 4afef7d..62a6260 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ offset_x offset_y bounds_x bounds_y +dirs rivers unused/ diff --git a/polygons.lua b/polygons.lua index 443f3ac..4824327 100644 --- a/polygons.lua +++ b/polygons.lua @@ -27,10 +27,10 @@ copy_if_needed('dem') local dem = load_map('dem', 2, true, X*Z) copy_if_needed('lakes') local lakes = load_map('lakes', 2, true, X*Z) -copy_if_needed('bounds_x') -local bounds_x = load_map('bounds_x', 4, false, (X-1)*Z) -copy_if_needed('bounds_y') -local bounds_z = load_map('bounds_y', 4, false, X*(Z-1)) +copy_if_needed('dirs') +local dirs = load_map('dirs', 1, false, X*Z) +copy_if_needed('rivers') +local rivers = load_map('rivers', 4, false, X*Z) copy_if_needed('offset_x') local offset_x = load_map('offset_x', 1, true, X*Z) @@ -138,11 +138,21 @@ local function make_polygons(minp, maxp) polygon.lake = math.min(lakes[iA], lakes[iB], lakes[iC], lakes[iD]) -- Now, rivers. - -- Start by finding the river width (if any) for the polygon's 4 edges. - local river_west = river_width(bounds_z[iA]) - local river_north = river_width(bounds_x[iA-zp]) - local river_east = 1-river_width(bounds_z[iB]) - local river_south = 1-river_width(bounds_x[iD-zp-1]) + -- Load river flux values for the 4 corners + local riverA = river_width(rivers[iA]) + local riverB = river_width(rivers[iB]) + local riverC = river_width(rivers[iC]) + local riverD = river_width(rivers[iD]) + polygon.river_corners = {riverA, riverB, riverC, riverD} + + -- Flow directions + local dirA, dirB, dirC, dirD = dirs[iA], dirs[iB], dirs[iC], dirs[iD] + -- Determine the river flux on the edges, by testing dirs values + local river_west = (dirA==1 and riverA or 0) + (dirD==3 and riverD or 0) + local river_north = (dirA==2 and riverA or 0) + (dirB==4 and riverB or 0) + local river_east = 1 - (dirB==1 and riverB or 0) - (dirC==3 and riverC or 0) + local river_south = 1 - (dirD==2 and riverD or 0) - (dirC==4 and riverC or 0) + -- Only if opposite rivers overlap (should be rare) if river_west > river_east then local mean = (river_west + river_east) / 2 @@ -155,26 +165,6 @@ local function make_polygons(minp, maxp) river_south = mean end polygon.rivers = {river_west, river_north, river_east, river_south} - - -- Look for river corners - local around = {0,0,0,0,0,0,0,0} - if zp > 0 then - around[1] = river_width(bounds_z[iA-X]) - around[2] = river_width(bounds_z[iB-X]) - end - if xp < X-2 then - around[3] = river_width(bounds_x[iB-zp]) - around[4] = river_width(bounds_x[iC-zp-1]) - end - if zp < Z-2 then - around[5] = river_width(bounds_z[iC]) - around[6] = river_width(bounds_z[iD]) - end - if xp > 0 then - around[7] = river_width(bounds_x[iD-zp-2]) - around[8] = river_width(bounds_x[iA-zp-1]) - end - polygon.river_corners = {math.max(around[8], around[1]), math.max(around[2], around[3]), math.max(around[4], around[5]), math.max(around[6], around[7])} end end diff --git a/terrain_rivers.py b/terrain_rivers.py index 108476b..a1a9639 100755 --- a/terrain_rivers.py +++ b/terrain_rivers.py @@ -71,20 +71,19 @@ print('Done') # Twist the grid bx, by = bounds.make_bounds(model.dirs, model.rivers) -ox, oy = bounds.twist(bx, by, bounds.get_fixed(model.dirs)) +offset_x, offset_y = bounds.twist(bx, by, bounds.get_fixed(model.dirs)) # Convert offset in 8-bits -offset_x = np.clip(np.floor(ox * 256), -128, 127) -offset_y = np.clip(np.floor(oy * 256), -128, 127) +offset_x = np.clip(np.floor(offset_x * 256), -128, 127) +offset_y = np.clip(np.floor(offset_y * 256), -128, 127) # Save the files save(model.dem, 'dem', dtype='>i2') save(model.lakes, 'lakes', dtype='>i2') -save(np.abs(bx), 'bounds_x', dtype='>i4') -save(np.abs(by), 'bounds_y', dtype='>i4') save(offset_x, 'offset_x', dtype='i1') save(offset_y, 'offset_y', dtype='i1') +save(model.dirs, 'dirs', dtype='u1') save(model.rivers, 'rivers', dtype='>u4') with open('size', 'w') as sfile: