1
0
mirror of https://github.com/mt-mods/biome_lib.git synced 2025-06-28 22:36:44 +02:00

54 Commits

Author SHA1 Message Date
bf2ac2ea57 don't nil-out the recheck list, just empty it. 2021-04-16 13:06:24 -04:00
6342a16b0a Reign-in the default on-generated limit from +/- 31k to -16/+48m
since nothing much is normally found outside that range anyway

only enqueue blocks that are within that range, or within
the range specfied by all of the mods that make generate_plant() calls,
whichever covers more volume.
2021-04-16 13:02:54 -04:00
c6cd524f62 fix reporting of log sizes during shutdown 2021-04-16 12:06:52 -04:00
2dbacae561 remove mapblocks from the queue early if they have no surfaces to work on
(sadly can't be done for blocks in the deferred queue until
they come out of "idle")
2021-04-16 12:02:13 -04:00
f165434a84 change the queue ratio config setting
to avoid breaking old configs
also increase the default amount of work done per tick.
2021-04-16 10:41:38 -04:00
d6cba18844 add a mention in the readme about the mod's config settings 2021-04-16 10:39:17 -04:00
f003f19998 add a proper settingtypes.txt 2021-04-10 06:01:01 -04:00
d06ab90e01 allow re-check-log entries to time out gradually rather than
having to go all at once.  This purges the log sooner than before,
but without damaging the mapgen results.
2021-04-09 13:26:42 -04:00
ba46e6c05e Report the mod's progress and ETA
while purging the mapblock log at shutdown
2021-04-09 12:38:09 -04:00
ed0b23677d fix typo 2021-04-08 08:09:59 -04:00
3b35fc67c6 Periodically re-trigger the mapblock queue code if it's idle,
to give old, deferrred blocks a chance to time-out.  Needed
because if players aren't currently creating new terrain,
old blocks would never get processed, causing the block log
to only grow rather than eventually run dry (which could result
in very long shutdown times).
2021-04-08 06:33:43 -04:00
eabc053c05 If a block has to be re-checked, renew its timestamp 2021-04-07 09:12:57 -04:00
dd650da443 Allow old blocks to time-out after a while
(default 5 minutes).

Rationale: if a block is old enough, there's a very high probability
that the engine's done screwing around with its neighbors, so it's safe
to process.
2021-04-07 07:41:48 -04:00
0a34e3c7af rename debug variable and option for consistency
make global so it can be changed while running
2021-04-07 07:41:32 -04:00
07c2b1d9d4 move all settings at the top of the code
(some were scattered here and there)
2021-04-07 07:13:53 -04:00
1dc0febd8c print a message when the queue goes idle. 2021-04-07 05:26:31 -04:00
50f921a85a implement variable log levels
so that one need not see all the spammy stuff
if the only things of interest are e.g. warnings
2021-04-07 05:16:11 -04:00
6009f261c2 make sure that any block about to be scanned is definitely loaded (in
case the engine has unloaded the block because the player wandered off
for too long)
2021-04-07 04:55:57 -04:00
531577afcf rather than copy the re-check log back into the block log when it comes
time to run through it, just use it in-place, copying its entries back
to the main block log if they have to be skipped again (essentially
using the re-check list and the end of the block log as a double buffer)
2021-04-07 01:44:31 -04:00
e346fd599f rather than rearranging the block log to deal with blocks that can't be
populated yet, move those blocks to a separate list, and replay that
list whenever new mapblocks come in.  That way the main block list can
run dry and allow the block populate routines to go idle.

Thanks to Warr1024 for the idea!
2021-04-06 16:09:50 -04:00
212024a9b4 tiny optimization 2021-04-06 13:38:43 -04:00
1d2593f022 if the block list is empty, don't try to start another batch of actions. 2021-04-06 13:08:43 -04:00
3bc8737e2d make sure the target mapblock and all 8 of its corner neighbors have
been generated before populating the block (else move the target block
the end of the queue)

Thanks to Warr1024 for this idea!
2021-04-06 12:47:05 -04:00
0ea4cb3848 don't bother checking dtime during globalstep
it's enough to rely in the run ratio.
2021-04-06 10:00:16 -04:00
bef0a0d87e oops, forgot to allow for no-air-check blocks 2021-04-06 04:19:57 -04:00
89ca62e492 added a bunch of debugging info 2021-04-06 03:20:14 -04:00
a325c2ccd8 rewrote block queue handlers to reduce code duplication
and improve lag management

minetest.conf settings added:

biome_lib_dtime_limit:

Maximum lag allowed, in seconds.  Default 0.5s.  Larger values allow for
more lag, but make map updates run a bit faster.

