Ideas for a new leafdecay system

User avatar
Gael de Sailly
Member
 
Posts: 475
Joined: Sun Jan 26, 2014 17:01
GitHub: Gael-de-Sailly
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly

Ideas for a new leafdecay system

by Gael de Sailly » Thu Aug 04, 2016 12:14

Hello

I've always thought the leafdecay algorithm is one of the heaviest features of Minetest, since it's executed for hundreds of leaves every second, and that for every leaf, it needs to iterate over dozens of nodes.
I've seen that there is an optimization with trunk cache, but it still needs to iterate for many leaves.
I've an idea of a completely different method that may save time and allow bigger radius (up to 7), using param2.
The param2 for leaves is unused for now (except param2=1 for manually placed leaves).

My idea is to set a param2 for leaves. The param2 value can be converted into a relative position. The leafdecay algorithm consists in checking that a tree takes place at this position. So, every leaves block belongs to one tree. This solves a problem that I've very often seen: when you cut a trunk, the leaves falls, but if there is another tree next to it, most of the leaves don't fall.
My idea was to change the param2 values of schematics according to that. But a schematic can be placed at a random rotation. So a param2 value should match 4 positions (with 90° rotations) and we only have to iterate over 4 nodes.
This allows to spawn wider trees. It may slow down the mapgen, but not the leafdecay algorithm, since it has only 4 positions to check, no matter the radius.

I've made a test mod for that, with a modified pine tree schematic. You can see the code used to convert between param2 and vector, it's the function get_value in init.lua. It can handle an horizontal radius up to 7 (only the nearest are used for pine tree) and a vertical offset from -3 to +1. I've explained that in vector.txt.
Attachments
test.zip
Test mod for new leafdecay. You can rename it how you want. Run with minetest_game. Try to dig trees.
(2.81 KiB) Downloaded 111 times
Very busy this year too, so do not expect me to be very active on the forum or in game. But I'm not about to drop Minetest forever :)
 

User avatar
duane
Member
 
Posts: 776
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r

Re: Ideas for a new leafdecay system

by duane » Thu Aug 04, 2016 15:58

This sounds great. However, wouldn't it be simpler and more efficient to remove the abms altogether and make leaf decay an on_destruct function of tree-type nodes? The main reason for leaf decay is to keep people from having to clean up when they chop down a tree, and that's easy enough to deal with each time they remove a node.

There are two cases where this wouldn't work. First, leaves left hanging by the mapgen, but in most of these instances pieces of trunk are left in the air as well, so leaf decay is only marginally useful. Second, cases where you use voxelmanip or overwrite with a schematic. Even then, it might be worth leaving a few leaves to save the CPU time that an abm uses.
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: Ideas for a new leafdecay system

by BrandonReese » Thu Aug 04, 2016 16:13

duane wrote:This sounds great. However, wouldn't it be simpler and more efficient to remove the abms altogether and make leaf decay an on_destruct function of tree-type nodes?


That's an interesting avenue to explore. If you were to find all of the connected nodes that might not be very efficient. The other option would be to use find nodes in area to check an area for other tree nodes, and if no tree nodes are found then use find nodes in area to find all leaf nodes and decay them.
 

User avatar
duane
Member
 
Posts: 776
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r

Re: Ideas for a new leafdecay system

by duane » Thu Aug 04, 2016 16:35

Another question is -- how much time does leaf decay actually take at the moment? Even when I turn it completely off for every node, it doesn't seem to make much difference on my system.
 

User avatar
Gael de Sailly
Member
 
Posts: 475
Joined: Sun Jan 26, 2014 17:01
GitHub: Gael-de-Sailly
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly

Re: Ideas for a new leafdecay system

by Gael de Sailly » Thu Aug 04, 2016 17:07

The reason is not only to save time. It should improve the way leaves are removed. Instead of removing the leaves that are at more than n nodes from the trunk, it removes leaves that have been spawned with the tree, even if they are close to another tree, so it better respects the shape of the nearby trees, instead of leaving an ugly square of leaves next to the tree. In fact, that's the most important thing for me. The time saving argument has only made me think about it.
Very busy this year too, so do not expect me to be very active on the forum or in game. But I'm not about to drop Minetest forever :)
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: Ideas for a new leafdecay system

