Allow both main thread & mapgen env execution
parent
14cc75a48d
commit
b6055c76fb
19
API.md
19
API.md
|
@ -3,10 +3,27 @@
|
||||||
This mod is built in a way to be easy to change the underground world.
|
This mod is built in a way to be easy to change the underground world.
|
||||||
The API is written in a way to be very similar to the Minetest API.
|
The API is written in a way to be very similar to the Minetest API.
|
||||||
|
|
||||||
|
## Main thread vs. separate thread
|
||||||
|
|
||||||
|
This mod can both run on the main thread or on the mapgen thread. Generally,
|
||||||
|
the mapgen thread is recommended, but it isn't supported for Minetest versions
|
||||||
|
5.8 and under. The main thread works for everyone but it is slower.
|
||||||
|
|
||||||
|
This mod automatically determines whether a Minetest user is able to use the
|
||||||
|
faster mapgen thread. As a result, you should use the function
|
||||||
|
`ns_cavegen_init.register_cavegen_script`, with the input pointing to a file
|
||||||
|
containing the script for the cave generator. This mod will ensure that your
|
||||||
|
script is run on the appropriate thread.
|
||||||
|
|
||||||
|
If you wish to decide for yourself which thread to run the cave generator on,
|
||||||
|
you can use the `ns_cavegen_mapgen_environment` option in your settings file
|
||||||
|
(usually `minetest.conf`) to tell the cave generator whether to run the cave
|
||||||
|
generator in the separate thread or not.
|
||||||
|
|
||||||
## Shapes
|
## Shapes
|
||||||
|
|
||||||
Underground caves have varying shapes, and the variable
|
Underground caves have varying shapes, and the variable
|
||||||
`noordstar.registered_shapes` contains all those definitions.
|
`ns_cavegen.registered_shapes` contains all those definitions.
|
||||||
|
|
||||||
For shapes, the following functions are available:
|
For shapes, the following functions are available:
|
||||||
|
|
||||||
|
|
22
README.md
22
README.md
|
@ -1,26 +1,14 @@
|
||||||
# Noordstar caves
|
# Noordstar cave generator
|
||||||
|
|
||||||
The Noordstar caves mod helps add more caves to MineClone2 and Mineclonia.
|
The Noordstar caves mod helps add more caves to Minetest games.
|
||||||
|
|
||||||
For reference, see the [API documentation](API.md).
|
For reference, see the [API documentation](API.md).
|
||||||
|
|
||||||
This mod offers no new features to the player, but it allows programmers to add
|
This mod offers no new features to the player, but it allows programmers to add
|
||||||
custom caves into the world and to lower the world depth.
|
custom caves into the world and to lower the world depth.
|
||||||
|
|
||||||
## Tested & supported on
|
## Examples
|
||||||
|
|
||||||
The mod has been tested on the following games:
|
The following mods are known to use this cave generator mod:
|
||||||
|
|
||||||
- [x] VoxeLibre
|
- [ns_vl_caves](https://content.minetest.net/packages/Noordstar/ns_vl_caves/) for VoxeLibre & Mineclonia
|
||||||
- [ ] Mineclonia
|
|
||||||
- [ ] MTG
|
|
||||||
|
|
||||||
The mod has been tested on the following mapgens:
|
|
||||||
|
|
||||||
- [x] v7
|
|
||||||
- [ ] valleys
|
|
||||||
- [ ] carpathian
|
|
||||||
- [ ] v5
|
|
||||||
- [ ] flat
|
|
||||||
- [ ] fractal
|
|
||||||
- [ ] singlenode
|
|
||||||
|
|
25
init.lua
25
init.lua
|
@ -1,3 +1,28 @@
|
||||||
|
ns_cavegen_init = {}
|
||||||
|
|
||||||
|
-- Depending on the Minetest version, mapgen can be executed on the main thread
|
||||||
|
-- or on the separate thread.
|
||||||
|
|
||||||
|
-- Optionally, you can override this value.
|
||||||
|
local execute_in_mapgen_environment = false
|
||||||
|
|
||||||
|
function ns_cavegen_init.register_cavegen_script(file_name)
|
||||||
|
-- As of Minetest 5.9.0, a Minetest server can crash without notice when
|
||||||
|
-- a script is executed in the mapgen environment. This is likely related
|
||||||
|
-- to a memory leak error:
|
||||||
|
--
|
||||||
|
-- If you would like to override this setting, you can adjust the
|
||||||
|
-- "ns_cavegen_mapgen_environment" variable in your `minetest.conf` settings
|
||||||
|
-- file.
|
||||||
|
local use_mapgen_env = minetest.settings:get_bool("ns_cavegen_mapgen_environment", false)
|
||||||
|
|
||||||
|
if execute_in_mapgen_environment or use_mapgen_env then
|
||||||
|
minetest.register_mapgen_script(file_name)
|
||||||
|
else
|
||||||
|
dofile(file_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_mapgen_script(
|
minetest.register_mapgen_script(
|
||||||
minetest.get_modpath(minetest.get_current_modname()) .. "/script.lua"
|
minetest.get_modpath(minetest.get_current_modname()) .. "/script.lua"
|
||||||
)
|
)
|
21
script.lua
21
script.lua
|
@ -33,6 +33,20 @@ local WORLD_DEPTH = -60
|
||||||
|
|
||||||
local internal = {}
|
local internal = {}
|
||||||
|
|
||||||
|
function internal.init()
|
||||||
|
local uses_mapgen_env = minetest.save_gen_notify
|
||||||
|
|
||||||
|
if uses_mapgen_env then
|
||||||
|
minetest.register_on_generated(internal.mapgen)
|
||||||
|
else
|
||||||
|
minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||||
|
local vm = minetest.get_mapgen_object("voxelmanip")
|
||||||
|
internal.mapgen(vm, minp, maxp, blockseed)
|
||||||
|
vm:write_to_map()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-------------------------------- INTERNAL API ---------------------------------
|
-------------------------------- INTERNAL API ---------------------------------
|
||||||
|
@ -653,8 +667,13 @@ function internal.write_classified_node(vm_data, va, used_biomes, classified_nod
|
||||||
|
|
||||||
if ground_content_nodes[vm_node] == nil then
|
if ground_content_nodes[vm_node] == nil then
|
||||||
local name = minetest.get_name_from_content_id(content_id)
|
local name = minetest.get_name_from_content_id(content_id)
|
||||||
|
|
||||||
|
if minetest.registered_nodes[name] == nil then
|
||||||
|
ground_content_nodes[vm_node] = true
|
||||||
|
else
|
||||||
ground_content_nodes[vm_node] = minetest.registered_nodes[name].is_ground_content or true
|
ground_content_nodes[vm_node] = minetest.registered_nodes[name].is_ground_content or true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if ground_content_nodes[vm_node] then
|
if ground_content_nodes[vm_node] then
|
||||||
vm_data[vi] = content_id
|
vm_data[vi] = content_id
|
||||||
|
@ -887,7 +906,6 @@ end
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
minetest.register_on_generated(internal.mapgen)
|
|
||||||
|
|
||||||
ns_cavegen = {
|
ns_cavegen = {
|
||||||
cave_vastness = function(pos)
|
cave_vastness = function(pos)
|
||||||
|
@ -923,4 +941,5 @@ ns_cavegen = {
|
||||||
unregister_shape = internal.unregister_shape,
|
unregister_shape = internal.unregister_shape,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal.init()
|
||||||
-- dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/lua/register.lua")
|
-- dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/lua/register.lua")
|
Loading…
Reference in New Issue