master
FaceDeer 2018-12-01 20:48:16 -07:00
parent 3a2c816842
commit 47a9388933
4 changed files with 47 additions and 6 deletions

View File

@ -2,6 +2,9 @@ mapgen_helper = {}
mapgen_helper.mapgen_seed = tonumber(minetest.get_mapgen_setting("seed"))
-- The "sidelen" used in almost every mapgen
mapgen_helper.block_size = tonumber(minetest.get_mapgen_setting("chunksize")) * 16
local MP = minetest.get_modpath(minetest.get_current_modname())
dofile(MP.."/voxelarea_iterator.lua")
dofile(MP.."/voxeldata.lua")
@ -25,16 +28,15 @@ end
-- Returns a consistent list of random points within a volume.
-- Each call to this method will give the same set of points if the same parameters are provided
mapgen_helper.get_random_points = function(minp, maxp, min_output_size, max_output_size)
local next_seed = math.random(1, 1000000000)
math.randomseed(minp.x + minp.y*2^4 + minp.z*2^8 + mapgen_helper.mapgen_seed)
math.randomseed(minetest.hash_node_position(minp) + mapgen_helper.mapgen_seed)
local count = math.random(min_output_size, max_output_size)
local result = {}
while count > 0 do
local point = {}
point.x = math.random(minp.x, maxp.x)
point.x = math.random(minp.y, maxp.y)
point.y = math.random(minp.y, maxp.y)
point.z = math.random(minp.z, maxp.z)
table.insert(result, point)
count = count - 1

View File

@ -7,8 +7,8 @@ mapgen_helper.get_region_minp_xz = function(pos_xz, mapblocks)
return {x = math.floor((pos.x+32) / region_size) * region_size - 32, y = 0, z = math.floor((pos.z+32) / region_size) * region_size - 32}
end
-- Given a position and a grid scale, returns the minp corners of the four grids that the player is closest to.
-- For example, if we have a grid scale of 6 and the parameter position is at "*", the four points marked "R" would be returned.
-- Given a position and a region scale, returns the minp corners of the four regions that the player is closest to.
-- For example, if we have a region scale of 6 and the parameter position is at "*", the four points marked "R" would be returned.
-- |-----|-----|-----| |-----|-----|-----| |-----|-----|-----|
-- | | | | | | | | | | | |

View File

@ -72,4 +72,4 @@ end
function VoxelArea:iterp_xyz(minp, maxp)
return self:iter_xyz(minp.x, minp.y, minp.z, maxp.x, maxp.y, maxp.z)
end
end

View File

@ -16,6 +16,7 @@ mapgen_helper.mapgen_vm_data_param2 = function()
end
mapgen_helper.perlin3d = function(name, minp, maxp, perlin_params)
--minetest.debug(name..minetest.pos_to_string(minp)..minetest.pos_to_string(maxp))
local minx = minp.x
local minz = minp.z
local sidelen = maxp.x - minp.x + 1 --length of a mapblock
@ -44,6 +45,44 @@ mapgen_helper.perlin2d = function(name, minp, maxp, perlin_params)
return nvals_perlin
end
-- similar to iter_xyz, but iterates first along the y axis. Useful in mapgens that want to detect a vertical transition (eg, finding ground level)
function VoxelArea:iter_yxz(minx, miny, minz, maxx, maxy, maxz)
local i = self:index(minx, miny, minz) - self.ystride
local x = minx
local y = miny - 1
local z = minz
return function()
y = y + 1
if y <= maxy then
i = i + self.ystride
return i, x, y, z
end
y = miny
x = x + 1
if x <= maxx then
i = self:index(x, y, z)
return i, x, y, z
end
x = minx
z = z + 1
if z <= maxz then
i = self:index(x, y, z)
return i, x, y, z
end
end
end
function VoxelArea:iterp_yxz(minp, maxp)
return self:iter_yxz(minp.x, minp.y, minp.z, maxp.x, maxp.y, maxp.z)
end
-- TODO: need a nice iterator for this kind of thing, check whether VoxelArea's can do this or if something custom will be needed
mapgen_helper.index2d = function(minp, maxp, x, z)
return x - minp.x +