by paramat » Sat Aug 27, 2016 23:45
This mod addresses a problem i have been wanting to solve: how to generate multiple planets throughout the MT worldspace when each planet can be much larger than one mapchunk, considering that mapgen works per-mapchunk?
//////////////
On mod startup a 'space' table is created which is a flat array where each entry represents a mapchunk within a 128^3 mapchunk worldspace. The used worldspace is therefore 10240 nodes along each edge and the table has 2,097,152 entries.
Table entries start as 'nil', and 'nil' is interpreted as a mapchunk full of vacuum nodes.
For each planet added the 'planet id' number is added to the 'space' table for every mapchunk that planet occupies.
Before this though these mapchunks are scanned for any previously added planet, to avoid collided planets.
Random data for each planet is added to a second table called 'def' which is indexed by 'planet id'. This allows a large amount of data for each planet to be stored without it being duplicated in the 'space' table.
The most important planet data is the co-ordinates for it's centre, but there is also data for atmosphere radius, terrain scale, average terrain radius, lava core radius, ocean bool, water radius, atmosphere bool and cloud cover, with more data intended.
All randomness is pseudorandom, so every game session the exact same tables are generated, planets are in the same positions etc.
////////////////
Now when mapgen operates it looks up the entry in the space table corresponding to the mapchunk being generated, 'nil' results in vacuum nodes, otherwise planet data is used to generate part of a planet.
Player gravity depends on planet size and whether the player is close to a planet.
Away from a planet player gravity is set to zero. If in vacuum nodes the player will 'drown' (spacesuit intended).
If there is an atmosphere player sky is set to normal, otherwise a space skybox is used (currently black).
New players are spawned above the first planet and fall down onto it, disable damage first.
If you enable fly and disable damage you can travel through space to find new worlds.
////////////////
Currently all planets are fairly similar, Earthlike and lack caves and ores. The intention is for a variety of planets / moons / asteroids / comets of varying sizes and varying nodes, with or without atmospheres, oceans, clouds.
The spherical planets are for fun, and only have flora on the top segment. More suitable may be to have cubic planets each structured as a standard Minetest world is.
Last edited by
paramat on Sat Aug 27, 2016 23:59, edited 1 time in total.