merge ws/voxel
This commit is contained in:
commit
b7f3a69fcc
44 files changed
+7481
-27
No files matched your search
@@ -1125,3 +1125,81 @@ do
|
||||
jitTune(false)
|
||||
end
|
||||
end
|
||||
do
|
||||
-- NBT / voxels (ws-voxel): a chunk-like NBT tree (24 sections with packed long arrays, 4000 entity-like compounds)
|
||||
-- through codecs/text/Nbt (binary and SNBT), 1M packed 5-bit indices, a 64^3 Sponge schematic and Qubicle file
|
||||
local Nbt = require("@formats/codecs/text/Nbt")
|
||||
local Mc = require("@formats/codecs/model/Minecraft")
|
||||
local Schematic = require("@formats/model/schematic")
|
||||
local Qb = require("@formats/model/qb")
|
||||
local sections = Nbt.list("compound")
|
||||
for s = 1, 24 do
|
||||
local pal = Nbt.list("compound")
|
||||
for p = 1, 16 do
|
||||
table.insert(pal, Nbt.compound({ Name = "minecraft:block_" .. p, Properties = Nbt.compound({ axis = "y" }, { "axis" }) }, { "Name", "Properties" }))
|
||||
end
|
||||
local longs = buffer.create(256 * 8)
|
||||
for i = 0, 511 do
|
||||
buffer.writeu32(longs, i * 4, (i * 2654435761) % 4294967296)
|
||||
end
|
||||
table.insert(sections, Nbt.compound({ Y = Nbt.byte(s - 5), block_states = Nbt.compound({ palette = pal, data = Nbt.longArray(longs) }, { "palette", "data" }) }, { "Y", "block_states" }))
|
||||
end
|
||||
local ents = Nbt.list("compound")
|
||||
for i = 1, 4000 do
|
||||
table.insert(ents, Nbt.compound({
|
||||
id = "minecraft:thing",
|
||||
Pos = Nbt.list("double", { Nbt.double(i * 0.5), Nbt.double(64), Nbt.double(-i * 0.25) }),
|
||||
Health = Nbt.float(20),
|
||||
UUID = Nbt.intArray({ i, -i, i * 3, 7 }),
|
||||
Tags = Nbt.list("string", { "a", "b" }),
|
||||
Age = Nbt.short(i % 1000),
|
||||
Seed = Nbt.long(i * 1234567),
|
||||
}, { "id", "Pos", "Health", "UUID", "Tags", "Age", "Seed" }))
|
||||
end
|
||||
local root = Nbt.compound({ DataVersion = 3953, sections = sections, entities = ents }, { "DataVersion", "sections", "entities" })
|
||||
local raw = assert(Nbt.encode(root, { compression = "none" }))
|
||||
bench("nbt decode (" .. buffer.len(raw) // 1000 .. " KB)", 5, buffer.len(raw), function()
|
||||
Nbt.decode(raw)
|
||||
end)
|
||||
bench("nbt encode", 5, buffer.len(raw), function()
|
||||
Nbt.encode(root, { compression = "none" })
|
||||
end)
|
||||
local text = assert(Nbt.print(root))
|
||||
bench("snbt parse (" .. #text // 1000 .. " KB)", 3, #text, function()
|
||||
Nbt.parse(text)
|
||||
end)
|
||||
bench("snbt print", 3, #text, function()
|
||||
Nbt.print(root)
|
||||
end)
|
||||
local n = 1048576
|
||||
local idx = buffer.create(n * 2)
|
||||
for i = 0, n - 1 do
|
||||
buffer.writeu16(idx, i * 2, (i * 7) % 32)
|
||||
end
|
||||
local packed = Mc.Packed.pack(idx, n, 5, false)
|
||||
local out = buffer.create(n * 2)
|
||||
bench("packed unpack 1M x 5 bits (MB out)", 5, n * 2, function()
|
||||
Mc.Packed.unpack(packed, 5, n, false, out, 32)
|
||||
end)
|
||||
local V = 64
|
||||
local states = { "minecraft:air" }
|
||||
for i = 1, 40 do
|
||||
table.insert(states, "minecraft:block_" .. i)
|
||||
end
|
||||
local cells = buffer.create(V * V * V * 2)
|
||||
for i = 0, V * V * V - 1 do
|
||||
buffer.writeu16(cells, i * 2, if (i // V) % 3 == 0 then 0 else 1 + (i // 97) % 40)
|
||||
end
|
||||
local grid = Mc.voxels(V, V, V, states, cells)
|
||||
local schem = assert(Schematic.encode(grid, { compression = "none" }))
|
||||
bench("schem decode 64^3 (MB of cells)", 3, V * V * V, function()
|
||||
Schematic.decode(Bytes.reader(schem))
|
||||
end)
|
||||
bench("schem encode 64^3", 3, V * V * V, function()
|
||||
Schematic.encode(grid, { compression = "none" })
|
||||
end)
|
||||
local qb = assert(Qb.encode(grid))
|
||||
bench("qb decode 64^3 rle (MB of cells)", 3, V * V * V, function()
|
||||
Qb.decode(Bytes.reader(qb))
|
||||
end)
|
||||
end
|
||||
Reference in new issue
Block a user