Initial galaxy creation loop. Space skybox in ignore nodes
This commit is contained in:
parent
b06ff91ccc
commit
1656687dc5
@ -1,4 +1,4 @@
|
||||
planets 0.1.2 by paramat
|
||||
planets 0.1.3 by paramat
|
||||
For Minetest 0.4.13 and later
|
||||
Depends default
|
||||
Licenses: code WTFPL
|
||||
|
80
init.lua
80
init.lua
@ -1,5 +1,8 @@
|
||||
-- Parameters
|
||||
|
||||
local pnum = 1 -- number of planets desired
|
||||
local maxatt = 128 -- maximum number of attempts to add a planet
|
||||
|
||||
local np_terrain = {
|
||||
offset = 0,
|
||||
scale = 1.0,
|
||||
@ -27,10 +30,10 @@ dofile(minetest.get_modpath("planets") .. "/nodes.lua")
|
||||
-- Mapgen parameters
|
||||
|
||||
minetest.set_mapgen_params({mgname = "singlenode",
|
||||
flags = "nolight", water_level = -31000})
|
||||
chunksize = 5, water_level = -31000, flags = "nolight"})
|
||||
|
||||
|
||||
-- Space array and planet def table
|
||||
-- Create pseudorandom galaxy
|
||||
|
||||
-- space is 64 ^ 3 chunks, centred on world centre
|
||||
-- space table is flat array of planet ids or nil (vacuum chunk)
|
||||
@ -39,41 +42,71 @@ local space = {}
|
||||
local def = {}
|
||||
local spzstr = 64 * 64 -- space array z stride
|
||||
local spystr = 64 -- space array y stride
|
||||
local plid = 0 -- planet id of last planet added, 0 = none
|
||||
local addatt = 0 -- number of attempts to add a planet
|
||||
|
||||
while plid < pnum and addatt <= maxatt do -- avoid infinite attempts
|
||||
-- create initial planet data to check for obstruction
|
||||
-- cenx/y/z is planet centre
|
||||
-- radter = terrain radius / water level
|
||||
-- radatm = atmosphere radius
|
||||
-- plavar = planet variation
|
||||
-- radmax = atmosphere radius or max mountain radius
|
||||
local cenx = 0
|
||||
local ceny = 0
|
||||
local cenz = 0
|
||||
local radter = 256
|
||||
local radatm = 384
|
||||
local plavar = 1
|
||||
local radmax = 384
|
||||
|
||||
-- chunk co-ords of chunk containing planet centre
|
||||
-- measured from space origin (-32, -32, -32 chunks)
|
||||
local cenxcc = math.floor((cenx + 32) / 80) + 32
|
||||
local cenycc = math.floor((ceny + 32) / 80) + 32
|
||||
local cenzcc = math.floor((cenz + 32) / 80) + 32
|
||||
local radatmc = math.ceil(radatm / 80) -- planet radius in chunks
|
||||
local radmaxc = math.ceil(radmax / 80) -- planet radius in chunks
|
||||
|
||||
-- TODO add similar scan loop to check for existing planets
|
||||
-- do this once centre and atmosphere radius are known and
|
||||
-- before calculating other properties or creating def table entry
|
||||
-- check space is clear for planet
|
||||
local clear = true -- is space clear
|
||||
print ("[planets] Checking for obstruction")
|
||||
|
||||
-- planet 1
|
||||
def[1] = {i = cenx, j = ceny, k = cenz, t = radter, a = radatm, v = plavar}
|
||||
for cz = cenzcc - radmaxc, cenzcc + radmaxc do
|
||||
for cy = cenycc - radmaxc, cenycc + radmaxc do
|
||||
local spi = cz * spzstr + cy * spystr + cenxcc - radmaxc + 1
|
||||
for cx = cenxcc - radmaxc, cenxcc + radmaxc do
|
||||
if space[spi] ~= nil then
|
||||
clear = false
|
||||
print ("[planets] Planet obstructed")
|
||||
break
|
||||
end
|
||||
spi = spi + 1
|
||||
end
|
||||
if not clear then
|
||||
break
|
||||
end
|
||||
end
|
||||
if not clear then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
for cz = cenzcc - radatmc, cenzcc + radatmc do
|
||||
for cy = cenycc - radatmc, cenycc + radatmc do
|
||||
local spi = cz * spzstr + cy * spystr + cenxcc - radatmc + 1
|
||||
for cx = cenxcc - radatmc, cenxcc + radatmc do
|
||||
space[spi] = 1
|
||||
if clear then -- add planet
|
||||
-- TODO generate extra planet data
|
||||
plid = #def + 1 -- planet id
|
||||
-- add planet data to def table
|
||||
def[plid] = {i = cenx, j = ceny, k = cenz, t = radter, m = radmax}
|
||||
print ("[planets] Adding planet " .. plid)
|
||||
|
||||
for cz = cenzcc - radmaxc, cenzcc + radmaxc do
|
||||
for cy = cenycc - radmaxc, cenycc + radmaxc do
|
||||
local spi = cz * spzstr + cy * spystr + cenxcc - radmaxc + 1
|
||||
for cx = cenxcc - radmaxc, cenxcc + radmaxc do
|
||||
space[spi] = plid -- add planet id to this chunk
|
||||
spi = spi + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
addatt = addatt + 1
|
||||
end
|
||||
|
||||
|
||||
-- Globalstep function
|
||||
@ -89,14 +122,15 @@ local skybox_space = {
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
if math.random() < 0.02 then -- set gravity, skybox and override light
|
||||
if math.random() < 0.05 then -- set gravity, skybox and override light
|
||||
local ppos = player:getpos()
|
||||
ppos.y = ppos.y + 1.5 -- node player head is in
|
||||
if minetest.get_node(ppos).name == "planets:vacuum" then
|
||||
local nodename = minetest.get_node(ppos).name
|
||||
if nodename == "planets:vacuum" or nodename == "ignore" then -- space
|
||||
--player:set_physics_override(1, 1, 1) -- speed, jump, gravity
|
||||
player:set_sky({r = 0, g = 0, b = 0, a = 0}, "skybox", skybox_space)
|
||||
player:override_day_night_ratio(1)
|
||||
else
|
||||
else -- regular sky for now
|
||||
--player:set_physics_override(1, 1, 1) -- speed, jump, gravity
|
||||
player:set_sky({}, "regular", {})
|
||||
player:override_day_night_ratio(nil)
|
||||
@ -165,7 +199,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
local nvals_terrain = nobj_terrain:get3dMap_flat(pmapminp, nbuf_terrain)
|
||||
local nvals_cloud = nobj_cloud:get3dMap_flat(pmapminpclo, nbuf_cloud)
|
||||
|
||||
local tersca = (pdef.a - pdef.t) / 2 -- terrain scale
|
||||
local tersca = (pdef.m - pdef.t) / 2 -- terrain scale
|
||||
|
||||
local ni = 1 -- noise index
|
||||
for z = z0, z1 do
|
||||
@ -195,7 +229,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
if nvals_cloud[niq] > 0.5 then
|
||||
data[vi] = c_cloud
|
||||
end
|
||||
elseif nodrad <= pdef.a then -- air
|
||||
elseif nodrad <= pdef.m then -- air
|
||||
data[vi] = c_air
|
||||
else -- vacuum
|
||||
data[vi] = c_vacuum
|
||||
@ -227,5 +261,5 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
vm:write_to_map(data)
|
||||
|
||||
local chugent = math.ceil((os.clock() - t0) * 1000)
|
||||
print ("[planets] " .. chugent .. " ms")
|
||||
print ("[planets] Generated chunk " .. chugent .. " ms")
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user