biome_lib_queue_run_ratio:

If positive, this is the approximate number of globalstep ticks to skip
between map updates. If negative, it becomes the positive number of map
updates to run per globalstep tick before lag is checked.  No minimum
value, maximum +100.  Default: -100 (that is, 100 updates per globalstep
tick, with none intentionally skipped).  Use positive numbers for slow
machines or biome_lib-using mods that tend to cause lag, and negative
values for fast machines and mods.
2021-04-06 03:20:12 -04:00
8ecb401309 fix a couple of missing = signs 2021-04-05 12:44:21 -04:00
9ed4858518 take the integer of that last division I added
always round up.  otherwise it'll break the `for` loop
if a mod supplies a value not divisible by 25 :-)
2021-04-01 09:02:41 -04:00
26dbbb5a67 since we split to mapblocks now,
biome.max_count as received from mods has to be scaled appropriately
as mods expect this value to be relative to the usual
chunk size of 80x80 = 6400 nodes' horizontal area.
2021-04-01 08:32:45 -04:00
ec0a0f0c3b add some debugging messages 2021-04-01 07:18:28 -04:00
e92361675f remove the old-plantslib-api compat thing 2021-04-01 06:24:09 -04:00
7f1fec6ae0 add compatibility for games other than minetest_game 2021-04-01 05:47:22 -04:00
f569bb1fbd fix outdated "plantlife" message
and some redundancy
2021-04-01 05:03:29 -04:00
f2a807b814 make debug mode a proper minetest.conf setting 2021-04-01 05:02:07 -04:00
9b7705c380 move the "registered N actions on M surfaces" message to debug 2021-04-01 04:59:57 -04:00
c9f6235815 Add a function to print active/pending block counts to debug 2021-04-01 04:50:03 -04:00
ddd88613e0 trim some blank lines 2021-04-01 04:34:07 -04:00
27cd07cb36 Fix overlap in the split-to-blocks feature 2021-04-01 04:33:53 -04:00
ac8738d837 use mod.conf instead of depends.txt 2021-03-29 19:56:09 -04:00
0005af6022 fix my name 2021-03-29 19:53:26 -04:00
228296411e split generated map chunks into mapblock-sized pieces as they're logged
to reduce lag/latency at a tiny cost of overall throughput.
2021-03-29 05:19:52 -04:00
353ca0cbd4 optimize some blocklist/actionlist checks 2021-03-28 23:10:31 -04:00
d65c72d48b don't need the old non-air-above find nodes call anymore
only very old minetest engine lacks the air-above api call
2021-03-25 19:27:38 -04:00
10a1089767 add minimum minetest version key for contentdb 2020-06-03 13:00:01 -04:00
5a910875af fix deprecated function call 2020-04-15 16:59:40 -04:00
a96f015ce9 properly-limit abm-based growth to just the proper surfaces
(if no surface list is given, just grow on anything)
2019-05-22 20:02:30 -04:00
d72e15f1d0 get rid of old junglegrass -> dry shrub "corner case" 2019-05-22 19:28:13 -04:00
29899f2d36 Fix call to nil (function) vector.copy
Either vector.new or table.copy
NOT LIKE THIS
2019-01-07 19:37:16 +01:00
0837ff7fd2 Sync with world temperature if available 2019-01-02 23:08:07 +01:00
ff9ce531d6 Cleanup ABM callback 2019-01-02 22:29:59 +01:00
fa304f9d18 Fixes 2019-01-02 22:06:07 +01:00
b7d69a8487 Split code and tidy up
Split to growth.lua and search_functions.lua
New function populate_single_surface for a single position check
Use 'return' to reduce indent levels
2019-01-02 20:35:39 +01:00
f056d6d76e add descriptive names to ABM calls
can be specified by label= in the biome table
else biome_lib will try to make up something useful
fix #1
2018-12-01 10:51:18 -05:00
8 changed files with 829 additions and 453 deletions

56
API.txt
View File

