Optimise use of noise and lighting. Fix code style issues. New LGPL license. Add info to readme

This commit is contained in:
paramat 2015-08-21 23:24:04 +01:00
parent 135943b1a3
commit 6ae9e45202
4 changed files with 179 additions and 119 deletions

View File

@ -1,4 +1,15 @@
pathv6alt 0.2.9 by paramat pathv6alt 0.3.0 by paramat
For latest stable Minetest back to 0.4.8 For Minetest 0.4.12 and later
Depends default stairs Depends default stairs
Licenses: code WTFPL Licenses: Code LGPLv2.1, textures CC BY-SA 3.0
Use with mapgen v6. Creates a worldwide network of paths, bridges and occasional tunnels.
Compatible with custom mapgen v6 noise parameters, you will need to enter your custom noise parameters 'terrain base' 'terrain higher' 'height select' 'mud' into the mod code.
By default will generate paths up to y = 127, raise parameter YMAXMINP for a higher limit, you will need to tune HSAMP to avoid paths becoming too steep.
Mgv6 noise parameters are used to calculate a path surface that smoothly conforms to the land without getting too steep to climb. Where the path leaves the ground it becomes a wooden bridge with random columns that reach to stone below.
There is an (enabled by default) option of using stair nodes to create walkable (no jumping) and drivable paths.
There are 4 path networks with 'spreads' of 1024, 2048, 4096 and 8192, the two larger spread paths are 5 nodes wide.
Mgv6 has 'base terrain' and 'higher terrain', and a third noise 'height select' controls the blend/mix between those two terrains. A fourth noise 'steepness' controls how fast the height select switches between base and higher, creating slopes and cliffs.
In this mod mgv6 mapgen is recreated in lua, the surface of the paths is essentially mgv6 as it would be if all slopes were gentle slopes instead of cliffs, i have set a fixed and low 'steepness'.

108
init.lua
View File

