rename: src/Formats -> src/Rosetta, @formats -> @rosetta requires, build/luajit/rosetta + rosetta._compat, build/roblox/Rosetta, ROSETTA_* env/globals, writer vendor strings
This commit is contained in:
1 parent
2956576d7f
commit
22ddcd78fa
941 files changed
+3364
-3364
No files matched your search
@@ -0,0 +1,212 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- model/ply/Binary: PLY element data loops. Value read / write by type code (1 i8, 2 u8, 3 i16, 4 u16, 5 i32, 6 u32,
|
||||
-- 7 f32, 8 f64) in either byte order, the column copy of fixed-size rows (scalar properties only) and the row walk of
|
||||
-- rows with lists (a scan for the list totals, then the fill). The caller (init) sizes every destination from the
|
||||
-- header counts and the scan, and checks the rows fit in the data first, so every index here is in range; a bad list
|
||||
-- count or an out-of-range vertex index returns false / -1 with a message. Nothing here throws.
|
||||
local readu8, readi8, readu16, readi16, readu32, readi32 = buffer.readu8, buffer.readi8, buffer.readu16, buffer.readi16, buffer.readu32, buffer.readi32
|
||||
local readf32, readf64 = buffer.readf32, buffer.readf64
|
||||
local writeu8, writei8, writeu16, writei16, writeu32, writei32 = buffer.writeu8, buffer.writei8, buffer.writeu16, buffer.writei16, buffer.writeu32, buffer.writei32
|
||||
local writef32, writef64 = buffer.writef32, buffer.writef64
|
||||
local byteswap, band, rshift = bit32.byteswap, bit32.band, bit32.rshift
|
||||
|
||||
local Binary = {}
|
||||
|
||||
Binary.SIZE = { 1, 1, 2, 2, 4, 4, 4, 8 }
|
||||
local SIZE = Binary.SIZE
|
||||
local scratch = buffer.create(8)
|
||||
|
||||
local function swap16(v: number): number
|
||||
return rshift(v, 8) + band(v, 255) * 256
|
||||
end
|
||||
|
||||
-- rd(b, q, code, be) -> the value at q
|
||||
local function rd(b: buffer, q: number, code: number, be: boolean): number
|
||||
if not be then
|
||||
if code == 7 then
|
||||
return readf32(b, q)
|
||||
elseif code == 2 then
|
||||
return readu8(b, q)
|
||||
elseif code == 5 then
|
||||
return readi32(b, q)
|
||||
elseif code == 6 then
|
||||
return readu32(b, q)
|
||||
elseif code == 8 then
|
||||
return readf64(b, q)
|
||||
elseif code == 1 then
|
||||
return readi8(b, q)
|
||||
elseif code == 3 then
|
||||
return readi16(b, q)
|
||||
end
|
||||
return readu16(b, q)
|
||||
end
|
||||
if code <= 2 then
|
||||
return if code == 1 then readi8(b, q) else readu8(b, q)
|
||||
elseif code <= 4 then
|
||||
local v = swap16(readu16(b, q))
|
||||
return if code == 3 and v >= 32768 then v - 65536 else v
|
||||
elseif code <= 7 then
|
||||
local v = byteswap(readu32(b, q))
|
||||
if code == 6 then
|
||||
return v
|
||||
elseif code == 5 then
|
||||
return if v >= 2147483648 then v - 4294967296 else v
|
||||
end
|
||||
writeu32(scratch, 0, v)
|
||||
return readf32(scratch, 0)
|
||||
end
|
||||
writeu32(scratch, 0, byteswap(readu32(b, q + 4)))
|
||||
writeu32(scratch, 4, byteswap(readu32(b, q)))
|
||||
return readf64(scratch, 0)
|
||||
end
|
||||
Binary.rd = rd
|
||||
|
||||
-- wr(d, o, code, v): v as code, little endian
|
||||
local function wr(d: buffer, o: number, code: number, v: number)
|
||||
if code == 7 then
|
||||
writef32(d, o, v)
|
||||
elseif code == 6 then
|
||||
writeu32(d, o, v)
|
||||
elseif code == 5 then
|
||||
writei32(d, o, v)
|
||||
elseif code == 2 then
|
||||
writeu8(d, o, v)
|
||||
elseif code == 8 then
|
||||
writef64(d, o, v)
|
||||
elseif code == 1 then
|
||||
writei8(d, o, v)
|
||||
elseif code == 3 then
|
||||
writei16(d, o, v)
|
||||
else
|
||||
writeu16(d, o, v)
|
||||
end
|
||||
end
|
||||
Binary.wr = wr
|
||||
|
||||
-- put(d, o, code, v, be): v as code in either byte order (the writer)
|
||||
function Binary.put(d: buffer, o: number, code: number, v: number, be: boolean)
|
||||
if not be or code <= 2 then
|
||||
wr(d, o, code, v)
|
||||
return
|
||||
end
|
||||
wr(scratch, 0, code, v)
|
||||
if code <= 4 then
|
||||
writeu16(d, o, swap16(readu16(scratch, 0)))
|
||||
elseif code <= 7 then
|
||||
writeu32(d, o, byteswap(readu32(scratch, 0)))
|
||||
else
|
||||
writeu32(d, o, byteswap(readu32(scratch, 4)))
|
||||
writeu32(d, o + 4, byteswap(readu32(scratch, 0)))
|
||||
end
|
||||
end
|
||||
|
||||
-- fixed(b, p, n, rowSize, np, srcOff, code, be, dst, dOff, dStride, dCode): column copies of n fixed-size rows at p
|
||||
function Binary.fixed(b: buffer, p: number, n: number, rowSize: number, np: number, srcOff: { number }, code: { number }, be: boolean, dst: { buffer }, dOff: { number }, dStride: { number }, dCode: { number })
|
||||
for k = 1, np do
|
||||
local sc, dc, d = code[k], dCode[k], dst[k]
|
||||
local q0, o0, st = p + srcOff[k], dOff[k], dStride[k]
|
||||
if sc == dc and not be then
|
||||
local sz = SIZE[sc]
|
||||
if sz == 4 then
|
||||
for i = 0, n - 1 do
|
||||
writeu32(d, o0 + i * st, readu32(b, q0 + i * rowSize))
|
||||
end
|
||||
elseif sz == 1 then
|
||||
for i = 0, n - 1 do
|
||||
writeu8(d, o0 + i * st, readu8(b, q0 + i * rowSize))
|
||||
end
|
||||
elseif sz == 2 then
|
||||
for i = 0, n - 1 do
|
||||
writeu16(d, o0 + i * st, readu16(b, q0 + i * rowSize))
|
||||
end
|
||||
else
|
||||
for i = 0, n - 1 do
|
||||
writeu32(d, o0 + i * st, readu32(b, q0 + i * rowSize))
|
||||
writeu32(d, o0 + i * st + 4, readu32(b, q0 + i * rowSize + 4))
|
||||
end
|
||||
end
|
||||
else
|
||||
for i = 0, n - 1 do
|
||||
wr(d, o0 + i * st, dc, rd(b, q0 + i * rowSize, sc, be))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- scan(b, p, limit, n, np, code, isList, countCode, be) -> the end offset and the item total of each list property,
|
||||
-- or -1, message (truncated rows, a negative / fractional count)
|
||||
function Binary.scan(b: buffer, p: number, limit: number, n: number, np: number, code: { number }, isList: { boolean }, countCode: { number }, be: boolean): (number, any)
|
||||
local totals = table.create(np, 0)
|
||||
local q = p
|
||||
for _ = 1, n do
|
||||
for k = 1, np do
|
||||
if isList[k] then
|
||||
local cc = countCode[k]
|
||||
local csz = SIZE[cc]
|
||||
if q + csz > limit then
|
||||
return -1, "list runs past the end"
|
||||
end
|
||||
local c = rd(b, q, cc, be)
|
||||
if c < 0 or c ~= c // 1 then
|
||||
return -1, "bad list count"
|
||||
end
|
||||
q += csz + c * SIZE[code[k]]
|
||||
if q > limit then
|
||||
return -1, "list runs past the end"
|
||||
end
|
||||
totals[k] += c
|
||||
else
|
||||
q += SIZE[code[k]]
|
||||
if q > limit then
|
||||
return -1, "row runs past the end"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return q, totals
|
||||
end
|
||||
|
||||
-- rows(b, p, n, np, code, isList, countCode, be, dst, dOff, dStride, dCode, sizes, bound) -> true | false, message.
|
||||
-- Scalars go to dst[k] at dOff + row * dStride as dCode; lists write their count to sizes[k] (u32 per row) and their
|
||||
-- items one after the other into dst[k] as dCode; bound[k] >= 0 checks items are integers in 0 .. bound - 1. The rows
|
||||
-- must have passed scan() with the same arguments.
|
||||
function Binary.rows(b: buffer, p: number, n: number, np: number, code: { number }, isList: { boolean }, countCode: { number }, be: boolean, dst: { buffer }, dOff: { number }, dStride: { number }, dCode: { number }, sizes: { buffer }, bound: { number }): (boolean, string?)
|
||||
local at = table.create(np, 0)
|
||||
local q = p
|
||||
for i = 0, n - 1 do
|
||||
for k = 1, np do
|
||||
local sc, dc, d = code[k], dCode[k], dst[k]
|
||||
if isList[k] then
|
||||
local cc = countCode[k]
|
||||
local c = rd(b, q, cc, be)
|
||||
q += SIZE[cc]
|
||||
writeu32(sizes[k], i * 4, c)
|
||||
local ia, ssz, dsz, bd = at[k], SIZE[sc], SIZE[dc], bound[k]
|
||||
if bd >= 0 then
|
||||
for j = 0, c - 1 do
|
||||
local v = rd(b, q, sc, be)
|
||||
q += ssz
|
||||
if v < 0 or v >= bd or v ~= v // 1 then
|
||||
return false, "vertex index out of range"
|
||||
end
|
||||
wr(d, (ia + j) * dsz, dc, v)
|
||||
end
|
||||
else
|
||||
for j = 0, c - 1 do
|
||||
wr(d, (ia + j) * dsz, dc, rd(b, q, sc, be))
|
||||
q += ssz
|
||||
end
|
||||
end
|
||||
at[k] = ia + c
|
||||
else
|
||||
wr(d, dOff[k] + i * dStride[k], dc, rd(b, q, sc, be))
|
||||
q += SIZE[sc]
|
||||
end
|
||||
end
|
||||
end
|
||||
return true, nil
|
||||
end
|
||||
|
||||
return Binary
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user