From ee88f6603fb599ce3d3d07245ff534b00dcb7a50 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Thu, 15 Oct 2020 17:35:08 +0200 Subject: [PATCH] Fix the param1 and param2 encoding The values were all saved to `data[p]` but `p` was not updated, so only one param1 and param2 value were saved. This also led to invalid metadata decoding. I have changed the function so that it keeps track of the size of `data` instead of inserting elements with `data[#data+1]` because the code is probably performance-relevant. --- init.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/init.lua b/init.lua index 0cc7f76..9d6020a 100644 --- a/init.lua +++ b/init.lua @@ -364,7 +364,7 @@ end local indic_names = {"indices_n", "indices_p1", "indices_p2", "indices_m"} local function compress_nodedata(nodedata) - local data = {} + local data, n = {}, 0 -- put indices first for j = 1,#indic_names do local indices = nodedata[indic_names[j]] @@ -377,7 +377,8 @@ local function compress_nodedata(nodedata) for f = nodedata.index_bytes-1, 0, -1 do v = v .. string.char(math.floor(off * 2^(-8*f)) % 0x100) end - data[#data+1] = v + n = n+1 + data[n] = v prev_index = index end end @@ -386,7 +387,8 @@ local function compress_nodedata(nodedata) -- big endian here if nodedata.indices_n then for i = 1,#nodedata.nodeids do - data[#data+1] = string.char(math.floor(nodedata.nodeids[i] * 2^-8) + n = n+1 + data[n] = string.char(math.floor(nodedata.nodeids[i] * 2^-8) ) .. string.char(nodedata.nodeids[i] % 0x100) end end @@ -394,15 +396,16 @@ local function compress_nodedata(nodedata) for j = 1,2 do if nodedata["indices_p" .. j] then local vs = nodedata["param" .. j .. "s"] - local p = #data for i = 1,#vs do - data[p+1] = string.char(vs[i]) + n = n+1 + data[n] = string.char(vs[i]) end end end -- meta… if nodedata.indices_m then - data[#data+1] = minetest.serialize(nodedata.metastrings) + n = n+1 + data[n] = minetest.serialize(nodedata.metastrings) end return minetest.compress(table.concat(data)) end