by BrandonReese » Thu Aug 04, 2016 17:07

duane wrote:Another question is -- how much time does leaf decay actually take at the moment? Even when I turn it completely off for every node, it doesn't seem to make much difference on my system.


Last time I ran a profiler I don't remember it being toward the top.
 

twoelk
Member
 
Posts: 1092
Joined: Fri Apr 19, 2013 16:19

Re: Ideas for a new leafdecay system

by twoelk » Thu Aug 04, 2016 18:24

some trees do sort of huddle together. So do we get a tree-cadastre?

Image
some jungle trees in disguise from this post
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Ideas for a new leafdecay system

by burli » Thu Aug 04, 2016 19:11

If leaves replace the leaves from another tree and then you remove the tree, the other tree gets destroyed.

So, attaching leaves to a tree doesn't work, IMHO
 

User avatar
TG-MyinaWD
Member
 
Posts: 355
Joined: Thu May 08, 2014 21:22
GitHub: Maddie-Myina
IRC: Maddie-Myina
In-game: .

Re: Ideas for a new leafdecay system

by TG-MyinaWD » Fri Aug 05, 2016 01:06

I always thought of why in the first place we can dig the leaves and retrieve them. In my minetest subgame Idea I removed doing so. Then again I had a idea how about when the tree is removed it causes the leaves to far like gravel and sand but have it a flat height (1/16) and they will set there forevermore and change color according to humanity setup. And one to get leaves will need a Trimmer or a Rake (if on ground). However I have no idea how do all this so.. I staying with remove cannot retrieve leaves.

But overall we need maybe a way leaves decay from not getting water maybe too.
I'm a Transgender no shame about it.
I prefer to be considered as a "Girl/Lady/Miss/Madam/Female" for now on.
 

User avatar
duane
Member
 
Posts: 776
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r

Re: Ideas for a new leafdecay system

by duane » Fri Aug 05, 2016 01:31

Gael de Sailly wrote:The reason is not only to save time. It should improve the way leaves are removed. Instead of removing the leaves that are at more than n nodes from the trunk, it removes leaves that have been spawned with the tree, even if they are close to another tree, so it better respects the shape of the nearby trees, instead of leaving an ugly square of leaves next to the tree. In fact, that's the most important thing for me. The time saving argument has only made me think about it.


If you have a schematic that over-writes one tree with another, which probably happens a lot in the mapgen, wouldn't you still get ugly holes when you remove the newer of the two?
 

User avatar
Gael de Sailly
Member
 
Posts: 475
Joined: Sun Jan 26, 2014 17:01
GitHub: Gael-de-Sailly
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly

Re: Ideas for a new leafdecay system

by Gael de Sailly » Fri Aug 05, 2016 08:34

duane wrote:If you have a schematic that over-writes one tree with another, which probably happens a lot in the mapgen, wouldn't you still get ugly holes when you remove the newer of the two?

I've seen it but for me it's not worse than previously.
With the current minetest_game leafdecay, in a very dense forest, if you dig a tree, you don't get any leaves.
With this new leafdecay, it will still make a hole in the forest (what is expected).
It's normal that, when you cut a tree that is very close to another, this other tree has not its own shape. But I've not really seen "big holes". The fact that a param2 matches 4 positions means that some leaves (mostly those who are between 2 trees) are attached to 2 or more trees, and so will not disappear if you dig one of these trees.
Very busy this year too, so do not expect me to be very active on the forum or in game. But I'm not about to drop Minetest forever :)
 

User avatar
Gael de Sailly
Member
 
Posts: 475
Joined: Sun Jan 26, 2014 17:01
GitHub: Gael-de-Sailly
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly

Re: Ideas for a new leafdecay system

by Gael de Sailly » Fri Aug 05, 2016 08:43

duane wrote:Wouldn't it be simpler and more efficient to remove the abms altogether and make leaf decay an on_destruct function of tree-type nodes?

Very interesting too.
Very busy this year too, so do not expect me to be very active on the forum or in game. But I'm not about to drop Minetest forever :)
 

