ws-game: docs/guide sections (game archives, game models, game textures) with tested snippets (tools/fixtures/docs_game.py); bench lines (explode, mpq, wad map)
This commit is contained in:
1 parent
3d01293b82
commit
0b1c5ebfec
5 files changed
+267
No files matched your search
@@ -1102,3 +1102,45 @@ do
|
||||
Bcn.decode("bc6h", b6, 0, w, h)
|
||||
end)
|
||||
end
|
||||
do
|
||||
-- game formats (ws-game): PKWARE DCL explode (StormLib's implode streams from tools/fixtures/mpq.py), reading every
|
||||
-- file of a StormLib MPQ (MB/s of file data), Freedoom's MAP01 to a Scene (tools/fixtures/wad.py: sector
|
||||
-- outlines, triangulation, walls; MB/s of map lumps), an MD2 with every frame as a morph target
|
||||
local Explode = require("@formats/codecs/compress/Explode")
|
||||
local Mpq = require("@formats/archive/mpq")
|
||||
local Wad = require("@formats/archive/wad")
|
||||
local MQ = require("@tests/gen/mpq")
|
||||
local WD = require("@tests/gen/wad")
|
||||
for _, c in MQ.implode do
|
||||
if c.name == "text" or c.name == "ascii-4096" or c.name == "binary-2048" then
|
||||
local data = buffer.fromstring(c.data)
|
||||
bench("explode " .. c.name .. " (" .. c.size .. " B)", 20, c.size, function()
|
||||
Explode.decompress(data)
|
||||
end)
|
||||
end
|
||||
end
|
||||
local arch = MQ.archives[1]
|
||||
local mb = buffer.fromstring(arch.data)
|
||||
local a = assert(Mpq.decode(Bytes.reader(mb)))
|
||||
local total = 0
|
||||
for _, e in a:list() do
|
||||
total += e.size
|
||||
end
|
||||
bench("mpq read every file (v1)", 5, total, function()
|
||||
local m = Mpq.decode(Bytes.reader(mb))
|
||||
for _, e in m:list() do
|
||||
m:read(e.name)
|
||||
end
|
||||
end)
|
||||
local wb = buffer.fromstring(WD.freedoom.data)
|
||||
local w = assert(Wad.decode(Bytes.reader(wb)))
|
||||
local lumps = 0
|
||||
for _, l in Wad.lumps(w) :: any do
|
||||
if l.map == "MAP01" then
|
||||
lumps += l.size
|
||||
end
|
||||
end
|
||||
bench("wad MAP01 -> Scene (no textures)", 3, lumps, function()
|
||||
Wad.map(w, "MAP01", { textures = false })
|
||||
end)
|
||||
end
|
||||
@@ -0,0 +1,78 @@
|
||||
# Docs inputs for the game formats sections of the archive / scene / image pages (tools/fixtures.py;
|
||||
# tools/docs_check.py explains the inputs), made with the writers of the format fixtures: a Quake PAK
|
||||
# (tools/fixtures/pak.py), a PWAD with a room map, a flat and a tall patch (wad.py), a Build GRP, a VPK (Python's vpk
|
||||
# package, through vpk.py), an MPQ (StormLib, through mpq.py), an MD2 (md2.py), an .md5mesh + .md5anim (md5.py), an
|
||||
# SMD (smd.py), a Half-Life BSP (bsp.py), a PlayStation TIM (tim.py), a BLP2 (blp.py) and a VTF 7.2.
|
||||
# tests/gen/docs_game.luau { files = { [name] = bytes }, vars = { pakBytes = "pak0.pak", ... } }
|
||||
import importlib.util, json, os, struct, tempfile, shutil
|
||||
|
||||
INPUTS = ["tools/docs_check.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 vtf72(w, h, rgba):
|
||||
hd = bytearray(80)
|
||||
struct.pack_into("<4sIIIHHIHH", hd, 0, b"VTF\0", 7, 2, 80, w, h, 0, 1, 0)
|
||||
struct.pack_into("<f", hd, 48, 1.0)
|
||||
struct.pack_into("<iBiBBH", hd, 52, 0, 1, -1, 0, 0, 1)
|
||||
return bytes(hd) + rgba
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
rng = ctx.rng(3)
|
||||
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)
|
||||
files = {}
|
||||
files["pak0.pak"] = mod(ctx, "pak").write([("maps/start.bsp", rng.randbytes(64)), ("gfx/palette.lmp", bytes(range(256)) * 3),
|
||||
("progs/player.mdl", rng.randbytes(32)), ("default.cfg", b"bind w +forward\n")])
|
||||
files["room.wad"], _ = mod(ctx, "wad").room()
|
||||
files["duke.grp"] = mod(ctx, "grp").write([("GAME.CON", b"define X 1\n"), ("E1L1.MAP", rng.randbytes(40))])
|
||||
# VPK: the vpk package
|
||||
vpk = mod(ctx, "vpk")
|
||||
tmp = tempfile.mkdtemp(prefix="formats-docs-game-")
|
||||
try:
|
||||
src = os.path.join(tmp, "src")
|
||||
for name, data in (("materials/brick/wall.vmt", b"LightmappedGeneric { }"), ("scripts/game.txt", b"\"game\" { }\n")):
|
||||
p = os.path.join(src, name)
|
||||
os.makedirs(os.path.dirname(p), exist_ok=True)
|
||||
open(p, "wb").write(data)
|
||||
out = os.path.join(tmp, "pak01_dir.vpk")
|
||||
ctx.python(["vpk"], vpk.WRITE, input=json.dumps({"src": src, "version": 2, "out": out}).encode())
|
||||
files["pak01_dir.vpk"] = open(out, "rb").read()
|
||||
# MPQ: StormLib
|
||||
mpq = mod(ctx, "mpq")
|
||||
txt = os.path.join(tmp, "readme.txt")
|
||||
open(txt, "wb").write(b"Warcraft III map notes\n" * 20)
|
||||
arch = {"name": "map", "path": os.path.join(tmp, "map.w3x"), "create": 0x00100000,
|
||||
"files": [{"name": "war3map.j", "src": txt, "flags": mpq.COMPRESS | mpq.REPLACE, "comp": mpq.ZLIB},
|
||||
{"name": "readme.txt", "src": txt, "flags": mpq.IMPLODE | mpq.REPLACE, "comp": mpq.PKWARE}]}
|
||||
ctx.python([], mpq.CODE, input=json.dumps({"lib": mpq.lib_path(), "archives": [arch], "implode": [], "modes": []}).encode())
|
||||
files["map.w3x"] = open(arch["path"], "rb").read()
|
||||
finally:
|
||||
shutil.rmtree(tmp)
|
||||
files["tank.md2"], _, _ = mod(ctx, "md2").md2(rng, 12, 12, 10, ["stand1", "stand2", "run1", "run2", "run3"], ["models/tank/skin.pcx"])
|
||||
md5 = mod(ctx, "md5")
|
||||
text, info = md5.mesh(rng)
|
||||
files["imp.md5mesh"] = text.encode()
|
||||
atext, _ = md5.anim(rng, info["joints"], 5, 24, "idle")
|
||||
files["idle.md5anim"] = atext.encode()
|
||||
stext, _ = mod(ctx, "smd").smd(rng, 3, 4, 6, ["skin.bmp"], True, False)
|
||||
files["barney.smd"] = stext.encode()
|
||||
files["crossfire.bsp"] = mod(ctx, "bsp").brush_map(rng, "hl", bytes(768))["data"]
|
||||
tdata, _, _, _ = mod(ctx, "tim").tim(rng, 16, 8, 4)
|
||||
files["face.tim"] = tdata
|
||||
files["icon.blp"] = mod(ctx, "blp").blp2(1, 3, 8, 8, 4, 4, [rng.randbytes(64)])
|
||||
files["wall.vtf"] = vtf72(4, 4, rng.randbytes(64))
|
||||
check.emit_inputs(ctx, files, {
|
||||
"pakBytes": "pak0.pak", "wadBytes": "room.wad", "grpBytes": "duke.grp", "vpkBytes": "pak01_dir.vpk",
|
||||
"mpqBytes": "map.w3x", "md2Bytes": "tank.md2", "md5meshBytes": "imp.md5mesh", "md5animBytes": "idle.md5anim",
|
||||
"smdBytes": "barney.smd", "bspBytes": "crossfire.bsp", "timBytes": "face.tim", "blpBytes": "icon.blp",
|
||||
"vtfBytes": "wall.vtf",
|
||||
})
|
||||
Reference in new issue
Block a user