Leafdecay changes: Changes needed in tree mods

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Leafdecay changes: Changes needed in tree mods

by paramat » Sat Feb 25, 2017 04:26

The leafdecay ABM has been removed from Minetest Game and replaced with an API using event-based decay: decay only happens around a trunk node when that node is removed.
You will need to edit your tree mods to register leafdecay for each tree type, details are below and in game_api.txt.
Apologies for the disruption, we think is it is worth it to finally remove this ABM.

Originally leafdecay used a 'trunk cache' to try to reduce processing, this was removed a while ago due to the cache using huge amounts of memory, to compensate the ABM was slowed down but was still very intensive. Also, we have recently increased the default active block radius so the ABM had become more intensive.

99+% of the time the ABM was running for no reason, leafdecay only needed to happen when trunks were removed nearby. When the ABM was removing leaves it was slow because it has to be tuned to not be too intensive, because it ran all the time.

The new nodetimers ensure that all leaves disappear within the specified time of 12sec, instead of a few always remaining for a long time due to random removal. Leafdecay will now be faster and guaranteed within 12sec, meaning if the player immediately walks away all leaves will decay by the time the player leaves the active block radius (48 nodes by default).

Because trunk nodes and leaf nodes are registered for each other, this means that if two different tree types are intersecting, removing the trunks of one tree type will only remove leaves belonging to that tree.

Registering leafdecay (from game_api.txt)
-----------------------------------------------------

To enable leaf decay for leaves when a tree is cut down by a player,
register the tree with the default.register_leafdecay(leafdecaydef)
function.

If `param2` of any registered node is ~= 0, the node will always be
preserved. Thus, if the player places a node of that kind, you will
want to set `param2 = 1` or so.

The function `default.after_place_leaves` can be set as
`after_place_node of a node` to set param2 to 1 if the player places
the node (should not be used for nodes that use param2 otherwise
(e.g. facedir)).

If the node is in the `leafdecay_drop` group then it will always be
dropped as an item.

`default.register_leafdecay(leafdecaydef)`

`leafdecaydef` is a table, with following members:
{
trunks = {"default:tree"}, -- nodes considered trunks
leaves = {"default:leaves", "default:apple"},
-- nodes considered for removal
radius = 3, -- radius to consider for searching
}

Note: all the listed nodes in `trunks` have their `on_after_destruct`
callback overridden. All the nodes listed in `leaves` have their
`on_timer` callback overridden.

Example (from nodes.lua)
---------------------------------

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if minetest.get_mapgen_setting("mg_name") == "v6" then
   default.register_leafdecay({
      trunks = {"default:tree"},
      leaves = {"default:apple", "default:leaves"},
      radius = 2,
   })

   default.register_leafdecay({
      trunks = {"default:jungletree"},
      leaves = {"default:jungleleaves"},
      radius = 3,
   })

   default.register_leafdecay({
      trunks = {"default:pine_tree"},
      leaves = {"default:pine_needles"},
      radius = 3,
   })
else
   default.register_leafdecay({
      trunks = {"default:tree"},
      leaves = {"default:apple", "default:leaves"},
      radius = 3,
   })

   default.register_leafdecay({
      trunks = {"default:jungletree"},
      leaves = {"default:jungleleaves"},
      radius = 2,
   })

   default.register_leafdecay({
      trunks = {"default:pine_tree"},
      leaves = {"default:pine_needles"},
      radius = 2,
   })
end

default.register_leafdecay({
   trunks = {"default:acacia_tree"},
   leaves = {"default:acacia_leaves"},
   radius = 2,
})

default.register_leafdecay({
   trunks = {"default:aspen_tree"},
   leaves = {"default:aspen_leaves"},
   radius = 3,
})


'radius' should be set to the maximum distance of leaves from trunks, this will usually be the same as the value of the 'leafdecay' group.

If anyone has questions please ask here.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Leafdecay changes: Changes needed in tree mods

by TumeniNodes » Sat Feb 25, 2017 05:36