@ -1,20 +1,14 @@
-- pathv6alt 0.2.9 by paramat
-- For latest stable Minetest and back to 0.4.8
-- Depends default stairs
-- License: code WTFPL
-- junglewood bridge boards
-- mod nodes do not drop default nodes
-- Stabilise tunnel roof: dirt/sand to stone
-- Parameters -- Parameters
local WALK = true -- Walkable paths local WALK = true -- Walkable paths
local YMAXMINP = 48 -- Maximum minp.y of generated chunks (-32 for default mapgen v6. 48, 128, 208 for higher) local YMAXMINP = 48 -- Maximum minp.y of generated chunks
-- (-32 for default mapgen v6. 48, 128, 208 for higher)
local HSAMP = 0.85 -- Height select amplitude. Maximum steepness of paths local HSAMP = 0.85 -- Height select amplitude. Maximum steepness of paths
local HSOFF = -0.2 -- Height select noise offset. Bias paths towards base (-) or higher (+) terrain local HSOFF = -0.2 -- Height select noise offset.
-- Bias paths towards base (-) or higher (+) terrain
local TCOL = 0.3 -- Column noise threshold. Bridge column density local TCOL = 0.3 -- Column noise threshold. Bridge column density
-- Mapgen v6 parameters -- Mapgen v6 parameters
-- 2D noise for base terrain -- 2D noise for base terrain
@ -118,10 +112,32 @@ local np_column = {
persist = 2 persist = 2
} }
-- Stuff
-- Do files
dofile(minetest.get_modpath("pathv6alt") .. "/nodes.lua") dofile(minetest.get_modpath("pathv6alt") .. "/nodes.lua")
-- Set mapgen parameters
minetest.register_on_mapgen_init(function(mgparams)
minetest.set_mapgen_params({flags="nolight"})
end)
-- Initialize noise objects to nil
local nobj_base = nil
local nobj_higher = nil
local nobj_hselect = nil
local nobj_mud = nil
local nobj_patha = nil
local nobj_pathb = nil
local nobj_pathc = nil
local nobj_pathd = nil
local nobj_column = nil
-- On generated function -- On generated function
minetest.register_on_generated(function(minp, maxp, seed) minetest.register_on_generated(function(minp, maxp, seed)
@ -137,7 +153,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
local y0 = minp.y local y0 = minp.y
local z0 = minp.z local z0 = minp.z
print ("[pathv6alt] chunk minp ("..x0.." "..y0.." "..z0..")") --print ("[pathv6alt] minp (" .. x0 .. " " .. y0 .. " " .. z0 .. ")")
local c_air = minetest.get_content_id("air") local c_air = minetest.get_content_id("air")
local c_ignore = minetest.get_content_id("ignore") local c_ignore = minetest.get_content_id("ignore")
@ -173,19 +189,31 @@ minetest.register_on_generated(function(minp, maxp, seed)
local sidelen = x1 - x0 + 1 local sidelen = x1 - x0 + 1
local overlen = sidelen + 5 -- noisemap x, z from minp-3 to maxp+2 local overlen = sidelen + 5 -- noisemap x, z from minp-3 to maxp+2
local chulens = {x=overlen, y=overlen, z=sidelen} local chulens = {x = overlen, y = overlen, z = 1}
local minpos = {x = x0 - 3, y = z0 - 3} local minpos = {x = x0 - 3, y = z0 - 3}
local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat({x=x0+122, y=z0+122}) -- noisemap offsets - 3 nobj_base = nobj_base or minetest.get_perlin_map(np_base, chulens)
local nvals_higher = minetest.get_perlin_map(np_higher, chulens):get2dMap_flat({x=x0+247, y=z0+247}) nobj_higher = nobj_higher or minetest.get_perlin_map(np_higher, chulens)
local nvals_hselect = minetest.get_perlin_map(np_hselect, chulens):get2dMap_flat({x=x0+122, y=z0+122}) nobj_hselect = nobj_hselect or minetest.get_perlin_map(np_hselect, chulens)
local nvals_mud = minetest.get_perlin_map(np_mud, chulens):get2dMap_flat({x=x0+97, y=z0+97}) nobj_mud = nobj_mud or minetest.get_perlin_map(np_mud, chulens)
local nvals_patha = minetest.get_perlin_map(np_patha, chulens):get2dMap_flat(minpos) nobj_patha = nobj_patha or minetest.get_perlin_map(np_patha, chulens)
local nvals_pathb = minetest.get_perlin_map(np_pathb, chulens):get2dMap_flat(minpos) nobj_pathb = nobj_pathb or minetest.get_perlin_map(np_pathb, chulens)
local nvals_pathc = minetest.get_perlin_map(np_pathc, chulens):get2dMap_flat(minpos) nobj_pathc = nobj_pathc or minetest.get_perlin_map(np_pathc, chulens)
local nvals_pathd = minetest.get_perlin_map(np_pathd, chulens):get2dMap_flat(minpos) nobj_pathd = nobj_pathd or minetest.get_perlin_map(np_pathd, chulens)
local nvals_column = minetest.get_perlin_map(np_column, chulens):get2dMap_flat(minpos) nobj_column = nobj_column or minetest.get_perlin_map(np_column, chulens)
-- these 4 minpos are mgv6 noise offsets - 3
local nvals_base = nobj_base:get2dMap_flat({x = x0 + 122, y = z0 + 122})
local nvals_higher = nobj_higher:get2dMap_flat({x = x0 + 247, y = z0 + 247})
local nvals_hselect = nobj_hselect:get2dMap_flat({x = x0 + 122, y = z0 + 122})
local nvals_mud = nobj_mud:get2dMap_flat({x = x0 + 97, y = z0 + 97})
local nvals_patha = nobj_patha:get2dMap_flat(minpos)
local nvals_pathb = nobj_pathb:get2dMap_flat(minpos)
local nvals_pathc = nobj_pathc:get2dMap_flat(minpos)
local nvals_pathd = nobj_pathd:get2dMap_flat(minpos)
local nvals_column = nobj_column:get2dMap_flat(minpos)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax}) local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
@ -199,7 +227,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
local n_xprepathb = false local n_xprepathb = false
local n_xprepathc = false local n_xprepathc = false
local n_xprepathd = false local n_xprepathd = false
for x = x0 - 3, x1 + 2 do -- x0-3, z0-3 is to setup initial values of 'xprepath_', 'zprepath_' -- x0-3, z0-3 is to setup initial values of 'xprepath_', 'zprepath_'
for x = x0 - 3, x1 + 2 do
local n_patha = nvals_patha[ni] local n_patha = nvals_patha[ni]
local n_zprepatha = nvals_patha[(ni - overlen)] local n_zprepatha = nvals_patha[(ni - overlen)]
@ -212,7 +241,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
local n_pathd = nvals_pathd[ni] local n_pathd = nvals_pathd[ni]
local n_zprepathd = nvals_pathd[(ni - overlen)] local n_zprepathd = nvals_pathd[(ni - overlen)]
if x >= x0 - 2 and z >= z0 - 2 then -- paths overgenerate by 2 nodes to erase mudflow griefing -- paths overgenerate by 2 nodes to erase mudflow griefing
if x >= x0 - 2 and z >= z0 - 2 then
local abscol = math.abs(nvals_column[ni]) local abscol = math.abs(nvals_column[ni])
local base = nvals_base[ni] local base = nvals_base[ni]
local higher = nvals_higher[ni] local higher = nvals_higher[ni]
@ -226,10 +256,15 @@ minetest.register_on_generated(function(minp, maxp, seed)
local tlevel = base * (1 - tblend) + higher * tblend + mudadd local tlevel = base * (1 - tblend) + higher * tblend + mudadd
local pathy = math.floor(math.max(tlevel, 6)) local pathy = math.floor(math.max(tlevel, 6))
if (n_patha >= 0 and n_xprepatha < 0) or (n_patha < 0 and n_xprepatha >= 0) -- patha -- paths a and b
or (n_patha >= 0 and n_zprepatha < 0) or (n_patha < 0 and n_zprepatha >= 0) if (n_patha >= 0 and n_xprepatha < 0)
or (n_pathb >= 0 and n_xprepathb < 0) or (n_pathb < 0 and n_xprepathb >= 0) -- pathb or (n_patha < 0 and n_xprepatha >= 0)
or (n_pathb >= 0 and n_zprepathb < 0) or (n_pathb < 0 and n_zprepathb >= 0) then or (n_patha >= 0 and n_zprepatha < 0)
or (n_patha < 0 and n_zprepatha >= 0)
or (n_pathb >= 0 and n_xprepathb < 0)
or (n_pathb < 0 and n_xprepathb >= 0)
or (n_pathb >= 0 and n_zprepathb < 0)
or (n_pathb < 0 and n_zprepathb >= 0) then
if pathy > y1 then -- build columns through this chunk if pathy > y1 then -- build columns through this chunk
if abscol < TCOL then if abscol < TCOL then
local vi = area:index(x, y1, z) local vi = area:index(x, y1, z)
@ -455,10 +490,15 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
end end
end end
elseif (n_pathc >= 0 and n_xprepathc < 0) or (n_pathc < 0 and n_xprepathc >= 0) -- pathc -- paths c and d
or (n_pathc >= 0 and n_zprepathc < 0) or (n_pathc < 0 and n_zprepathc >= 0) elseif (n_pathc >= 0 and n_xprepathc < 0)
or (n_pathd >= 0 and n_xprepathd < 0) or (n_pathd < 0 and n_xprepathd >= 0) -- pathd or (n_pathc < 0 and n_xprepathc >= 0)
or (n_pathd >= 0 and n_zprepathd < 0) or (n_pathd < 0 and n_zprepathd >= 0) then or (n_pathc >= 0 and n_zprepathc < 0)
or (n_pathc < 0 and n_zprepathc >= 0)
or (n_pathd >= 0 and n_xprepathd < 0)
or (n_pathd < 0 and n_xprepathd >= 0)
or (n_pathd >= 0 and n_zprepathd < 0)
or (n_pathd < 0 and n_zprepathd >= 0) then
if pathy > y1 then -- build columns through this chunk if pathy > y1 then -- build columns through this chunk
if abscol < TCOL then if abscol < TCOL then
for i = -1, 1, 2 do for i = -1, 1, 2 do
@ -730,11 +770,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
vm:set_data(data) vm:set_data(data)
vm:set_lighting({day=0, night=0})
vm:calc_lighting() vm:calc_lighting()
vm:write_to_map(data) vm:write_to_map(data)
local chugent = math.ceil((os.clock() - t1) * 1000) local chugent = math.ceil((os.clock() - t1) * 1000)
print ("[pathv6alt] " .. chugent .. " ms") print ("[pathv6alt] " .. chugent .. " ms")
end) end)

