Some performance improvements

This commit is contained in:
Joachim Stolberg 2018-06-23 23:58:30 +02:00
parent 16fefca1fa
commit 16f62e30bc
2 changed files with 33 additions and 8 deletions

@ -27,6 +27,11 @@ function display_update(pos, objref)
visual_size = {x=0.94, y=0.94} }) visual_size = {x=0.94, y=0.94} })
end end
local function on_timer(pos)
local meta = minetest.get_meta(pos)
display_lib.update_entities(pos)
return false
end
local lcd_box = { local lcd_box = {
type = "wallmounted", type = "wallmounted",
@ -59,6 +64,7 @@ minetest.register_node("smartline:display", {
display_lib.update_entities(pos) display_lib.update_entities(pos)
end, end,
on_timer = on_timer,
on_place = display_lib.on_place, on_place = display_lib.on_place,
on_construct = display_lib.on_construct, on_construct = display_lib.on_construct,
on_destruct = display_lib.on_destruct, on_destruct = display_lib.on_destruct,
@ -121,18 +127,25 @@ end
tubelib.register_node("smartline:display", {}, { tubelib.register_node("smartline:display", {}, {
on_recv_message = function(pos, topic, payload) on_recv_message = function(pos, topic, payload)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local timer = minetest.get_node_timer(pos)
if topic == "text" then -- add one line and scroll if necessary if topic == "text" then -- add one line and scroll if necessary
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
add_line(meta, payload) add_line(meta, payload)
display_lib.update_entities(pos) if not timer:is_started() then
timer:start(2)
end
elseif topic == "row" then -- overwrite the given row elseif topic == "row" then -- overwrite the given row
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
write_row(meta, payload) write_row(meta, payload)
display_lib.update_entities(pos) if not timer:is_started() then
timer:start(2)
end
elseif topic == "clear" then -- clear the screen elseif topic == "clear" then -- clear the screen
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("text", "") meta:set_string("text", "")
display_lib.update_entities(pos) if not timer:is_started() then
timer:start(2)
end
end end
end, end,
}) })

@ -94,6 +94,20 @@ local function generate_Key2Number()
end end
end end
local function not_protected(pos, placer_name, clicker_name)
local meta = minetest.get_meta(pos)
if meta then
local cached_name = meta:get_string("tubelib_cached_name")
if placer_name and (placer_name == cached_name or not minetest.is_protected(pos, placer_name)) then
meta:set_string("tubelib_cached_name", placer_name)
if clicker_name == nil or not minetest.is_protected(pos, clicker_name) then
return true
end
end
end
return false
end
------------------------------------------------------------------- -------------------------------------------------------------------
-- API helper functions -- API helper functions
------------------------------------------------------------------- -------------------------------------------------------------------
@ -224,8 +238,7 @@ function tubelib.send_message(numbers, placer_name, clicker_name, topic, payload
for _,num in ipairs(string_split(numbers, " ")) do for _,num in ipairs(string_split(numbers, " ")) do
if Number2Pos[num] and Number2Pos[num].name then if Number2Pos[num] and Number2Pos[num].name then
local data = Number2Pos[num] local data = Number2Pos[num]
if placer_name and not minetest.is_protected(data.pos, placer_name) then if not_protected(data.pos, placer_name, clicker_name) then
if clicker_name == nil or not minetest.is_protected(data.pos, clicker_name) then
if tubelib_NodeDef[data.name] and tubelib_NodeDef[data.name].on_recv_message then if tubelib_NodeDef[data.name] and tubelib_NodeDef[data.name].on_recv_message then
tubelib_NodeDef[data.name].on_recv_message(data.pos, topic, payload) tubelib_NodeDef[data.name].on_recv_message(data.pos, topic, payload)
end end
@ -233,7 +246,6 @@ function tubelib.send_message(numbers, placer_name, clicker_name, topic, payload
end end
end end
end end
end
function tubelib.send_request(number, topic, payload) function tubelib.send_request(number, topic, payload)
if Number2Pos[number] and Number2Pos[number].name then if Number2Pos[number] and Number2Pos[number].name then