From cd2a77803f87a6e6e85db113a5546a6306db63f8 Mon Sep 17 00:00:00 2001 From: Gael-de-Sailly Date: Fri, 21 Jan 2022 14:22:22 +0100 Subject: [PATCH] Globalize some of the main functions This will allow to avoid nested 'dofile's --- heightmap.lua | 7 ++----- init.lua | 8 ++++---- polygons.lua | 4 +--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/heightmap.lua b/heightmap.lua index f9e593e..3532818 100644 --- a/heightmap.lua +++ b/heightmap.lua @@ -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 diff --git a/init.lua b/init.lua index f90e693..8cb43b7 100644 --- a/init.lua +++ b/init.lua @@ -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 diff --git a/polygons.lua b/polygons.lua index 6dd04a8..b977958 100644 --- a/polygons.lua +++ b/polygons.lua @@ -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