Globalize some of the main functions

This will allow to avoid nested 'dofile's
This commit is contained in:
Gael-de-Sailly 2022-01-21 14:22:22 +01:00
parent b0930f4d40
commit cd2a77803f
3 changed files with 7 additions and 12 deletions

View File

@ -1,6 +1,5 @@
local modpath = mapgen_rivers.modpath
local make_polygons = dofile(modpath .. 'polygons.lua')
local transform_quadri = dofile(modpath .. 'geometry.lua')
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)
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 terrain_height_map = {}
@ -144,5 +143,3 @@ local function heightmaps(minp, maxp)
return terrain_height_map, lake_height_map
end
return heightmaps

View File

@ -10,6 +10,8 @@ if minetest.get_mapgen_setting("mg_name") ~= "singlenode" then
end
dofile(modpath .. 'settings.lua')
dofile(modpath .. 'polygons.lua')
dofile(modpath .. 'heightmap.lua')
local sea_level = mapgen_rivers.settings.sea_level
local elevation_chill = mapgen_rivers.settings.elevation_chill
@ -22,8 +24,6 @@ if use_biomegen_mod then
biomegen.set_elevation_chill(elevation_chill)
end
local heightmaps = dofile(modpath .. 'heightmap.lua')
-- Linear interpolation
local function interp(v00, v01, v11, v10, xf, zf)
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}
incr = pmaxp.x-pminp.x+1
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
terrain_map, lake_map = heightmaps(minp, maxp)
terrain_map, lake_map = mapgen_rivers.make_heightmaps(minp, maxp)
end
-- Check that there is at least one position that reaches min y

View File

@ -119,7 +119,7 @@ local init = false
-- On map generation, determine into which polygon every point (in 2D) will fall.
-- Also store polygon-specific data
local function make_polygons(minp, maxp)
function mapgen_rivers.make_polygons(minp, maxp)
local grid = mapgen_rivers.grid
local dem = grid.dem
@ -252,5 +252,3 @@ local function make_polygons(minp, maxp)
return polygons
end
return make_polygons