Very nice. This is a big improvement.
Thank you for the work everyone.
Flick?... Flick who?
 

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

Re: Leafdecay changes: Changes needed in tree mods

by burli » Sat Feb 25, 2017 07:08

I'm curious what happens now. I expect a lot of issues because of not decaying leaves
 

User avatar
yzelast
Member
 
Posts: 43
Joined: Sun Oct 02, 2016 01:18
GitHub: yzelast
In-game: yzelast

Re: Leafdecay changes: Changes needed in tree mods

by yzelast » Sun Feb 26, 2017 22:24

Looks easy, every optimization is welcome.
Have a free time? So check it out my mods: Real Trees and Wood Plus
 

User avatar
Sergey
Member
 
Posts: 362
Joined: Wed Jan 11, 2017 13:28

Re: Leafdecay changes: Changes needed in tree mods

by Sergey » Mon Feb 27, 2017 01:04

Will leaves decay if a tree of same type stands nearby?

Now leaves do not actually belong to "its" tree and will not decay if there is corresponding tree node no further than 4 blocks away. So when felling tree its leaves usually stick to neighbour tree.
 

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

Re: Leafdecay changes: Changes needed in tree mods

by burli » Mon Feb 27, 2017 07:53

A leaf has no reference to it's tree. It decays if a trunk is removed and no other trunk is within the decay radius

But only trunks the leaf is registered for. A default leaf will decay even if it is nearby an aspen tree
 

User avatar
ExeterDad
Member
 
Posts: 1121
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad

Re: Leafdecay changes: Changes needed in tree mods

by ExeterDad » Tue Feb 28, 2017 05:21

burli wrote: A default leaf will decay even if it is nearby an aspen tree

That alone is a huge step forward :)
٩(̾●̮̮̃̾•̃̾)۶

Kibbie and I have a beautiful public server now! HOMETOWN
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Leafdecay changes: Changes needed in tree mods

by TumeniNodes » Tue Feb 28, 2017 16:31

I'm sorry but, I still do not understand why all the leaves within a certain radius of a tree trunk do not just instantly get removed, once a player remove a trunk block from said tree?
That would only make more sense in my mind, and would completely remove the need for any extra/additional time based processes to do so? Would that not free up even more resources during that event? or... would it cause a heavier load by having it all happen at once?

12 seconds is most definitely much quicker than the previous process but....

You cut a tree down, and all happens right there and then... Shabam! At least that's how things work in my yard :P

I mean, I have read all the reasons, etc., related to all of this and I still just do not get it. : /
granted, I realize I "don't get" a lot of things...
Flick?... Flick who?
 

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

Re: Leafdecay changes: Changes needed in tree mods

by burli » Tue Feb 28, 2017 17:00

why all the leaves within a certain radius of a tree trunk do not just instantly get removed

Because each removed leaf causes a light update, which can cause a high load.

And the slow decaying leaves are common and I think it looks cool
 

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

Re: Leafdecay changes: Changes needed in tree mods

by burli » Tue Feb 28, 2017 17:10

just an example: each light update needs, depending on your system, let's say 20ms. If you have a decay radius of 3 you have a block of 7x7x7 nodes, so over 300 possible nodes.

Let's just say 100 leaves. That would mean 100x 20ms

I think this makes it more clear why the delay. Another way would be to use the VoxelManip.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Leafdecay changes: Changes needed in tree mods

by TumeniNodes » Tue Feb 28, 2017 17:17

burli wrote:Because each removed leaf causes a light update, which can cause a high load.


ahhhhh, now I get it. I always forget about the lighting updates.
While I do not think it would cause much a load on resources for just a couple trees... I imagine it probably would if the payer is clearing a lot of trees.

Although, my own personal feeling is that MT is too dense with trees in the first place. They could stand to be thinned out a little.
I have noticed a dramatic difference, by doing this but... I also reduced the density of trees dramatically, and other stuff.