User avatar
duane
Member
 
Posts: 776
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r

Re: Ideas for a new leafdecay system

by duane » Sat Aug 06, 2016 00:37

BrandonReese wrote:
duane wrote:This sounds great. However, wouldn't it be simpler and more efficient to remove the abms altogether and make leaf decay an on_destruct function of tree-type nodes?


That's an interesting avenue to explore. If you were to find all of the connected nodes that might not be very efficient. The other option would be to use find nodes in area to check an area for other tree nodes, and if no tree nodes are found then use find nodes in area to find all leaf nodes and decay them.


I'll probably play with it a bit, but the only advantage is time, and it seems like that's not much of an issue. Now, if I could find a way to make mobs more efficient, that would be worthwhile.
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

Re: Ideas for a new leafdecay system

by Sokomine » Wed Aug 10, 2016 23:59

The idea sounds very intresting. Some additional information as to which tree trunk a particular leaf thinks it belongs to would make lumberjack mods (cut the whole tree including leaves) more efficient and leave less leaves floating around. Leaf decay can be very slow at times on servers.
A list of my mods can be found here.
 

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

Re: Ideas for a new leafdecay system

by SegFault22 » Thu Aug 25, 2016 06:11

duane wrote:the only advantage is time

...
Gael de Sailly wrote:The leafdecay algorithm consists in checking that a tree takes place at this position. So, every leaves block belongs to one tree. This solves a problem that I've very often seen: when you cut a trunk, the leaves falls, but if there is another tree next to it, most of the leaves don't fall.

Is this not also an advantage?
 

User avatar
duane
Member
 
Posts: 776
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r

Re: Ideas for a new leafdecay system

by duane » Thu Aug 25, 2016 07:55

SegFault22 wrote:
duane wrote:the only advantage is time

...
Gael de Sailly wrote:The leafdecay algorithm consists in checking that a tree takes place at this position. So, every leaves block belongs to one tree. This solves a problem that I've very often seen: when you cut a trunk, the leaves falls, but if there is another tree next to it, most of the leaves don't fall.

Is this not also an advantage?


I was referring to my idea sucking, not the original post.
 

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

Re: Ideas for a new leafdecay system

by SegFault22 » Fri Aug 26, 2016 14:59

duane wrote:
SegFault22 wrote: ~ka-snip~


I was referring to my idea sucking, not the original post.

Oh. Okay, then, that's all good.
 

User avatar
Casimir
Member
 
Posts: 1101
Joined: Fri Aug 03, 2012 16:59

Re: Ideas for a new leafdecay system

by Casimir » Sun Sep 04, 2016 21:13

For Voxelgarden I made some time ago a slightly different leafdecay. It work like nodeupdate in that it checks for surrounding nodes. Sparked by this discussion I also added a callback to run leafupdate after a tree was dug.
It's fast, and the abm only needs to run with an interval of 5 and chance of 90 (compared to 2 and 5 in MTG). However it leaves sometimes large chuncks of leaves in the air which only decay after a longer waiting period.
 

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

Re: Ideas for a new leafdecay system

by SegFault22 » Tue Sep 06, 2016 20:18

I like the trees to instantly "fall" when the bottom node is cut with an axe (all tree-trunk-block nodes turn to items and fall, all leaf-blocks decay instantly and some drop saplings) - however, when you have two or more trees close together, the leaves can interfere, and half of the leaves on one tree (or worse, all of them on all connected trees) will be cut as well. Assigning metadata to each leaf-block telling what tree-node(s) are connected, will solve this problem; maybe its also possible for the metadata of outer leaf blocks to reference the inner leaf blocks, that way when you remove the inner leaf blocks, the outer ones decay instead of just floating there around the tree-trunk.
 

gpcf
Member
 
Posts: 57
Joined: Fri May 27, 2016 10:48
In-game: gabriel

Re: Ideas for a new leafdecay system

by gpcf » Mon Oct 24, 2016 13:25

I like SegFault's idea. I'm going to implement this for the moretrees mod, every tree should get an Id assigned (maybe the tree's position) and when one trunk node is chopped down in that tree, the entire tree with that id decays.
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 5 guests

cron