Default almost all node meta fields to private.
Trying to isolate server performance issues, it was pointed out that clients are spending a LOT of time receiving and rebuilding mapblock meshes, and that updating node meta triggers this, even when that meta is not relevant to the rendering of nodes. Rubenwardy added a suggestion to change this in the engine: https://github.com/minetest/minetest/issues/10127 This patch implements this suggestion at the game level, since in NodeCore's case we already were making the assumption that nearly all metadata fields were private.
This commit is contained in:
parent
cf799989b3
commit
b4c72c9b2c
@ -81,6 +81,7 @@ end
|
||||
|
||||
include("compat_vector")
|
||||
include("issue9043")
|
||||
include("nodemetahack")
|
||||
|
||||
include("util_misc")
|
||||
include("util_hookmeta")
|
||||
|
35
mods/nc_api/nodemetahack.lua
Normal file
35
mods/nc_api/nodemetahack.lua
Normal file
@ -0,0 +1,35 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local getmetatable, minetest, pairs
|
||||
= getmetatable, minetest, pairs
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local publicfields = {
|
||||
formspec = true,
|
||||
infotext = true
|
||||
}
|
||||
|
||||
local function hook(meta)
|
||||
for k, v in pairs(meta) do
|
||||
if k:sub(1, 4) == "set_" then
|
||||
meta[k] = function(data, name, ...)
|
||||
if not publicfields[name] then
|
||||
data:mark_as_private(name)
|
||||
end
|
||||
return v(data, name, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local rawmeta = minetest.get_meta
|
||||
function minetest.get_meta(...)
|
||||
local raw = rawmeta(...)
|
||||
if raw then
|
||||
local meta = getmetatable(raw)
|
||||
if meta then
|
||||
hook(meta)
|
||||
minetest.get_meta = rawmeta
|
||||
end
|
||||
end
|
||||
return raw
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user