View File

@ -1,14 +1,25 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE License of source code
Version 2, December 2004 ----------------------
Pathv6alt
Copyright (C) 2014-2015 paramat
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
Everyone is permitted to copy and distribute verbatim or modified This program is distributed in the hope that it will be useful,
copies of this license document, and changing it is allowed as long but WITHOUT ANY WARRANTY; without even the implied warranty of
as the name is changed. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE You should have received a copy of the GNU Lesser General Public License along
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0. You just DO WHAT THE FUCK YOU WANT TO. License of media (textures)
---------------------------
All textures are derived from Minetest's default textures.
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
http://creativecommons.org/licenses/by-sa/3.0/

View File

@ -23,7 +23,7 @@ minetest.register_node("pathv6alt:bridgewood", {
}) })
minetest.register_node("pathv6alt:stairn", { -- stair rising to the north minetest.register_node("pathv6alt:stairn", { -- stair rising to the north
description = "Stair north", description = "Jungle wood stair N",
tiles = {"default_junglewood.png"}, tiles = {"default_junglewood.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -40,7 +40,7 @@ minetest.register_node("pathv6alt:stairn", { -- stair rising to the north
}) })
minetest.register_node("pathv6alt:stairs", { minetest.register_node("pathv6alt:stairs", {
description = "Stair south", description = "Jungle wood stair S",
tiles = {"default_junglewood.png"}, tiles = {"default_junglewood.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -57,7 +57,7 @@ minetest.register_node("pathv6alt:stairs", {
}) })
minetest.register_node("pathv6alt:staire", { minetest.register_node("pathv6alt:staire", {
description = "Stair east", description = "Jungle wood stair E",
tiles = {"default_junglewood.png"}, tiles = {"default_junglewood.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -74,7 +74,7 @@ minetest.register_node("pathv6alt:staire", {
}) })
minetest.register_node("pathv6alt:stairw", { minetest.register_node("pathv6alt:stairw", {
description = "Stair west", description = "Jungle wood stair W",
tiles = {"default_junglewood.png"}, tiles = {"default_junglewood.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -91,7 +91,7 @@ minetest.register_node("pathv6alt:stairw", {
}) })
minetest.register_node("pathv6alt:stairne", { minetest.register_node("pathv6alt:stairne", {
description = "Stair north east", description = "Jungle wood stair NE",
tiles = {"default_junglewood.png"}, tiles = {"default_junglewood.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -108,7 +108,7 @@ minetest.register_node("pathv6alt:stairne", {
}) })
minetest.register_node("pathv6alt:stairnw", { minetest.register_node("pathv6alt:stairnw", {
description = "Stair north west", description = "Jungle wood stair NW",
tiles = {"default_junglewood.png"}, tiles = {"default_junglewood.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -125,7 +125,7 @@ minetest.register_node("pathv6alt:stairnw", {
}) })
minetest.register_node("pathv6alt:stairse", { minetest.register_node("pathv6alt:stairse", {
description = "Stair south east", description = "Jungle wood stair SE",
tiles = {"default_junglewood.png"}, tiles = {"default_junglewood.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -142,7 +142,7 @@ minetest.register_node("pathv6alt:stairse", {
}) })
minetest.register_node("pathv6alt:stairsw", { minetest.register_node("pathv6alt:stairsw", {
description = "Stair south west", description = "Jungle wood stair SW",
tiles = {"default_junglewood.png"}, tiles = {"default_junglewood.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -159,7 +159,7 @@ minetest.register_node("pathv6alt:stairsw", {
}) })
minetest.register_node("pathv6alt:pstairn", { minetest.register_node("pathv6alt:pstairn", {
description = "Stair north", description = "Dirt stair N",
tiles = {"pathv6alt_path.png"}, tiles = {"pathv6alt_path.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -177,7 +177,7 @@ minetest.register_node("pathv6alt:pstairn", {
}) })
minetest.register_node("pathv6alt:pstairs", { minetest.register_node("pathv6alt:pstairs", {
description = "Stair south", description = "Dirt stair S",
tiles = {"pathv6alt_path.png"}, tiles = {"pathv6alt_path.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -195,7 +195,7 @@ minetest.register_node("pathv6alt:pstairs", {
}) })
minetest.register_node("pathv6alt:pstaire", { minetest.register_node("pathv6alt:pstaire", {
description = "Stair east", description = "Dirt stair E",
tiles = {"pathv6alt_path.png"}, tiles = {"pathv6alt_path.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -213,7 +213,7 @@ minetest.register_node("pathv6alt:pstaire", {
}) })
minetest.register_node("pathv6alt:pstairw", { minetest.register_node("pathv6alt:pstairw", {
description = "Stair west", description = "Dirt stair W",
tiles = {"pathv6alt_path.png"}, tiles = {"pathv6alt_path.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -231,7 +231,7 @@ minetest.register_node("pathv6alt:pstairw", {
}) })
minetest.register_node("pathv6alt:pstairne", { minetest.register_node("pathv6alt:pstairne", {
description = "Stair north east", description = "Dirt stair NE",
tiles = {"pathv6alt_path.png"}, tiles = {"pathv6alt_path.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -249,7 +249,7 @@ minetest.register_node("pathv6alt:pstairne", {
}) })
minetest.register_node("pathv6alt:pstairnw", { minetest.register_node("pathv6alt:pstairnw", {
description = "Stair north west", description = "Dirt stair NW",
tiles = {"pathv6alt_path.png"}, tiles = {"pathv6alt_path.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -267,7 +267,7 @@ minetest.register_node("pathv6alt:pstairnw", {
}) })
minetest.register_node("pathv6alt:pstairse", { minetest.register_node("pathv6alt:pstairse", {
description = "Stair south east", description = "Dirt stair SE",
tiles = {"pathv6alt_path.png"}, tiles = {"pathv6alt_path.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -285,7 +285,7 @@ minetest.register_node("pathv6alt:pstairse", {
}) })
minetest.register_node("pathv6alt:pstairsw", { minetest.register_node("pathv6alt:pstairsw", {
description = "Stair south west", description = "Dirt stair SW",
tiles = {"pathv6alt_path.png"}, tiles = {"pathv6alt_path.png"},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",