Lua function to add node groups, not just individual nodes
It's a known fact that adding too many nodes at once from Lua can be very slow. The Big Trees mod had issues because of this, and my Structures system also doesn't work as quickly as it could, while the Lua floatlands can take up to a minute to generate. Worse than that, I frequently get incomplete building spawns with my Structures mod, which proves the current method can even fail.
Currently, the only way to add blocks in Lua is with the minetest.env:add_node() function. Using it to spawn a lot of blocks at once is very laggy and even unsafe. I assume it's because it sends a lot of signals to create, notify and store a lot of blocks in a short amount of time... which the code can't properly group and doesn't have the time to handle.
My suggested alternative is allowing a list of blocks to be sent. The reason why trees and landscapes generated by the mapgen are so fast is that spawning a lot of blocks simultaneously is a dozen times faster in C++, given they can be organized and grouped accordingly while the hard work is done once for all nodes rather than per-node. With such a function, adding structures from Lua wouldn't require spamming the code with nodes, but sending a single list which the engine can queue and manage optimally.
Currently, the only way to add blocks in Lua is with the minetest.env:add_node() function. Using it to spawn a lot of blocks at once is very laggy and even unsafe. I assume it's because it sends a lot of signals to create, notify and store a lot of blocks in a short amount of time... which the code can't properly group and doesn't have the time to handle.
My suggested alternative is allowing a list of blocks to be sent. The reason why trees and landscapes generated by the mapgen are so fast is that spawning a lot of blocks simultaneously is a dozen times faster in C++, given they can be organized and grouped accordingly while the hard work is done once for all nodes rather than per-node. With such a function, adding structures from Lua wouldn't require spamming the code with nodes, but sending a single list which the engine can queue and manage optimally.
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
# Example of the current way (slow and with chances of failure):
minetest.env:add_node(pos1, { name = "dirt_with_grass" })
minetest.env:add_node(pos2, { name = "cobblestone" })
# Example of the suggested way (quicker and safer):
group = { }
table.insert(group, { pos1, { name = "dirt_with_grass" } })
table.insert(group, { pos2, { name = "cobblestone" } })
minetest.env:add_node_group(group)