How much storing values in metadata affects performance?

User avatar
yzelast
Member
 
Posts: 54
Joined: Sun Oct 02, 2016 01:18
Location: Far Far Away
GitHub: yzelast
In-game: yzelast

How much storing values in metadata affects performance?

by yzelast » Mon Dec 31, 2018 22:38

Hi guys, i'm implementing a feature in my mod that makes the leaves regrow after some time, and after some tests it looks like using metadatas is the easiest way to do it.
I only need to store 2 values, the node name and the facedir, and i wanna know if having a lot of these metadatas together will affect the game performance.

Here is the code i used to test:
- setting the values
Code: Select all
minetest.override_item("default:leaves", {
   description = "Apple Leaves",
   drop = {max_items = 1,
      items = {
         {items = {"default:stick"}, rarity = 0},
         {items = {"default:sapling"}, rarity = 0},
      },
   },
   groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1, apple = 1},

   on_punch = function(pos)
   local node = minetest.get_node(pos)
      minetest.set_node(pos, {name="realtrees:invisible_leaves"})
   local meta = minetest.get_meta(pos)
      meta:set_int("face",node.param2)
      meta:set_string("name",node.name)
   end,

   on_timer = function(pos)
      realtrees.leafdecay(pos, 5, "apple", "default:leaves")
   end,
})


- getting the values
Code: Select all
minetest.register_node("realtrees:invisible_leaves", {
   description = "Invisible Apple Leaves",
   drawtype = "airlike",
   paramtype = "light",
   paramtype2 = "facedir",
   walkable = true,
   pointable = true,
   buildable_to = true,

   on_punch = function(pos)
      minetest.get_node_timer(pos):start(5)
   end,

   on_timer = function(pos)
   local meta = minetest.get_meta(pos)
   local face = meta:get_int("face")
   local name = meta:get_string("name")
      minetest.set_node(pos, {name=name, param2=face})
   end,
})


The way i was trying to implement this feature was using an invisible node for each different leaf, so i would have at least 20 different nodes just for this stuff...
G84mU6AQ9dKaNhxn6dq8P5C0y5r8NssE
 

User avatar
Krock
Developer
 
Posts: 4224
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: How much storing values in metadata affects performance?

by Krock » Tue Jan 01, 2019 12:51

Overall it'll be about equal.

Metadata will likely make the map a little bigger than if you'd use different nodes for each kind of leaves.
Individual nodes will make the client's initialization process to take a little bit longer.

If you use the same node many times in the mapblock (as in: one next to each other) then the client can combine the faces and thus, rendering might be a tiny bit faster.
Both variants perform about the same, performance isn't a concern in your case.
>> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 


Return to Modding Discussion



Who is online

Users browsing this forum: texmex and 1 guest