docs/guide: Quake maps and BSP, WAD2 / WAD3, lmp / spr, Quake III shaders and skins; bench lines; q3skin sniff needs a path

This commit is contained in:
4DBug committed 2026-11-01 19:25:25 -06:00
1 parent 175ca9e823
commit 1e69799c21
11 files changed
+663 -461

No files matched your search

+21
View File
@@ -1902,3 +1902,24 @@ do
jitTune(false)
end
end
-- ws-quake: .map brushes to polygons (codecs/model/Brush clip + CSG hull + merge; MB/s of map text) and a compiled
-- BSP with its lightmap atlas and tree (MB/s of file); fixtures tools/fixtures/map.py, tools/fixtures/bsp.py
do
local MapFmt = require("@rosetta/model/map")
local BspFmt = require("@rosetta/model/bsp")
local Bytes = require("@rosetta/core/Bytes")
local MF = require("@tests/gen/map")
local BF = require("@tests/gen/bsp")
local text = buffer.fromstring(MF.quake.text)
bench("map decode (brushes)", 5, buffer.len(text), function()
assert(MapFmt.decode(Bytes.reader(text), { files = MF.quake.files }))
end)
bench("map decode (hull + merge)", 5, buffer.len(text), function()
assert(MapFmt.decode(Bytes.reader(text), { files = MF.quake.files, hull = true, merge = true }))
end)
local bsp = buffer.fromstring(BF.ericw.bsp29.data)
bench("bsp decode (lightmaps, tree)", 5, buffer.len(bsp), function()
assert(BspFmt.decode(Bytes.reader(bsp)))
end)
end
+49
View File
@@ -0,0 +1,49 @@
# Docs inputs for the Quake sections of the scene / archive / image / data pages (tools/fixtures.py; tools/docs_check.py
# explains the inputs): the room .map of map.py with its WAD2, the same room compiled by ericw-tools (qbsp + vis, the
# lighting lump filled by _qbsp.light), a gfx.wad-like WAD2 (wad2.py's writer), a qpic .lmp and a random palette.lmp
# (Quake's own is GPL), a Half-Life sprite (spr.py), a shader script and a .skin (q3shader.py).
# tests/gen/docs_quake.luau { files = { [name] = bytes }, vars = { roomMapText = "room.map", ... } }
import importlib.util, os, struct
INPUTS = ["tools/docs_check.py", "tools/fixtures/_qbsp.py", "tools/fixtures/map.py", "tools/fixtures/spr.py",
"tools/fixtures/q3shader.py"]
def mod(ctx, name):
spec = importlib.util.spec_from_file_location("fx_" + name, os.path.join(ctx.root, "tools", "fixtures", name + ".py"))
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
def generate(ctx):
rng = ctx.rng(9)
spec = importlib.util.spec_from_file_location("docs_check", os.path.join(ctx.root, "tools", "docs_check.py"))
check = importlib.util.module_from_spec(spec)
spec.loader.exec_module(check)
H, M, B = mod(ctx, "_qbsp"), mod(ctx, "map"), mod(ctx, "brush")
files = {}
pal = bytes(rng.randrange(256) for _ in range(768))
texwad = H.wad([(n, 0x44, H.miptex(n, w, h, rng)) for n, w, h in M.TEX])
world, door = M.layout(rng)
text = M.write(B, "quake", world, door, rng, "gfx/tex.wad")
files["room.map"] = text
files["tex.wad"] = texwad
res = H.compile(ctx, text.replace("gfx/tex.wad", "tex.wad"), {"tex.wad": texwad}, ["-nopercent"], vis=True)
files["room.bsp"], _ = H.light(H.read_bsp(res["bsp"]), rng)
qp = bytes(rng.randrange(256) for _ in range(24 * 24))
files["palette.lmp"] = pal
files["disc.lmp"] = struct.pack("<II", 24, 24) + qp
mips = [bytes(rng.randrange(256) for _ in range((32 >> m) * (32 >> m))) for m in range(4)]
files["gfx.wad"] = H.wad([("palette", 0x40, pal), ("disc", 0x42, files["disc.lmp"]),
("brick", 0x44, H.miptex("brick", 32, 32, rng, pixels=mips))])
S = mod(ctx, "spr")
files["flame.spr"] = S.sprite(rng, 2, [("single", (-16, 16, 32, 32)), ("group", [0.1, 0.2], [(-8, 8, 16, 16), (-8, 8, 16, 16)])], pal)["data"]
Q = mod(ctx, "q3shader")
files["base.shader"] = Q.SCRIPTS[0]
files["sarge.skin"] = Q.SKINS[0]
check.emit_inputs(ctx, files, {
"roomMapText": "room.map", "texWadBytes": "tex.wad", "roomBspBytes": "room.bsp", "quakePaletteBytes": "palette.lmp",
"discLmpBytes": "disc.lmp", "gfxWadBytes": "gfx.wad", "flameSprBytes": "flame.spr", "shaderText": "base.shader",
"skinText": "sarge.skin",
})