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

41 Commits

Author SHA1 Message Date
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
6935e73994 Merge branch 'intllib_update' into 'master'
Replace deprecated call to 'intllib.Getter'

See merge request VanessaE/biome_lib!1
2018-11-25 23:54:02 +00:00
ad12e97281 Replace deprecated call to 'intllib.Getter' 2018-11-25 23:54:02 +00:00
7 changed files with 698 additions and 433 deletions

73
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
@ -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
@ -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,43 @@ 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.
Put these settings in your game's minetest.conf (or your client's own config,
if desired). You'll need to set all of them.
biome_lib_default_grow_through_nodes
Comma-separated list of things that a spawned node is allowed to grow
through. Air is always added to whatever you specify.
Default: air, default:snow
biome_lib_default_water_nodes
Comma-separated list of nodes that should be treated as water for the sake
of looking for neighboring "wet" ground.
Default: default:water_source, default:water_flowing,
default:river_water_source, default:river_water_flowing
biome_lib_default_wet_surfaces
Comma-separated list of nodes that should be considered "wet" if one of
the aforementioned water nodes is nearby.
Default: default:dirt, default:dirt_with_grass, default:sand
biome_lib_default_grow_nodes
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 for ALL growable nodes, if the calling
mod doesn't provide its own lists.
Default: "default:dirt_with_grass"
biome_lib_default_ground_nodes
Comma-separated list of nodes to use as the "root" of something that can
gradually climb up a wall, to be used for ALL such nodes, if the calling
mod doesn't provide its own lists.
Default: "default:dirt_with_grass"

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)

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

887
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

74
search_functions.lua Normal file
View File

@ -0,0 +1,74 @@
-- 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)
for x = 0, 4 do
local minx = minp.x + x*16
for y = 0, 4 do
local miny = minp.y + y*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 }
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, false }
end
end
end
biome_lib.run_block_recheck_list = true
end)