From 18b293cec8b183f51a479d589ad1b0b429ab4998 Mon Sep 17 00:00:00 2001 From: cheapie Date: Fri, 23 Aug 2024 12:25:24 -0500 Subject: Performance improvements --- init.lua | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/init.lua b/init.lua index a56195c..43589d0 100644 --- a/init.lua +++ b/init.lua @@ -18,32 +18,15 @@ local function generateTexture(pos,serdata) minetest.log("error","[digiscreen] Failed to deserialize display data at "..minetest.pos_to_string(pos,0)) return end + local bincolors = "" for y=1,16,1 do - if type(data[y]) ~= "table" then - minetest.log("error","[digiscreen] Invalid row "..y.." at "..minetest.pos_to_string(pos,0)) - return - end - for x=1,16,1 do - if type(data[y][x]) ~= "string" or string.len(data[y][x]) ~= 6 then - minetest.log("error","[digiscreen] Missing/wrong length display data for X="..x.." Y="..y.." at "..minetest.pos_to_string(pos,0)) - return - end - for i=1,6,1 do - if not tonumber(string.sub(data[y][x],i,i),16) then - minetest.log("error","[digiscreen] Invalid digit in display data for X="..x.." Y="..y.." at "..minetest.pos_to_string(pos,0)) - return - end - end - end - end - - local ret = "[combine:16x16" - for y=1,16,1 do + if type(data[y]) ~= "table" then data[y] = {} end for x=1,16,1 do - ret = ret..string.format(":%d,%d=(digiscreen_pixel.png\\^[colorize\\:#%s\\:255)",x-1,y-1,data[y][x]) + bincolors = bincolors..minetest.colorspec_to_bytes(data[y][x] or "000000") end end - return ret + local img = minetest.encode_png(16,16,bincolors,0) + return "[png:"..minetest.encode_base64(img) end local function updateDisplay(pos) -- cgit v1.2.3