mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2024-12-29 12:20:41 +01:00
Switch again to using river direction and flux instead of table of bounds
This commit is contained in:
parent
6af6795d90
commit
206c68813e
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,5 +6,6 @@ offset_x
|
|||||||
offset_y
|
offset_y
|
||||||
bounds_x
|
bounds_x
|
||||||
bounds_y
|
bounds_y
|
||||||
|
dirs
|
||||||
rivers
|
rivers
|
||||||
unused/
|
unused/
|
||||||
|
48
polygons.lua
48
polygons.lua
@ -27,10 +27,10 @@ copy_if_needed('dem')
|
|||||||
local dem = load_map('dem', 2, true, X*Z)
|
local dem = load_map('dem', 2, true, X*Z)
|
||||||
copy_if_needed('lakes')
|
copy_if_needed('lakes')
|
||||||
local lakes = load_map('lakes', 2, true, X*Z)
|
local lakes = load_map('lakes', 2, true, X*Z)
|
||||||
copy_if_needed('bounds_x')
|
copy_if_needed('dirs')
|
||||||
local bounds_x = load_map('bounds_x', 4, false, (X-1)*Z)
|
local dirs = load_map('dirs', 1, false, X*Z)
|
||||||
copy_if_needed('bounds_y')
|
copy_if_needed('rivers')
|
||||||
local bounds_z = load_map('bounds_y', 4, false, X*(Z-1))
|
local rivers = load_map('rivers', 4, false, X*Z)
|
||||||
|
|
||||||
copy_if_needed('offset_x')
|
copy_if_needed('offset_x')
|
||||||
local offset_x = load_map('offset_x', 1, true, X*Z)
|
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])
|
polygon.lake = math.min(lakes[iA], lakes[iB], lakes[iC], lakes[iD])
|
||||||
|
|
||||||
-- Now, rivers.
|
-- Now, rivers.
|
||||||
-- Start by finding the river width (if any) for the polygon's 4 edges.
|
-- Load river flux values for the 4 corners
|
||||||
local river_west = river_width(bounds_z[iA])
|
local riverA = river_width(rivers[iA])
|
||||||
local river_north = river_width(bounds_x[iA-zp])
|
local riverB = river_width(rivers[iB])
|
||||||
local river_east = 1-river_width(bounds_z[iB])
|
local riverC = river_width(rivers[iC])
|
||||||
local river_south = 1-river_width(bounds_x[iD-zp-1])
|
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)
|
-- Only if opposite rivers overlap (should be rare)
|
||||||
if river_west > river_east then
|
if river_west > river_east then
|
||||||
local mean = (river_west + river_east) / 2
|
local mean = (river_west + river_east) / 2
|
||||||
@ -155,26 +165,6 @@ local function make_polygons(minp, maxp)
|
|||||||
river_south = mean
|
river_south = mean
|
||||||
end
|
end
|
||||||
polygon.rivers = {river_west, river_north, river_east, river_south}
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,20 +71,19 @@ print('Done')
|
|||||||
|
|
||||||
# Twist the grid
|
# Twist the grid
|
||||||
bx, by = bounds.make_bounds(model.dirs, model.rivers)
|
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
|
# Convert offset in 8-bits
|
||||||
offset_x = np.clip(np.floor(ox * 256), -128, 127)
|
offset_x = np.clip(np.floor(offset_x * 256), -128, 127)
|
||||||
offset_y = np.clip(np.floor(oy * 256), -128, 127)
|
offset_y = np.clip(np.floor(offset_y * 256), -128, 127)
|
||||||
|
|
||||||
# Save the files
|
# Save the files
|
||||||
save(model.dem, 'dem', dtype='>i2')
|
save(model.dem, 'dem', dtype='>i2')
|
||||||
save(model.lakes, 'lakes', 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_x, 'offset_x', dtype='i1')
|
||||||
save(offset_y, 'offset_y', dtype='i1')
|
save(offset_y, 'offset_y', dtype='i1')
|
||||||
|
|
||||||
|
save(model.dirs, 'dirs', dtype='u1')
|
||||||
save(model.rivers, 'rivers', dtype='>u4')
|
save(model.rivers, 'rivers', dtype='>u4')
|
||||||
|
|
||||||
with open('size', 'w') as sfile:
|
with open('size', 'w') as sfile:
|
||||||
|
Loading…
Reference in New Issue
Block a user