archive/vswap (Wolfenstein 3D pages: walls, sprites and sounds through a palette passed in) and vector/gamemaps (GAMEMAPS + MAPHEAD, Carmack + RLEW, into a TileMap); test data from the fixture's own writers
This commit is contained in:
1 parent
719abb97c0
commit
e51fd3585e
15 files changed
+3139
-1085
No files matched your search
@@ -0,0 +1,107 @@
|
||||
-- archive/vswap + vector/gamemaps tests: Wolfenstein 3D page files and maps written by the fixture's own writers
|
||||
-- (walls, sprites with gaps, sounds; Carmack + RLEW planes) against their source pixels and tiles.
|
||||
-- Fixtures: tools/fixtures/wolf3d.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@rosetta")
|
||||
local Vswap = require("@rosetta/archive/vswap")
|
||||
local Gamemaps = require("@rosetta/vector/gamemaps")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Fx = require("@tests/gen/wolf3d")
|
||||
|
||||
local t = T.suite("vswap")
|
||||
t:eq(Vswap.name, "vswap", "name")
|
||||
t:eq(Gamemaps.name, "gamemaps", "name")
|
||||
|
||||
local vs = Fx.vswap
|
||||
t:eq(F.detect(vs.data, { name = "VSWAP.WL6" }), "vswap", "F.detect VSWAP")
|
||||
local a, err = Vswap.decode(Bytes.reader(buffer.fromstring(vs.data)))
|
||||
t:check(a, "vswap: " .. tostring(err))
|
||||
do
|
||||
local list = a:list()
|
||||
t:eq(list[1].name, "walls/000", "wall entry")
|
||||
t:eq(list[#vs.walls + 1].name, "sprites/000", "sprite entry")
|
||||
t:eq(list[#list].name, "soundinfo", "sound info entry")
|
||||
t:eq(a.meta.source.walls, #vs.walls, "wall count")
|
||||
t:eq(a.meta.source.sprites, #vs.sprites, "sprite count")
|
||||
for i, crc in vs.walls do
|
||||
local img, e = Vswap.image(a, "wall", i - 1, { palette = Fx.palette })
|
||||
t:check(img, "wall " .. i .. ": " .. tostring(e))
|
||||
t:eq(Crc32.of((img :: any).pixels), crc, "wall " .. i .. " pixels (column-major, 6-bit palette)")
|
||||
end
|
||||
for i, crc in vs.sprites do
|
||||
local img, e = Vswap.image(a, "sprite", i - 1, { palette = Fx.palette })
|
||||
t:check(img, "sprite " .. i .. ": " .. tostring(e))
|
||||
t:eq(Crc32.of((img :: any).pixels), crc, "sprite " .. i .. " pixels and holes")
|
||||
end
|
||||
local grey = Vswap.image(a, "wall", 0) :: any
|
||||
t:eq(grey.meta.source.palette, false, "no palette: grey")
|
||||
t:eq(Vswap.sounds(a), #vs.sounds, "sound count")
|
||||
for i, s in vs.sounds do
|
||||
local au, e = Vswap.sound(a, i)
|
||||
t:check(au, "sound " .. i .. ": " .. tostring(e))
|
||||
local x = au :: any
|
||||
t:eq(x.frames, s.bytes, "sound " .. i .. " length (across pages)")
|
||||
t:eq(buffer.readf32(x.samples, 0), (s.first - 128) / 128, "sound " .. i .. " first sample")
|
||||
t:eq(buffer.readf32(x.samples, (s.bytes - 1) * 4), (s.last - 128) / 128, "sound " .. i .. " last sample")
|
||||
t:eq(x.sampleRate, 7042, "rate")
|
||||
end
|
||||
local _, e1 = Vswap.image(a, "wall", 99)
|
||||
t:check(e1 and e1.code == Err.ARG, "missing wall")
|
||||
local _, e2 = Vswap.sound(a, 0)
|
||||
t:check(e2 and e2.code == Err.ARG, "missing sound")
|
||||
end
|
||||
|
||||
do
|
||||
t:eq(F.detect(Fx.gamemaps, { name = "GAMEMAPS.WL6" }), "gamemaps", "F.detect GAMEMAPS")
|
||||
t:eq(F.detect(Fx.maphead, { name = "MAPHEAD.WL6" }), "gamemaps", "F.detect MAPHEAD")
|
||||
local files = { ["MAPHEAD.WL6"] = Fx.maphead, ["GAMEMAPS.WL6"] = Fx.gamemaps }
|
||||
local list = Gamemaps.maps(Bytes.reader(buffer.fromstring(Fx.gamemaps)), { name = "GAMEMAPS.WL6", files = files }) :: any
|
||||
t:eq(#list, #Fx.maps, "maps listed (slot 2 is -1)")
|
||||
for _, m in Fx.maps do
|
||||
for _, from in { "gamemaps", "maphead" } do
|
||||
local src = if from == "gamemaps" then Fx.gamemaps else Fx.maphead
|
||||
local tm, e = Gamemaps.decode(Bytes.reader(buffer.fromstring(src)), { name = string.upper(from) .. ".WL6", files = files, map = m.slot })
|
||||
t:check(tm, m.name .. " from " .. from .. ": " .. tostring(e))
|
||||
local x = tm :: any
|
||||
t:eq(x.width, m.width, m.name .. ": width")
|
||||
t:eq(x.height, m.height, m.name .. ": height")
|
||||
t:eq(x.properties.name, m.name, m.name .. ": name")
|
||||
t:eq(#x.layers, 3, m.name .. ": planes")
|
||||
for k, crc in m.planes do
|
||||
local b = buffer.create(m.width * m.height * 2)
|
||||
for i, v in x.layers[k].data do
|
||||
buffer.writeu16(b, (i - 1) * 2, v)
|
||||
end
|
||||
t:eq(Crc32.of(b), crc, m.name .. ": plane " .. k .. " after Carmack + RLEW")
|
||||
end
|
||||
end
|
||||
end
|
||||
local tm = F.load(Fx.gamemaps, { name = "GAMEMAPS.WL6", files = files }) :: any
|
||||
t:check(tm and tm.kind == "tilemap" and tm.layers[1].name == "walls", "F.load: a TileMap")
|
||||
local _, e = Gamemaps.decode(Bytes.reader(buffer.fromstring(Fx.gamemaps)))
|
||||
t:check(e and e.code == Err.UNSUPPORTED, "no MAPHEAD")
|
||||
local _, e2 = Gamemaps.decode(Bytes.reader(buffer.fromstring(Fx.gamemaps)), { mapHead = Fx.maphead, map = 2 })
|
||||
t:check(e2 and e2.code == Err.ARG, "empty slot")
|
||||
end
|
||||
|
||||
t:fuzz("vswap", function(b: buffer)
|
||||
local w = Vswap.decode(Bytes.reader(b))
|
||||
if w then
|
||||
for i = 0, 3 do
|
||||
Vswap.image(w, "wall", i)
|
||||
Vswap.image(w, "sprite", i)
|
||||
end
|
||||
Vswap.sound(w, 1)
|
||||
Vswap.sound(w, 2)
|
||||
end
|
||||
return w
|
||||
end, { buffer.fromstring(vs.data) }, { mutations = 300 })
|
||||
t:fuzz("gamemaps", function(b: buffer)
|
||||
return Gamemaps.decode(Bytes.reader(b), { mapHead = Fx.maphead, map = 3 })
|
||||
end, { buffer.fromstring(Fx.gamemaps) }, { mutations = 300 })
|
||||
t:fuzz("maphead", function(b: buffer)
|
||||
return Gamemaps.decode(Bytes.reader(b), { gameMaps = Fx.gamemaps })
|
||||
end, { buffer.fromstring(Fx.maphead) }, { mutations = 300 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user