mirror of
https://github.com/HybridDog/we_undo.git
synced 2025-01-05 20:27:35 +01:00
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.
This commit is contained in:
parent
d8a5c2e4a0
commit
ee88f6603f
15
init.lua
15
init.lua
@ -364,7 +364,7 @@ end
|
|||||||
|
|
||||||
local indic_names = {"indices_n", "indices_p1", "indices_p2", "indices_m"}
|
local indic_names = {"indices_n", "indices_p1", "indices_p2", "indices_m"}
|
||||||
local function compress_nodedata(nodedata)
|
local function compress_nodedata(nodedata)
|
||||||
local data = {}
|
local data, n = {}, 0
|
||||||
-- put indices first
|
-- put indices first
|
||||||
for j = 1,#indic_names do
|
for j = 1,#indic_names do
|
||||||
local indices = nodedata[indic_names[j]]
|
local indices = nodedata[indic_names[j]]
|
||||||
@ -377,7 +377,8 @@ local function compress_nodedata(nodedata)
|
|||||||
for f = nodedata.index_bytes-1, 0, -1 do
|
for f = nodedata.index_bytes-1, 0, -1 do
|
||||||
v = v .. string.char(math.floor(off * 2^(-8*f)) % 0x100)
|
v = v .. string.char(math.floor(off * 2^(-8*f)) % 0x100)
|
||||||
end
|
end
|
||||||
data[#data+1] = v
|
n = n+1
|
||||||
|
data[n] = v
|
||||||
prev_index = index
|
prev_index = index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -386,7 +387,8 @@ local function compress_nodedata(nodedata)
|
|||||||
-- big endian here
|
-- big endian here
|
||||||
if nodedata.indices_n then
|
if nodedata.indices_n then
|
||||||
for i = 1,#nodedata.nodeids do
|
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)
|
) .. string.char(nodedata.nodeids[i] % 0x100)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -394,15 +396,16 @@ local function compress_nodedata(nodedata)
|
|||||||
for j = 1,2 do
|
for j = 1,2 do
|
||||||
if nodedata["indices_p" .. j] then
|
if nodedata["indices_p" .. j] then
|
||||||
local vs = nodedata["param" .. j .. "s"]
|
local vs = nodedata["param" .. j .. "s"]
|
||||||
local p = #data
|
|
||||||
for i = 1,#vs do
|
for i = 1,#vs do
|
||||||
data[p+1] = string.char(vs[i])
|
n = n+1
|
||||||
|
data[n] = string.char(vs[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- meta…
|
-- meta…
|
||||||
if nodedata.indices_m then
|
if nodedata.indices_m then
|
||||||
data[#data+1] = minetest.serialize(nodedata.metastrings)
|
n = n+1
|
||||||
|
data[n] = minetest.serialize(nodedata.metastrings)
|
||||||
end
|
end
|
||||||
return minetest.compress(table.concat(data))
|
return minetest.compress(table.concat(data))
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user