@ -72,6 +72,7 @@ biome = {
---- most likely want to use at least some of these to limit how and
---- where your objects are spawned.
label = string, -- set this to identify the ABM for Minetest's profiler
avoid_nodes = {table}, -- same meaning as savoid, above
avoid_radius = num, -- same as sradius
seed_diff = num, -- The Perlin seed difference value passed to the
@ -111,9 +112,9 @@ biome = {
depth_max = num, -- If the object spawns on top of a water source, the
-- water must be at most this deep. Defaults to 1.
min_elevation = num, -- Surface must be at this altitude or higher to
-- spawn at all. Defaults to -31000...
max_elevation = num, -- ...but must be no higher than this altitude.
-- Defaults to +31000.
-- spawn at all. Defaults to -16 meters.
max_elevation = num, -- Surface must be no higher than this altitude.
-- Defaults to +48.
near_nodes = {table}, -- List of nodes that must be somewhere in the
-- vicinity in order for the plant to spawn. Can also
-- be a string with a single node name. If not
@ -238,7 +239,7 @@ biome = {
---- Everything else is optional, but you'll definitely want to use
---- some of these other fields to limit where and under what
---- conditions the objects are spawned.
below_nodes = {table}, -- List of nodes that must be below the target
-- node. Useful in snow biomes to keep objects from
-- spawning in snow that's on the wrong surface for
@ -269,8 +270,8 @@ biome = {
depth = num, -- How deep/thick of a layer the spawned-on node must
-- be. Typically used for water.
min_elevation = num, -- Minimum elevation in meters/nodes. Defaults to
-- -31000 (unlimited).
max_elevation = num, -- Max elevation. Defaults to +31000 (unlimited).
-- -16 meters.
max_elevation = num, -- Max elevation. Defaults to +48m.
near_nodes = {table}, -- what nodes must be in the general vicinity of the
-- object being spawned.
near_nodes_size = num, -- how wide of a search area to look for the nodes
@ -342,14 +343,18 @@ into something else over time. This function has no return value, and accepts
a biome definition table as the only parameter. These are defined like so:
options = {
grow_plant = "string", -- Name of the node to be grown into something
-- else. This value is passed to the ABM as the
-- "nodenames" parameter, so it is the plants
-- themselves that are the ABM trigger, rather than
label = string, -- set this to identify the ABM for Minetest's
-- profiler. If not set, biome_lib will set it to
-- "biome_lib grow_plants(): " appended with the node
-- in grow_plant (or the first item if it's a table)
grow_plant = "string" or {table}, -- Name(s) of the node(s) to be grown
-- into something else. This value is passed to the
-- ABM as the "nodenames" parameter, so the plants
-- themselves are the ABM trigger, rather than
-- the ground they spawned on. A plant will only grow
-- if the node above it is air. Can also be a table,
-- but note that all nodes referenced therein will be
-- grown into the same object.
-- if the node above it is air. If you use a table,
-- note that all nodes referenced therein will be
-- grown into the same final object.
grow_delay = num, -- Passed as the ABM "interval" parameter, as with
-- spawning.
grow_chance = num, -- Passed as the ABM "chance" parameter.
@ -441,12 +446,22 @@ question is already loaded, or false if not.
=====
dbg(string)
dbg(string, level)
This is a simple debug output function which takes one string parameter. It
just checks if DEBUG is true and outputs the phrase "[Plantlife] " followed by
the supplied string, via the print() function, if so.
'level' is a number that, if supplied, dictates the lowest 'biome_lib_debug'
can be set to in minetest.conf for this message to be displayed. Both the
default log level and the default message level are 0, thus always showing the
supplied message.
Although it's not set in stone, a good practice is to use a level of 0 (or
just omit the value) for anything that generally important enough that it
ought always be shown, 1 for errors, 2 for warnings, 3 for info, 4 for verbose
spammy stuff.
=====
biome_lib:generate_tree(pos, treemodel)
biome_lib:grow_tree(pos, treemodel)
@ -583,3 +598,16 @@ And this particular one is mapped slightly differently from the others:
(Note the +150 and +50 offsets)
==================
Default game nodes
==================
Although this project was intended to be used with minetest_game, it can be
configured to work with something else instead. All you need to do is provide
the names of the nodes in your game you want biome_lib's internals to use.
See settingtypes.txt for a list. Any item listed there can be changed either
by adding it to your minetest.conf, or by using the "all settings" menu in
Minetest, whatever's appropriate for your particular setup.

View File

@ -12,7 +12,7 @@ Both mapgen-based spawning and ABM-based spawning is supported. Growing code is
It is primarily intended for mapgen v6, but it should work fine when used with mapgen v7.
**Dependencies**: default from minetest_game
**Dependencies:** nothing, but if you don't use `minetest_game`, you'll need to supply some settings (see API.txt).
**Recommends**: [Plantlife Modpack](https://github.com/minetest-mods/plantlife_modpack),
[More Trees](https://github.com/minetest-mods/moretrees)
@ -25,4 +25,6 @@ It is primarily intended for mapgen v6, but it should work fine when used with m
* biome_lib:find_valid_wall()
* biome_lib:is_node_loaded()
For a complete description of these functions as well as several of the internal variables within the mod, [read the API.txt document](https://raw.githubusercontent.com/minetest-mods/biome_lib/master/API.txt) included in this package.
For a complete description of these functions as well as several of the internal variables within the mod, see `API.txt`.
**Configuration:** This mod has several variables you can set in your `minetest.conf` to change things a bit, from the default nodes it uses, to the debug log level and the block queue behavior. For a list with complete descriptions, see `settingtypes.txt`.

View File

@ -1,3 +0,0 @@
default
intllib?

90
growth.lua Normal file
View File

@ -0,0 +1,90 @@
local time_scale = ...
-- The growing ABM
function biome_lib.check_surface(name, nodes)
if not nodes then return true end
if type(nodes) == "string" then return nodes == name end
if nodes.set and nodes[name] then
return true
else
for _, n in ipairs(nodes) do
if name == n then return true end
end
end
return false
end
function biome_lib:grow_plants(opts)
local options = opts
options.height_limit = options.height_limit or 5
options.ground_nodes = options.ground_nodes or biome_lib.default_ground_nodes
options.grow_nodes = options.grow_nodes or biome_lib.default_grow_nodes
options.seed_diff = options.seed_diff or 0
local n
if type(options.grow_plant) == "table" then
n = "multi: "..options.grow_plant[1]..", ..."
else
n = options.grow_plant
end
options.label = options.label or "biome_lib grow_plants(): "..n
if options.grow_delay*time_scale >= 1 then
options.interval = options.grow_delay*time_scale
else
options.interval = 1
end
minetest.register_abm({
nodenames = { options.grow_plant },
interval = options.interval,
chance = options.grow_chance,
label = options.label,
action = function(pos, node, active_object_count, active_object_count_wider)
local p_top = {x=pos.x, y=pos.y+1, z=pos.z}
local p_bot = {x=pos.x, y=pos.y-1, z=pos.z}
local n_top = minetest.get_node(p_top)
local n_bot = minetest.get_node(p_bot)
local root_node = minetest.get_node({x=pos.x, y=pos.y-options.height_limit, z=pos.z})
local walldir = nil
if options.need_wall and options.verticals_list then
walldir = biome_lib:find_adjacent_wall(p_top, options.verticals_list, options.choose_random_wall)
end
if biome_lib.default_grow_through_nodes[n_top.name]
and (not options.need_wall or (options.need_wall and walldir)) then
if options.grow_vertically and walldir then
if biome_lib:search_downward(pos, options.height_limit, options.ground_nodes) then
minetest.swap_node(p_top, { name = options.grow_plant, param2 = walldir})
end
elseif biome_lib.check_surface(n_bot.name, options.grow_nodes) then
if not options.grow_result and not options.grow_function then
minetest.swap_node(pos, biome_lib.air)
else
biome_lib:replace_object(pos, options.grow_result, options.grow_function, options.facedir, options.seed_diff)
end
end
end
end
})
end
-- spawn_tree() on generate is routed through here so that other mods can hook
-- into it.
function biome_lib:generate_tree(pos, nodes_or_function_or_model)
minetest.spawn_tree(pos, nodes_or_function_or_model)
end
-- and this one's for the call used in the growing code
function biome_lib:grow_tree(pos, nodes_or_function_or_model)
minetest.spawn_tree(pos, nodes_or_function_or_model)
end

994
init.lua

File diff suppressed because it is too large Load Diff

View File

@ -1 +1,3 @@
name = biome_lib
min_minetest_version = 5.2.0
optional_depends = default, intllib

83
search_functions.lua Normal file
View File

@ -0,0 +1,83 @@
-- function to decide if a node has a wall that's in verticals_list{}
-- returns wall direction of valid node, or nil if invalid.
function biome_lib:find_adjacent_wall(pos, verticals, randomflag)
local verts = dump(verticals)
if randomflag then
local walltab = {}
if string.find(verts, minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name) then walltab[#walltab + 1] = 3 end
if string.find(verts, minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name) then walltab[#walltab + 1] = 2 end
if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z-1 }).name) then walltab[#walltab + 1] = 5 end
if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z+1 }).name) then walltab[#walltab + 1] = 4 end
if #walltab > 0 then return walltab[math.random(1, #walltab)] end
else
if string.find(verts, minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name) then return 3 end
if string.find(verts, minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name) then return 2 end
if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z-1 }).name) then return 5 end
if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z+1 }).name) then return 4 end
end
return nil
end
-- Function to search downward from the given position, looking for the first
-- node that matches the ground table. Returns the new position, or nil if
-- height limit is exceeded before finding it.
function biome_lib:search_downward(pos, heightlimit, ground)
for i = 0, heightlimit do
if string.find(dump(ground), minetest.get_node({x=pos.x, y=pos.y-i, z = pos.z}).name) then
return {x=pos.x, y=pos.y-i, z = pos.z}
end
end
return false
end
function biome_lib:find_open_side(pos)
if minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name == "air" then
return {newpos = { x=pos.x-1, y=pos.y, z=pos.z }, facedir = 2}
end
if minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name == "air" then
return {newpos = { x=pos.x+1, y=pos.y, z=pos.z }, facedir = 3}
end
if minetest.get_node({ x=pos.x, y=pos.y, z=pos.z-1 }).name == "air" then
return {newpos = { x=pos.x, y=pos.y, z=pos.z-1 }, facedir = 4}
end
if minetest.get_node({ x=pos.x, y=pos.y, z=pos.z+1 }).name == "air" then
return {newpos = { x=pos.x, y=pos.y, z=pos.z+1 }, facedir = 5}
end
return nil
end
-- "Record" the map chunks being generated by the core mapgen,
-- split into individual mapblocks to reduce lag
minetest.register_on_generated(function(minp, maxp, blockseed)
local timestamp = minetest.get_us_time()
for y = 0, 4 do
local miny = minp.y + y*16
if miny >= biome_lib.mapgen_elevation_limit.min
and (miny + 15) <= biome_lib.mapgen_elevation_limit.max then
for x = 0, 4 do
local minx = minp.x + x*16
for z = 0, 4 do
local minz = minp.z + z*16
local bmin = {x=minx, y=miny, z=minz}
local bmax = {x=minx + 15, y=miny + 15, z=minz + 15}
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, true, timestamp }
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, false, timestamp }
end
end
else
biome_lib.dbg("Did not enqueue mapblocks at elevation "..miny.."m, they're out of range of any generate_plant() calls.", 4)
end
end
biome_lib.run_block_recheck_list = true
end)

