mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-01-01 14:00:36 +01:00
Pre-generation: reverse X and Y directions everywhere
to make directions compatible with the mapgen code
This commit is contained in:
parent
74733549df
commit
b02387944d
@ -51,12 +51,9 @@ local function generate()
|
|||||||
local mfloor = math.floor
|
local mfloor = math.floor
|
||||||
local mmin, mmax = math.min, math.max
|
local mmin, mmax = math.min, math.max
|
||||||
local offset_x, offset_y = twist(model.dirs, model.rivers, 5)
|
local offset_x, offset_y = twist(model.dirs, model.rivers, 5)
|
||||||
local dirs = model.dirs
|
|
||||||
local converter = {2, 1, 4, 3, [0]=0}
|
|
||||||
for i=1, size.x*size.y do
|
for i=1, size.x*size.y do
|
||||||
offset_x[i] = mmin(mmax(offset_x[i]*256, -128), 127)
|
offset_x[i] = mmin(mmax(offset_x[i]*256, -128), 127)
|
||||||
offset_y[i] = mmin(mmax(offset_y[i]*256, -128), 127)
|
offset_y[i] = mmin(mmax(offset_y[i]*256, -128), 127)
|
||||||
dirs[i] = converter[dirs[i]] -- TODO Fix this
|
|
||||||
end
|
end
|
||||||
|
|
||||||
mapgen_rivers.write_map('dem', model.dem, 2)
|
mapgen_rivers.write_map('dem', model.dem, 2)
|
||||||
|
@ -46,13 +46,13 @@ local function erode(model, time)
|
|||||||
new_elev = lakes[iw]
|
new_elev = lakes[iw]
|
||||||
break
|
break
|
||||||
elseif d == 1 then
|
elseif d == 1 then
|
||||||
inext = iw+1
|
|
||||||
elseif d == 2 then
|
|
||||||
inext = iw+X
|
inext = iw+X
|
||||||
|
elseif d == 2 then
|
||||||
|
inext = iw+1
|
||||||
elseif d == 3 then
|
elseif d == 3 then
|
||||||
inext = iw-1
|
|
||||||
elseif d == 4 then
|
|
||||||
inext = iw-X
|
inext = iw-X
|
||||||
|
elseif d == 4 then
|
||||||
|
inext = iw-1
|
||||||
end
|
end
|
||||||
|
|
||||||
local etime = erosion_time[iw]
|
local etime = erosion_time[iw]
|
||||||
|
@ -56,10 +56,10 @@ local function flow_routing(dem, dirs, lakes, method)
|
|||||||
for x=1, X do
|
for x=1, X do
|
||||||
local zi = dem[i]
|
local zi = dem[i]
|
||||||
local plist = {
|
local plist = {
|
||||||
x<X and mmax(zi-dem[i+1], 0) or 0, -- Eastward
|
|
||||||
y<Y and mmax(zi-dem[i+X], 0) or 0, -- Southward
|
y<Y and mmax(zi-dem[i+X], 0) or 0, -- Southward
|
||||||
x>1 and mmax(zi-dem[i-1], 0) or 0, -- Westward
|
x<X and mmax(zi-dem[i+1], 0) or 0, -- Eastward
|
||||||
y>1 and mmax(zi-dem[i-X], 0) or 0, -- Northward
|
y>1 and mmax(zi-dem[i-X], 0) or 0, -- Northward
|
||||||
|
x>1 and mmax(zi-dem[i-1], 0) or 0, -- Westward
|
||||||
}
|
}
|
||||||
|
|
||||||
local d = flow_local(plist)
|
local d = flow_local(plist)
|
||||||
@ -67,13 +67,13 @@ local function flow_routing(dem, dirs, lakes, method)
|
|||||||
if d == 0 then
|
if d == 0 then
|
||||||
singular[#singular+1] = i
|
singular[#singular+1] = i
|
||||||
elseif d == 1 then
|
elseif d == 1 then
|
||||||
dirs2[i+1] = dirs2[i+1] + 1
|
dirs2[i+X] = dirs2[i+X] + 1
|
||||||
elseif d == 2 then
|
elseif d == 2 then
|
||||||
dirs2[i+X] = dirs2[i+X] + 2
|
dirs2[i+1] = dirs2[i+1] + 2
|
||||||
elseif d == 3 then
|
elseif d == 3 then
|
||||||
dirs2[i-1] = dirs2[i-1] + 4
|
dirs2[i-X] = dirs2[i-X] + 4
|
||||||
elseif d == 4 then
|
elseif d == 4 then
|
||||||
dirs2[i-X] = dirs2[i-X] + 8
|
dirs2[i-1] = dirs2[i-1] + 8
|
||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
@ -128,44 +128,44 @@ local function flow_routing(dem, dirs, lakes, method)
|
|||||||
basin_id[i] = ib
|
basin_id[i] = ib
|
||||||
local d = dirs2[i]
|
local d = dirs2[i]
|
||||||
|
|
||||||
if d >= 8 then -- River coming from South
|
if d >= 8 then -- River coming from East
|
||||||
d = d - 8
|
d = d - 8
|
||||||
queue[#queue+1] = i+X
|
|
||||||
--tinsert(queue, i+X)
|
|
||||||
elseif i <= X*(Y-1) then
|
|
||||||
add_link(i, i+X, ib, true)
|
|
||||||
else
|
|
||||||
add_link(i, 0, ib, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
if d >= 4 then -- River coming from East
|
|
||||||
d = d - 4
|
|
||||||
queue[#queue+1] = i+1
|
queue[#queue+1] = i+1
|
||||||
--tinsert(queue, i+1)
|
--tinsert(queue, i+X)
|
||||||
elseif i%X > 0 then
|
elseif i%X > 0 then
|
||||||
add_link(i, i+1, ib, false)
|
add_link(i, i+1, ib, false)
|
||||||
else
|
else
|
||||||
add_link(i, 0, ib, false)
|
add_link(i, 0, ib, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
if d >= 2 then -- River coming from North
|
if d >= 4 then -- River coming from South
|
||||||
d = d - 2
|
d = d - 4
|
||||||
queue[#queue+1] = i-X
|
queue[#queue+1] = i+X
|
||||||
--tinsert(queue, i-X)
|
--tinsert(queue, i+1)
|
||||||
elseif i > X then
|
elseif i <= X*(Y-1) then
|
||||||
add_link(i, i-X, ib, true)
|
add_link(i, i+X, ib, true)
|
||||||
else
|
else
|
||||||
add_link(i, 0, ib, true)
|
add_link(i, 0, ib, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
if d >= 1 then -- River coming from West
|
if d >= 2 then -- River coming from West
|
||||||
|
d = d - 2
|
||||||
queue[#queue+1] = i-1
|
queue[#queue+1] = i-1
|
||||||
--tinsert(queue, i-1)
|
--tinsert(queue, i-X)
|
||||||
elseif i%X ~= 1 then
|
elseif i%X ~= 1 then
|
||||||
add_link(i, i-1, ib, false)
|
add_link(i, i-1, ib, false)
|
||||||
else
|
else
|
||||||
add_link(i, 0, ib, false)
|
add_link(i, 0, ib, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if d >= 1 then -- River coming from North
|
||||||
|
queue[#queue+1] = i-X
|
||||||
|
--tinsert(queue, i-1)
|
||||||
|
elseif i > X then
|
||||||
|
add_link(i, i-X, ib, true)
|
||||||
|
else
|
||||||
|
add_link(i, 0, ib, true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
dirs2 = nil
|
dirs2 = nil
|
||||||
@ -291,7 +291,7 @@ local function flow_routing(dem, dirs, lakes, method)
|
|||||||
--print('Flow '..b2..' into '..b1)
|
--print('Flow '..b2..' into '..b1)
|
||||||
-- Make b2 flow into b1
|
-- Make b2 flow into b1
|
||||||
local i = bound.i
|
local i = bound.i
|
||||||
local dir = bound.is_y and 4 or 3
|
local dir = bound.is_y and 3 or 4
|
||||||
--print(basin_id[i])
|
--print(basin_id[i])
|
||||||
if basin_id[i] ~= b2 then
|
if basin_id[i] ~= b2 then
|
||||||
dir = dir - 2
|
dir = dir - 2
|
||||||
@ -308,13 +308,13 @@ local function flow_routing(dem, dirs, lakes, method)
|
|||||||
repeat
|
repeat
|
||||||
dir, dirs[i] = dirs[i], dir
|
dir, dirs[i] = dirs[i], dir
|
||||||
if dir == 1 then
|
if dir == 1 then
|
||||||
i = i + 1
|
|
||||||
elseif dir == 2 then
|
|
||||||
i = i + X
|
i = i + X
|
||||||
|
elseif dir == 2 then
|
||||||
|
i = i + 1
|
||||||
elseif dir == 3 then
|
elseif dir == 3 then
|
||||||
i = i - 1
|
|
||||||
elseif dir == 4 then
|
|
||||||
i = i - X
|
i = i - X
|
||||||
|
elseif dir == 4 then
|
||||||
|
i = i - 1
|
||||||
end
|
end
|
||||||
dir = reverse[dir]
|
dir = reverse[dir]
|
||||||
until dir == 0
|
until dir == 0
|
||||||
@ -349,13 +349,13 @@ local function accumulate(dirs, waterq)
|
|||||||
local i2
|
local i2
|
||||||
local dir = dirs[i1]
|
local dir = dirs[i1]
|
||||||
if dir == 1 then
|
if dir == 1 then
|
||||||
i2 = i1+1
|
|
||||||
elseif dir == 2 then
|
|
||||||
i2 = i1+X
|
i2 = i1+X
|
||||||
|
elseif dir == 2 then
|
||||||
|
i2 = i1+1
|
||||||
elseif dir == 3 then
|
elseif dir == 3 then
|
||||||
i2 = i1-1
|
|
||||||
elseif dir == 4 then
|
|
||||||
i2 = i1-X
|
i2 = i1-X
|
||||||
|
elseif dir == 4 then
|
||||||
|
i2 = i1-1
|
||||||
end
|
end
|
||||||
if i2 then
|
if i2 then
|
||||||
ndonors[i2] = ndonors[i2] + 1
|
ndonors[i2] = ndonors[i2] + 1
|
||||||
@ -371,13 +371,13 @@ local function accumulate(dirs, waterq)
|
|||||||
--print(dir)
|
--print(dir)
|
||||||
while dir > 0 do
|
while dir > 0 do
|
||||||
if dir == 1 then
|
if dir == 1 then
|
||||||
i2 = i2 + 1
|
|
||||||
elseif dir == 2 then
|
|
||||||
i2 = i2 + X
|
i2 = i2 + X
|
||||||
|
elseif dir == 2 then
|
||||||
|
i2 = i2 + 1
|
||||||
elseif dir == 3 then
|
elseif dir == 3 then
|
||||||
i2 = i2 - 1
|
|
||||||
elseif dir == 4 then
|
|
||||||
i2 = i2 - X
|
i2 = i2 - X
|
||||||
|
elseif dir == 4 then
|
||||||
|
i2 = i2 - 1
|
||||||
end
|
end
|
||||||
--print('Incrementing '..i2)
|
--print('Incrementing '..i2)
|
||||||
w = w + waterq[i2]
|
w = w + waterq[i2]
|
||||||
|
@ -12,14 +12,14 @@ local function get_bounds(dirs, rivers)
|
|||||||
for i=1, X*Y do
|
for i=1, X*Y do
|
||||||
local dir = dirs[i]
|
local dir = dirs[i]
|
||||||
local river = rivers[i]
|
local river = rivers[i]
|
||||||
if dir == 1 then -- East (+X)
|
if dir == 1 then -- South (+Y)
|
||||||
bounds_x[i] = river
|
|
||||||
elseif dir == 2 then -- South (+Y)
|
|
||||||
bounds_y[i] = river
|
bounds_y[i] = river
|
||||||
elseif dir == 3 then -- West (-X)
|
elseif dir == 2 then -- East (+X)
|
||||||
bounds_x[i-1] = river
|
bounds_x[i] = river
|
||||||
elseif dir == 4 then
|
elseif dir == 3 then -- North (-Y)
|
||||||
bounds_y[i-X] = river
|
bounds_y[i-X] = river
|
||||||
|
elseif dir == 4 then -- West (-X)
|
||||||
|
bounds_x[i-1] = river
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user