mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2025-02-22 06:50:29 +01:00
Flow accumulation: minor fix and simplification
This commit is contained in:
parent
f350f8785c
commit
72e2f3e670
@ -447,31 +447,25 @@ local function accumulate(dirs, waterq)
|
|||||||
-- This means: how many nodes will give their water to that given node, directly or indirectly?
|
-- This means: how many nodes will give their water to that given node, directly or indirectly?
|
||||||
-- This is obtained by following rivers downstream and summing up the flow of every tributary, starting with a value of 1 at the sources.
|
-- This is obtained by following rivers downstream and summing up the flow of every tributary, starting with a value of 1 at the sources.
|
||||||
-- This will give non-zero values for every node but only large values will be considered to be rivers.
|
-- This will give non-zero values for every node but only large values will be considered to be rivers.
|
||||||
waterq = waterq or {}
|
|
||||||
local X, Y = dirs.X, dirs.Y
|
local X, Y = dirs.X, dirs.Y
|
||||||
|
waterq = waterq or {X=X, Y=Y}
|
||||||
|
|
||||||
local ndonors = {}
|
local ndonors = {}
|
||||||
local waterq = {X=X, Y=Y}
|
|
||||||
for i=1, X*Y do
|
for i=1, X*Y do
|
||||||
ndonors[i] = 0
|
ndonors[i] = 0
|
||||||
waterq[i] = 1
|
waterq[i] = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Calculate the number of direct donors
|
-- Calculate the number of direct donors
|
||||||
for i1=1, X*Y do
|
for i=1, X*Y do
|
||||||
local i2
|
if dirs[i] == 1 then
|
||||||
local dir = dirs[i1]
|
ndonors[i+X] = ndonors[i+X] + 1
|
||||||
if dir == 1 then
|
elseif dirs[i] == 2 then
|
||||||
i2 = i1+X
|
ndonors[i+1] = ndonors[i+1] + 1
|
||||||
elseif dir == 2 then
|
elseif dirs[i] == 3 then
|
||||||
i2 = i1+1
|
ndonors[i-X] = ndonors[i-X] + 1
|
||||||
elseif dir == 3 then
|
elseif dirs[i] == 4 then
|
||||||
i2 = i1-X
|
ndonors[i-1] = ndonors[i-1] + 1
|
||||||
elseif dir == 4 then
|
|
||||||
i2 = i1-1
|
|
||||||
end
|
|
||||||
if i2 then
|
|
||||||
ndonors[i2] = ndonors[i2] + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user