But, as I state, thinning the tree density a little would bring yet even more of a boost in performance. Every little bit counts, and it would not change the overall "look and feel"... and added with this new leaf decay process would be two areas related to trees which make performance improvements :)

Thinking about it now, it seems a decent way to go about working on performance boosts throughout the game... focus on trees, plants, grass, etc... all in steps?
Flick?... Flick who?
 

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

Re: Leafdecay changes: Changes needed in tree mods

by burli » Tue Feb 28, 2017 17:42

And I want to add more and taller trees and more plants ;-)

I think, to increase the performance it is the wrong way to reduce the number of nodes. I think it would be better to reduce the detail level in the distance, e.g. remove small plants like grass and flowers or draw leaves as basic leaves and not fancy
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Leafdecay changes: Changes needed in tree mods

by TumeniNodes » Tue Feb 28, 2017 18:16

burli wrote:And I want to add more and taller trees and more plants ;-)

I think, to increase the performance it is the wrong way to reduce the number of nodes. I think it would be better to reduce the detail level in the distance, e.g. remove small plants like grass and flowers or draw leaves as basic leaves and not fancy


Taller trees I definitely agree with. I've been fiddling around with that, myself.

And your logic makes sense regarding detail rendering in the distance. And those things should not matter anyway, being they are so far away (visually) but, I had not even thought of that and have no idea what possibilities are available to set such visual's/or decorations rendering settings based on distance... is it possible?

Does it require another process which hits resources?

Is there a means to render leaves differently based upon their distance from the player? And causing them to switch to "fancy" within a certain radius to the player?

I mentioned making trees less dense only because, I'm not sure if other users notice the same fps drop/lag as I do in areas with very dense trees... (especially, more so jungle trees, for me), those seem to be more impacting than the other tree types.

When I reduced the number of trees, I noticed a good boost, overall... and it was even better after I completely removed jungle trees. (but this is just in my own case and on my own MT- spinoff.)
Flick?... Flick who?
 

User avatar
Sergey
Member
 
Posts: 362
Joined: Wed Jan 11, 2017 13:28

Re: Leafdecay changes: Changes needed in tree mods

by Sergey » Tue Feb 28, 2017 18:22

burli wrote:And I want to add more and taller trees and more plants ;-)

I think, to increase the performance it is the wrong way to reduce the number of nodes. I think it would be better to reduce the detail level in the distance, e.g. remove small plants like grass and flowers or draw leaves as basic leaves and not fancy

In my settings leaves are simple, not fancy. With fancy leaves it is impossible to play (at least for me) as FPS becomes 10 or so.
 

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

Re: Leafdecay changes: Changes needed in tree mods

by burli » Tue Feb 28, 2017 18:54

Of course. The more trees, the more the frame rate drops

But this becomes off topic. I open a new thread
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: Leafdecay changes: Changes needed in tree mods

by Wuzzy » Sat Mar 04, 2017 16:30

`leafdecaydef` is a table, with following members:


Why not “_leafdecaydef”?

Excerpt from lua_api.txt, node definitions:

_custom_field = whatever,
--[[
^ Add your own custom fields. By convention, all custom field names
should start with `_` to avoid naming collisions with future engine
usage.



To enable leaf decay for leaves when a tree is cut down by a player,
register the tree with the default.register_leafdecay(leafdecaydef)
function.


Wait, so simply adding the node to the “leafdecay” group is not working anymore? :-(
This makes stuff more complicated to maintain. I liked the group because it was so simple.
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: Leafdecay changes: Changes needed in tree mods

by paramat » Sun Mar 05, 2017 00:44

Correct the leafdecay group is now not used by MTGame as has no effect in MTGame, but we left the group there in case mods use it.
 

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

Re: Leafdecay changes: Changes needed in tree mods

by burli » Sun Mar 05, 2017 08:05

It's still simple, just a few more lines of code. And it saves a lot of computing time. Another benefit is that a default tree even decays if e.g an aspen tree is near. And you can decrease the decay time without adding more load
 


Return to Minetest News

Who is online

Users browsing this forum: No registered users and 6 guests

cron