Ideas for a new leafdecay system
- Gael de Sailly
- Member
- Posts: 845
- Joined: Sun Jan 26, 2014 17:01
- GitHub: gaelysam
- IRC: Gael-de-Sailly
- In-game: Gael-de-Sailly gaelysam
- Location: Voiron, France
Ideas for a new leafdecay system
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.
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 55 times
Just realize how bored we would be if the world was perfect.
- duane
- Member
- Posts: 1715
- Joined: Wed Aug 19, 2015 19:11
- GitHub: duane-r
- Location: Oklahoma City
- Contact:
Re: Ideas for a new leafdecay system
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.
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.
Believe in people and you don't need to believe anything else.
- BrandonReese
- Member
- Posts: 839
- Joined: Wed Sep 12, 2012 00:44
- GitHub: bremaweb
- IRC: BrandonReese
- In-game: BrandonReese
- Location: USA
Re: Ideas for a new leafdecay system
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.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?
- duane
- Member
- Posts: 1715
- Joined: Wed Aug 19, 2015 19:11
- GitHub: duane-r
- Location: Oklahoma City
- Contact:
Re: Ideas for a new leafdecay system
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.
Believe in people and you don't need to believe anything else.
- Gael de Sailly
- Member
- Posts: 845
- Joined: Sun Jan 26, 2014 17:01
- GitHub: gaelysam
- IRC: Gael-de-Sailly
- In-game: Gael-de-Sailly gaelysam
- Location: Voiron, France
Re: Ideas for a new leafdecay system
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.
Just realize how bored we would be if the world was perfect.
- BrandonReese
- Member
- Posts: 839
- Joined: Wed Sep 12, 2012 00:44
- GitHub: bremaweb
- IRC: BrandonReese
- In-game: BrandonReese
- Location: USA
Re: Ideas for a new leafdecay system
Last time I ran a profiler I don't remember it being toward the top.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.
-
- Member
- Posts: 1482
- Joined: Fri Apr 19, 2013 16:19
- GitHub: twoelk
- IRC: twoelk
- In-game: twoelk
- Location: northern Germany
Re: Ideas for a new leafdecay system
some trees do sort of huddle together. So do we get a tree-cadastre?
some jungle trees in disguise from this post
some jungle trees in disguise from this post
Re: Ideas for a new leafdecay system
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
So, attaching leaves to a tree doesn't work, IMHO
-
- Member
- Posts: 356
- Joined: Thu May 08, 2014 21:22
- GitHub: Maddie-Myina
- IRC: Maddie-Myina
- In-game: .
- Location: Far Eden
Re: Ideas for a new leafdecay system
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.
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.
I prefer to be considered as a "Girl/Lady/Miss/Madam/Female" for now on.
- duane
- Member
- Posts: 1715
- Joined: Wed Aug 19, 2015 19:11
- GitHub: duane-r
- Location: Oklahoma City
- Contact:
Re: Ideas for a new leafdecay system
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?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.
Believe in people and you don't need to believe anything else.
- Gael de Sailly
- Member
- Posts: 845
- Joined: Sun Jan 26, 2014 17:01
- GitHub: gaelysam
- IRC: Gael-de-Sailly
- In-game: Gael-de-Sailly gaelysam
- Location: Voiron, France
Re: Ideas for a new leafdecay system
I've seen it but for me it's not worse than previously.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?
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.
Just realize how bored we would be if the world was perfect.
- Gael de Sailly
- Member
- Posts: 845
- Joined: Sun Jan 26, 2014 17:01
- GitHub: gaelysam
- IRC: Gael-de-Sailly
- In-game: Gael-de-Sailly gaelysam
- Location: Voiron, France
Re: Ideas for a new leafdecay system
Very interesting too.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?
Just realize how bored we would be if the world was perfect.
- duane
- Member
- Posts: 1715
- Joined: Wed Aug 19, 2015 19:11
- GitHub: duane-r
- Location: Oklahoma City
- Contact:
Re: Ideas for a new leafdecay system
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.BrandonReese wrote: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.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?
Believe in people and you don't need to believe anything else.
-
- Member
- Posts: 4276
- Joined: Sun Sep 09, 2012 17:31
- GitHub: Sokomine
- IRC: Sokomine
- In-game: Sokomine
Re: Ideas for a new leafdecay system
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.
- SegFault22
- Member
- Posts: 872
- Joined: Mon May 21, 2012 03:17
- Location: NaN
Re: Ideas for a new leafdecay system
...duane wrote:the only advantage is time
Is this not also an advantage?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.
- duane
- Member
- Posts: 1715
- Joined: Wed Aug 19, 2015 19:11
- GitHub: duane-r
- Location: Oklahoma City
- Contact:
Re: Ideas for a new leafdecay system
I was referring to my idea sucking, not the original post.SegFault22 wrote:...duane wrote:the only advantage is timeIs this not also an advantage?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.
Believe in people and you don't need to believe anything else.
- SegFault22
- Member
- Posts: 872
- Joined: Mon May 21, 2012 03:17
- Location: NaN
Re: Ideas for a new leafdecay system
Oh. Okay, then, that's all good.duane wrote:I was referring to my idea sucking, not the original post.SegFault22 wrote: ~ka-snip~
- Casimir
- Member
- Posts: 1206
- Joined: Fri Aug 03, 2012 16:59
- GitHub: CasimirKaPazi
Re: Ideas for a new leafdecay system
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.
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.
- SegFault22
- Member
- Posts: 872
- Joined: Mon May 21, 2012 03:17
- Location: NaN
Re: Ideas for a new leafdecay system
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.
Re: Ideas for a new leafdecay system
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.
Play on Linuxworks server. We have got lots of trains.
My mods (Industrial Livestock Farming, Farebox and Faregate, Moving Walkways, Atm)
My mods (Industrial Livestock Farming, Farebox and Faregate, Moving Walkways, Atm)
Who is online
Users browsing this forum: Google [Bot] and 3 guests