mirror of
https://gitlab.com/gaelysam/mapgen_rivers.git
synced 2024-12-29 12:20:41 +01:00
Globalize some of the main functions
This will allow to avoid nested 'dofile's
This commit is contained in:
parent
b0930f4d40
commit
cd2a77803f
@ -1,6 +1,5 @@
|
|||||||
local modpath = mapgen_rivers.modpath
|
local modpath = mapgen_rivers.modpath
|
||||||
|
|
||||||
local make_polygons = dofile(modpath .. 'polygons.lua')
|
|
||||||
local transform_quadri = dofile(modpath .. 'geometry.lua')
|
local transform_quadri = dofile(modpath .. 'geometry.lua')
|
||||||
|
|
||||||
local sea_level = mapgen_rivers.settings.sea_level
|
local sea_level = mapgen_rivers.settings.sea_level
|
||||||
@ -19,9 +18,9 @@ local function interp(v00, v01, v11, v10, xf, zf)
|
|||||||
return v1*zf + v0*(1-zf)
|
return v1*zf + v0*(1-zf)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function heightmaps(minp, maxp)
|
function mapgen_rivers.make_heightmaps(minp, maxp)
|
||||||
|
|
||||||
local polygons = make_polygons(minp, maxp)
|
local polygons = mapgen_rivers.make_polygons(minp, maxp)
|
||||||
local incr = maxp.z-minp.z+1
|
local incr = maxp.z-minp.z+1
|
||||||
|
|
||||||
local terrain_height_map = {}
|
local terrain_height_map = {}
|
||||||
@ -144,5 +143,3 @@ local function heightmaps(minp, maxp)
|
|||||||
|
|
||||||
return terrain_height_map, lake_height_map
|
return terrain_height_map, lake_height_map
|
||||||
end
|
end
|
||||||
|
|
||||||
return heightmaps
|
|
||||||
|
8
init.lua
8
init.lua
@ -10,6 +10,8 @@ if minetest.get_mapgen_setting("mg_name") ~= "singlenode" then
|
|||||||
end
|
end
|
||||||
|
|
||||||
dofile(modpath .. 'settings.lua')
|
dofile(modpath .. 'settings.lua')
|
||||||
|
dofile(modpath .. 'polygons.lua')
|
||||||
|
dofile(modpath .. 'heightmap.lua')
|
||||||
|
|
||||||
local sea_level = mapgen_rivers.settings.sea_level
|
local sea_level = mapgen_rivers.settings.sea_level
|
||||||
local elevation_chill = mapgen_rivers.settings.elevation_chill
|
local elevation_chill = mapgen_rivers.settings.elevation_chill
|
||||||
@ -22,8 +24,6 @@ if use_biomegen_mod then
|
|||||||
biomegen.set_elevation_chill(elevation_chill)
|
biomegen.set_elevation_chill(elevation_chill)
|
||||||
end
|
end
|
||||||
|
|
||||||
local heightmaps = dofile(modpath .. 'heightmap.lua')
|
|
||||||
|
|
||||||
-- Linear interpolation
|
-- Linear interpolation
|
||||||
local function interp(v00, v01, v11, v10, xf, zf)
|
local function interp(v00, v01, v11, v10, xf, zf)
|
||||||
local v0 = v01*xf + v00*(1-xf)
|
local v0 = v01*xf + v00*(1-xf)
|
||||||
@ -117,9 +117,9 @@ local function generate(minp, maxp, seed)
|
|||||||
local pmaxp = {x=floor(xmax)+1, z=floor(zmax)+1}
|
local pmaxp = {x=floor(xmax)+1, z=floor(zmax)+1}
|
||||||
incr = pmaxp.x-pminp.x+1
|
incr = pmaxp.x-pminp.x+1
|
||||||
i_origin = 1 - pminp.z*incr - pminp.x
|
i_origin = 1 - pminp.z*incr - pminp.x
|
||||||
terrain_map, lake_map = heightmaps(pminp, pmaxp)
|
terrain_map, lake_map = mapgen_rivers.make_heightmaps(pminp, pmaxp)
|
||||||
else
|
else
|
||||||
terrain_map, lake_map = heightmaps(minp, maxp)
|
terrain_map, lake_map = mapgen_rivers.make_heightmaps(minp, maxp)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check that there is at least one position that reaches min y
|
-- Check that there is at least one position that reaches min y
|
||||||
|
@ -119,7 +119,7 @@ local init = false
|
|||||||
|
|
||||||
-- On map generation, determine into which polygon every point (in 2D) will fall.
|
-- On map generation, determine into which polygon every point (in 2D) will fall.
|
||||||
-- Also store polygon-specific data
|
-- Also store polygon-specific data
|
||||||
local function make_polygons(minp, maxp)
|
function mapgen_rivers.make_polygons(minp, maxp)
|
||||||
|
|
||||||
local grid = mapgen_rivers.grid
|
local grid = mapgen_rivers.grid
|
||||||
local dem = grid.dem
|
local dem = grid.dem
|
||||||
@ -252,5 +252,3 @@ local function make_polygons(minp, maxp)
|
|||||||
|
|
||||||
return polygons
|
return polygons
|
||||||
end
|
end
|
||||||
|
|
||||||
return make_polygons
|
|
||||||
|
Loading…
Reference in New Issue
Block a user