48
settingtypes.txt Normal file
View File

@ -0,0 +1,48 @@
# Comma-separated list of things that a spawned node is allowed to grow
# through. Air is always added to whatever else you specify here.
biome_lib_default_grow_through_nodes (List of things a plant can grow through) string default:snow
# Comma-separated list of nodes that should be treated as water or water-like
# for the sake of looking for neighboring wet ground.
biome_lib_default_water_nodes (List of "water-like" sources) string default:water_source,default:water_flowing,default:river_water_source,default:river_water_flowing
# Comma-separated list of nodes that should be considered "wet" if one of
# the configured "water-like" sources is nearby.
biome_lib_default_wet_surfaces (List of "wet" nodes) string default:dirt,default:dirt_with_grass,default:sand
# Comma-separated list of nodes that something must be sitting on to be
# able to actively change from one thing to another (such as a sapling
# growing into a tree), to be used if the mod that added that growable
# thing didn't provide its own list of suitable surfaces.
biome_lib_default_grow_nodes (List of default surfaces a plant can thrive on) string default:dirt_with_grass
# Comma-separated list of nodes to use as the "root" of something that can
# gradually climb up a wall (such as ivy), to be used if the mod that added
# the climing thing didn't provide its own list.
biome_lib_default_ground_nodes (List of default root nodes) string default:dirt_with_grass
# biome_lib divides its workload into "actions", as dictated by the sum
# total of all mods that use it, and this sets how much of that work is done
# per globalstep tick. If positive, a single action is executed on that
# percentage of ticks, on average. If negative, it becomes positive, and
# that many actions are executed on every single tick, skipping none.
# More negative means more throughput, at the expense of lag. On fast PC's,
# a setting of between -500 and -2000 might be good.
biome_lib_queue_ratio (Queue run ratio) int -200
# Minetest's map generator allows neighboring areas to overflow into one
# another, to create smooth terrain, but it often hands the map blocks that
# comprise those areas to Lua (and hence, to biome_lib) before that overflow
# function happens, which causes the mapgen to overwrite whatever Lua does
# to them. This setting (in seconds) makes biome_lib wait before adding its
# normal output to those map blocks, to give the engine plenty of time to
# run that overflow feature first.
biome_lib_block_timeout (Deferred block timeout) int 300
# This does just what it sounds like - it shows all debug output that's sent
# with a level equal to or greater than this value. A setting of 0 shows only
# the bare necessities, such as the startup and shutdown messages, 1 adds
# internal non-fatal errors to what's shown, 2 adds warnings, 3 adds other
# basic info, 4 adds all the verbose debugging spew. 3 is perhaps the most
# useful setting.
biome_lib_debug_log_level (Debug log level) int 0