merge ws/build

This commit is contained in:
4DBug committed 2026-11-01 19:18:53 -06:00
commit 9ae847d2a3
22 files changed
+6770 -1123

No files matched your search

+30
View File
@@ -1902,3 +1902,33 @@ do
jitTune(false)
end
end
do
-- Build engine (ws-build): an ART of 64 random 128 x 128 tiles to rgba8 through a palette (MB/s of rgba8 output),
-- and the two-room map of tools/fixtures/buildmap.py to a Scene (MB/s of map bytes)
local Art = require("@rosetta/image/art")
local BuildMap = require("@rosetta/model/buildmap")
local AF = require("@tests/gen/art")
local BF = require("@tests/gen/buildmap")
local rnd = 12345
local frames: { Types.Frame } = {}
for i = 1, 64 do
local img = Types.Image.new(128, 128, "gray8")
for k = 0, 128 * 128 - 1 do
rnd = (rnd * 1103515245 + 12345) % 2147483648
buffer.writeu8(img.pixels, k, rnd % 256)
end
img.meta.tile = i - 1
frames[i] = { image = img, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" }
end
local top = Types.Image.new(1, 1, "gray8")
top.frames = frames
local art = assert(Art.encode(top))
local pal = buffer.fromstring(AF.palette)
bench("art decode 64 x 128x128 -> rgba8", 3, 64 * 128 * 128 * 4, function()
Art.decode(Bytes.reader(art), { palette = pal })
end)
local map = buffer.fromstring(BF.maps[1].data)
bench("buildmap rooms -> Scene", 20, buffer.len(map), function()
BuildMap.decode(Bytes.reader(map))
end)
end
+106
View File
@@ -0,0 +1,106 @@
# Build engine reference tools for the art / buildmap fixtures: arttool (Jonathon Fowler, Artistic License 2.0) and
# map2stl (Ken Silverman) compiled from the nix eduke32 source (nixpkgs#eduke32.src, never committed) with g++ and a
# small compat.h stub written here: stdio and a few B* aliases, a NULL-safe Bfclose, and a DO_FREE_AND_NULL that leaks
# (arttool's Bstring copy constructor frees an uninitialised pointer). Binaries are cached in tests/gen/.buildtools/.
import os, subprocess
STUB = r"""
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <sys/stat.h>
#include <unistd.h>
#define Bassert assert
#define Bfclose(f) ((f) ? fclose(f) : 0)
#define Bfileno fileno
#define Bfopen fopen
#define Bfprintf fprintf
#define Bfputc fputc
#define Bfread fread
#define Bfseek fseek
#define Bfstat fstat
#define Bftell ftell
#define Bfwrite fwrite
#define Bmalloc malloc
#define Bprintf printf
#define Brealloc realloc
#define Brewind rewind
#define Bstat stat
#define Bstrcat strcat
#define Bstrcmp strcmp
#define Bstrdup strdup
#define Bstrlen strlen
#define BFILE FILE
#define DO_FREE_AND_NULL(x) do { (x) = NULL; } while (0)
#define EDUKE32_PREDICT_FALSE(x) (x)
#define ATTRIBUTE(x)
"""
def tools(ctx):
"""{"arttool": path, "map2stl": path}"""
out = os.path.join(ctx.gen, ".buildtools")
paths = {n: os.path.join(out, n) for n in ("arttool", "map2stl")}
if all(os.path.exists(p) for p in paths.values()):
return paths
os.makedirs(out, exist_ok=True)
src = subprocess.run(["nix", "build", "--no-link", "--print-out-paths", "nixpkgs#eduke32.src"], capture_output=True,
check=True).stdout.decode().strip().split("\n")[-1]
stub = os.path.join(out, "stub")
os.makedirs(stub, exist_ok=True)
with open(os.path.join(stub, "compat.h"), "w") as f:
f.write(STUB)
for name, path in paths.items():
ctx.nix("gcc", ["g++", "-O1", "-w", "-funsigned-char", "-I" + stub, os.path.join(src, "source/tools/src/%s.cpp" % name),
"-o", path])
return paths
def pcx_write(w, h, idx, pal):
"""8-bit RLE PCX (version 5) of row-major indices with a 256 x RGB palette, as arttool reads it"""
bpl = w + (w & 1)
hd = bytearray(128)
hd[0:4] = bytes([10, 5, 1, 8])
hd[8:10] = (w - 1).to_bytes(2, "little")
hd[10:12] = (h - 1).to_bytes(2, "little")
hd[65] = 1
hd[66:68] = bpl.to_bytes(2, "little")
hd[68] = 1
out = bytearray(hd)
for y in range(h):
row = list(idx[y * w:(y + 1) * w]) + [0] * (bpl - w)
i = 0
while i < bpl:
v, n = row[i], 1
while i + n < bpl and n < 63 and row[i + n] == v:
n += 1
if n > 1 or v >= 0xC0:
out.append(0xC0 | n)
out.append(v)
i += n
out.append(12)
out += bytes(pal)
return bytes(out)
def pcx_read(data):
"""(w, h, row-major indices, 768-byte palette) of an 8-bit RLE PCX"""
w = int.from_bytes(data[8:10], "little") - int.from_bytes(data[4:6], "little") + 1
h = int.from_bytes(data[10:12], "little") - int.from_bytes(data[6:8], "little") + 1
bpl = int.from_bytes(data[66:68], "little")
raw, p = bytearray(), 128
while len(raw) < bpl * h:
c = data[p]
p += 1
if c >= 0xC0:
raw += bytes([data[p]]) * (c & 63)
p += 1
else:
raw.append(c)
idx = bytearray()
for y in range(h):
idx += raw[y * bpl:y * bpl + w]
return w, h, bytes(idx), data[-768:]
+117
View File
@@ -0,0 +1,117 @@
# Build ART fixtures (tools/fixtures.py). No Duke 3D data (proprietary): a random PALETTE.DAT (256 distinct 6-bit
# colours, 32 shade tables, a translucency table) and LOOKUP.DAT (palookups 1 and 5, five alternate palettes) are
# made here. References, from the nix eduke32 source (tools/fixtures/_build_ref.py):
# - arttool create / addtile builds TILES000.ART (tiles 10..15, two of them empty) from 8-bit PCX files written
# here, with centre offsets and animation fields; `arttool info` gives the per-tile fields;
# - arttool exporttile writes each tile back as PCX through palette.dat (<< 2 scaling): its RGB is the reference;
# - an independent Python reading of the ART bytes (BUILDINF.TXT layout) gives each tile's column-major indices.
# tests/gen/art.luau { art, palette, lookup, start, last, tiles = { { tile, w, h, idx, rgb, xofs, yofs, animType,
# animFrames, animSpeed, picanm } }, shade = { n, table }, remap = { pal, table } }
import os, shutil, struct, subprocess, tempfile, importlib.util
_spec = importlib.util.spec_from_file_location("_build_ref", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_build_ref.py"))
B = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(B)
INPUTS = ["tools/fixtures/_build_ref.py"]
def palette_dat(rng):
cols, seen = [], set()
while len(cols) < 256:
c = (rng.randrange(64), rng.randrange(64), rng.randrange(64))
if c not in seen:
seen.add(c)
cols.append(c)
pal = bytes(v for c in cols for v in c)
shades = rng.randbytes(32 * 256)
return pal + struct.pack("<H", 32) + shades + rng.randbytes(65536)
def lookup_dat(rng):
out = bytearray([2])
for n in (1, 5):
out.append(n)
out += rng.randbytes(256)
for _ in range(5):
out += bytes(rng.randrange(64) for _ in range(768))
return bytes(out)
def parse_art(data):
"""independent ART reading: (first, last, [(w, h, picanm, column-major bytes)])"""
ver, _, first, last = struct.unpack_from("<4I", data, 0)
assert ver == 1
n = last - first + 1
xs = struct.unpack_from("<%dh" % n, data, 16)
ys = struct.unpack_from("<%dh" % n, data, 16 + 2 * n)
anm = struct.unpack_from("<%dI" % n, data, 16 + 4 * n)
p, tiles = 16 + 8 * n, []
for i in range(n):
size = xs[i] * ys[i]
tiles.append((xs[i], ys[i], anm[i], data[p:p + size]))
p += size
return first, last, tiles
SPECS = [ # tile, w, h, addtile options
(10, 16, 8, ["-x", "3", "-y", "-2"]),
(11, 1, 5, ["-ann", "3", "-ant", "2", "-ans", "4"]),
(13, 33, 17, ["-x", "-7", "-ann", "63", "-ant", "1", "-ans", "15"]),
(15, 64, 64, ["-y", "100", "-ant", "3"]),
]
def generate(ctx):
rng = ctx.rng(1997)
tools = B.tools(ctx)
pal_dat = palette_dat(rng)
pal8 = bytes(v << 2 for v in pal_dat[:768])
lookup = lookup_dat(rng)
tmp = tempfile.mkdtemp(prefix="rosetta-art-")
try:
run = lambda *a: subprocess.run([tools["arttool"]] + list(a), cwd=tmp, capture_output=True, check=True).stdout.decode()
run("create", "-o", "10", "-n", "6")
made = {}
for tile, w, h, extra in SPECS:
idx = bytes(rng.randrange(256) if rng.random() < 0.85 else 255 for _ in range(w * h))
made[tile] = idx
with open(os.path.join(tmp, "t%d.pcx" % tile), "wb") as f:
f.write(B.pcx_write(w, h, idx, pal8))
run("addtile", *extra, str(tile), "t%d.pcx" % tile)
art = open(os.path.join(tmp, "tiles000.art"), "rb").read()
with open(os.path.join(tmp, "palette.dat"), "wb") as f:
f.write(pal_dat)
info = {}
for line in run("info").split("\n"):
line = line.strip()
if line.startswith("Tile "):
head, rest = line.split(": ", 1)
t = int(head.split()[1])
size, rest = rest.split(" ", 1)
fields = dict(kv.split(": ") for kv in rest.split(", "))
info[t] = (size, {k: int(v) for k, v in fields.items()})
first, last, parsed = parse_art(art)
tiles = []
for i, (w, h, anm, cols) in enumerate(parsed):
t = first + i
size, f = info[t]
assert size == "%dx%d" % (w, h)
e = {"tile": t, "w": w, "h": h, "picanm": anm, "xofs": f["Xofs"], "yofs": f["Yofs"], "animType": f["AnimType"],
"animFrames": f["AnimFrames"], "animSpeed": f["AnimSpeed"]}
if w * h > 0:
idx = bytes(cols[x * h + y] for y in range(h) for x in range(w))
assert idx == made[t]
run("exporttile", str(t))
pw, ph, pidx, ppal = B.pcx_read(open(os.path.join(tmp, "tile%04d.pcx" % t), "rb").read())
assert (pw, ph, pidx) == (w, h, idx)
e["idx"] = idx
e["rgb"] = bytes(ppal[v * 3 + k] for v in pidx for k in range(3))
tiles.append(e)
finally:
shutil.rmtree(tmp)
ctx.emit("art", {
"art": art, "palette": pal_dat, "lookup": lookup, "start": first, "last": last, "tiles": tiles,
"shade": {"n": 7, "table": pal_dat[770 + 7 * 256:770 + 8 * 256]},
"remap": {"pal": 5, "table": lookup[1 + 257 + 1:1 + 257 + 257]},
})
+223
View File
@@ -0,0 +1,223 @@
# Build .map fixtures (tools/fixtures.py). No Duke 3D / Shadow Warrior maps (proprietary): maps are written here from
# BUILDINF.TXT (v7 layout; v8 / v9 share it), red walls linked by matching reversed wall segments. References:
# - an independent Python reading of each map: field sums per table, every sector's loops, and the floor / ceiling
# z of every sector at each of its wall points by the BUILDINF slope formula;
# - Ken Silverman's map2stl (eduke32 source, tools/fixtures/_build_ref.py) turns the v7 bytes of each map into an
# STL: total area and area-weighted centroid of its floor / ceiling triangles and of its wall triangles.
# tests/gen/buildmap.luau { maps = { { name, data, version, counts = { sectors, walls, sprites }, sums = { sector =
# { field = sum }, wall, sprite }, loops = { { { wall } } }, z = { { sector, x, y, floor,
# ceiling } }, stl = { floorArea, wallArea, floorCentroid = { x, y, z }, wallCentroid } } } }
import os, struct, subprocess, tempfile, shutil, importlib.util
_spec = importlib.util.spec_from_file_location("_build_ref", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_build_ref.py"))
B = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(B)
INPUTS = ["tools/fixtures/_build_ref.py"]
SECTOR = [("wallptr", "h"), ("wallnum", "h"), ("ceilingz", "i"), ("floorz", "i"), ("ceilingstat", "h"), ("floorstat", "h"),
("ceilingpicnum", "h"), ("ceilingheinum", "h"), ("ceilingshade", "b"), ("ceilingpal", "B"), ("ceilingxpanning", "B"),
("ceilingypanning", "B"), ("floorpicnum", "h"), ("floorheinum", "h"), ("floorshade", "b"), ("floorpal", "B"),
("floorxpanning", "B"), ("floorypanning", "B"), ("visibility", "B"), ("filler", "B"), ("lotag", "h"), ("hitag", "h"),
("extra", "h")]
WALL = [("x", "i"), ("y", "i"), ("point2", "h"), ("nextwall", "h"), ("nextsector", "h"), ("cstat", "h"), ("picnum", "h"),
("overpicnum", "h"), ("shade", "b"), ("pal", "B"), ("xrepeat", "B"), ("yrepeat", "B"), ("xpanning", "B"),
("ypanning", "B"), ("lotag", "h"), ("hitag", "h"), ("extra", "h")]
SPRITE = [("x", "i"), ("y", "i"), ("z", "i"), ("cstat", "h"), ("picnum", "h"), ("shade", "b"), ("pal", "B"), ("clipdist", "B"),
("filler", "B"), ("xrepeat", "B"), ("yrepeat", "B"), ("xoffset", "b"), ("yoffset", "b"), ("sectnum", "h"),
("statnum", "h"), ("ang", "h"), ("owner", "h"), ("xvel", "h"), ("yvel", "h"), ("zvel", "h"), ("lotag", "h"),
("hitag", "h"), ("extra", "h")]
FMT = {name: "<" + "".join(t for _, t in fields) for name, fields in (("sector", SECTOR), ("wall", WALL), ("sprite", SPRITE))}
assert [struct.calcsize(FMT[k]) for k in ("sector", "wall", "sprite")] == [40, 32, 44]
class MapBuilder:
def __init__(self, rng):
self.rng = rng
self.sectors, self.walls, self.sprites = [], [], []
def sector(self, loops, **f):
"""loops: outer loop first (positive shoelace in Build's y-down coordinates), then holes (negative)"""
start = len(self.walls)
for li, loop in enumerate(loops):
area = sum(loop[i][0] * loop[(i + 1) % len(loop)][1] - loop[(i + 1) % len(loop)][0] * loop[i][1] for i in range(len(loop)))
assert (area > 0) == (li == 0), "loop orientation"
base = len(self.walls)
for i, (x, y) in enumerate(loop):
self.walls.append({"x": x, "y": y, "point2": base + (i + 1) % len(loop), "nextwall": -1, "nextsector": -1,
"cstat": 0, "picnum": self.rng.randrange(1, 40), "overpicnum": 0, "shade": self.rng.randrange(-8, 20),
"pal": 0, "xrepeat": 8, "yrepeat": 8, "xpanning": self.rng.randrange(256),
"ypanning": self.rng.randrange(256), "lotag": 0, "hitag": 0, "extra": -1})
s = {k: 0 for k, _ in SECTOR}
s.update({"wallptr": start, "wallnum": len(self.walls) - start, "extra": -1, "ceilingpicnum": self.rng.randrange(1, 40),
"floorpicnum": self.rng.randrange(1, 40), "visibility": self.rng.randrange(256)})
s.update(f)
self.sectors.append(s)
return len(self.sectors) - 1
def link(self):
"""red walls: a wall a -> b of one sector and b -> a of another"""
seg = {}
for si, s in enumerate(self.sectors):
for w in range(s["wallptr"], s["wallptr"] + s["wallnum"]):
a, b = self.walls[w], self.walls[self.walls[w]["point2"]]
seg[(a["x"], a["y"], b["x"], b["y"])] = (si, w)
for si, s in enumerate(self.sectors):
for w in range(s["wallptr"], s["wallptr"] + s["wallnum"]):
a, b = self.walls[w], self.walls[self.walls[w]["point2"]]
o = seg.get((b["x"], b["y"], a["x"], a["y"]))
if o:
a["nextsector"], a["nextwall"] = o
def sprite(self, **f):
sp = {k: 0 for k, _ in SPRITE}
sp.update({"xrepeat": 64, "yrepeat": 64, "clipdist": 32, "owner": -1, "picnum": self.rng.randrange(1000, 2000),
"ang": self.rng.randrange(2048), "lotag": self.rng.randrange(100)})
sp.update(f)
self.sprites.append(sp)
def write(self, version, pos=(512, 512, -4096), ang=512, cursect=0, trailing=b""):
out = bytearray(struct.pack("<iiiihh", version, *pos, ang, cursect))
for name, rows, fields in (("sector", self.sectors, SECTOR), ("wall", self.walls, WALL), ("sprite", self.sprites, SPRITE)):
out += struct.pack("<H", len(rows))
for r in rows:
out += struct.pack(FMT[name], *[r[k] for k, _ in fields])
return bytes(out) + trailing
def parse(data):
"""independent reading: (version, {"sector": [...], "wall": [...], "sprite": [...]})"""
version = struct.unpack_from("<i", data, 0)[0]
p, tables = 20, {}
for name, fields in (("sector", SECTOR), ("wall", WALL), ("sprite", SPRITE)):
n = struct.unpack_from("<H", data, p)[0]
p += 2
size = struct.calcsize(FMT[name])
tables[name] = [dict(zip([k for k, _ in fields], struct.unpack_from(FMT[name], data, p + i * size))) for i in range(n)]
p += n * size
return version, tables
def slope_z(t, si, floor, x, y):
s = t["sector"][si]
pre = "floor" if floor else "ceiling"
z = s[pre + "z"]
if not s[pre + "stat"] & 2 or s[pre + "heinum"] == 0:
return z
w0 = t["wall"][s["wallptr"]]
w1 = t["wall"][w0["point2"]]
dx, dy = w1["x"] - w0["x"], w1["y"] - w0["y"]
ln = (dx * dx + dy * dy) ** 0.5
return z + s[pre + "heinum"] * (dx * (y - w0["y"]) - dy * (x - w0["x"])) / (ln * 256)
def loops_of(t, si):
s, out, seen = t["sector"][si], [], set()
for start in range(s["wallptr"], s["wallptr"] + s["wallnum"]):
if start in seen:
continue
loop, w = [], start
while w not in seen:
seen.add(w)
loop.append(w)
w = t["wall"][w]["point2"]
out.append(loop)
return out
def stl_stats(stl):
n = struct.unpack_from("<I", stl, 80)[0]
acc = {"floor": [0.0, 0.0, 0.0, 0.0], "wall": [0.0, 0.0, 0.0, 0.0]}
for i in range(n):
v = struct.unpack_from("<12f", stl, 84 + i * 50)
nz, a, b, c = v[2], v[3:6], v[6:9], v[9:12]
ux, uy, uz = b[0] - a[0], b[1] - a[1], b[2] - a[2]
vx, vy, vz = c[0] - a[0], c[1] - a[1], c[2] - a[2]
cx, cy, cz = uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx
area = 0.5 * (cx * cx + cy * cy + cz * cz) ** 0.5
k = acc["wall" if abs(nz) < 1e-6 else "floor"]
k[0] += area
for d in range(3):
k[d + 1] += area * (a[d] + b[d] + c[d]) / 3
res = {}
for k, (area, sx, sy, sz) in acc.items():
res[k + "Area"] = area
res[k + "Centroid"] = [sx / area, sy / area, sz / area] if area > 0 else [0.0, 0.0, 0.0]
return res
def rooms(rng):
m = MapBuilder(rng)
# a hall with a sloped platform sector inside (the hall's hole) and a red-wall opening to a sloped east room
m.sector([[(0, 0), (4096, 0), (4096, 1024), (4096, 3072), (4096, 4096), (0, 4096)],
[(1024, 1024), (1024, 2048), (2048, 2048), (2048, 1024)]], floorz=0, ceilingz=-32768)
m.sector([[(4096, 1024), (6144, 1024), (6144, 3072), (4096, 3072)]], floorz=-4096, ceilingz=-24576,
floorstat=2, floorheinum=-1024, ceilingstat=2 | 64, ceilingheinum=512, floorxpanning=17)
m.sector([[(1024, 1024), (2048, 1024), (2048, 2048), (1024, 2048)]], floorz=-8192, ceilingz=-28672,
floorstat=2 | 4 | 16, floorheinum=4096, ceilingstat=8 | 32)
m.link()
for w in m.walls:
if (w["x"], w["y"]) == (4096, 1024) and w["nextsector"] == 1:
w["cstat"] |= 16 | 4
w["overpicnum"] = 77
if w["nextsector"] == 2:
w["cstat"] |= 2 | 8
m.walls[0]["cstat"] |= 256
m.sprite(x=300, y=400, z=0, sectnum=0, cstat=1)
m.sprite(x=5000, y=2000, z=-4096, sectnum=1, cstat=16, ang=0)
m.sprite(x=1500, y=1500, z=-8192, sectnum=2, cstat=32 | 4, ang=1024)
return m
def sky(rng):
m = MapBuilder(rng)
m.sector([[(0, 0), (2048, 0), (2048, 2048), (0, 2048)]], floorz=0, ceilingz=-16384, ceilingstat=1)
m.sector([[(2048, 0), (4096, 0), (4096, 2048), (2048, 2048)]], floorz=1024, ceilingz=-20480, ceilingstat=1)
m.link()
m.sprite(x=1000, y=1000, z=0, sectnum=0)
return m
def yax(rng):
m = MapBuilder(rng)
m.sector([[(0, 0), (1024, 0), (1024, 1024), (0, 1024)]], floorz=0, ceilingz=-8192, ceilingstat=1024, ceilingxpanning=3)
m.sector([[(0, 0), (1024, 0), (1024, 1024), (0, 1024)]], floorz=-8192, ceilingz=-16384, floorstat=1024, floorxpanning=3)
m.walls[0]["cstat"] |= 1024
m.walls[0]["lotag"] = 4
m.walls[5]["cstat"] |= 2048
m.walls[5]["extra"] = 0
return m
def generate(ctx):
rng = ctx.rng(1996)
tools = B.tools(ctx)
specs = [("rooms", rooms(rng), 7, b""), ("sky", sky(rng), 8, b""), ("yax", yax(rng), 9, b""),
("trailing", rooms(rng), 7, b"EXTRA DATA\x00\x01")]
maps = []
tmp = tempfile.mkdtemp(prefix="rosetta-buildmap-")
try:
for name, m, version, trailing in specs:
data = m.write(version, trailing=trailing)
v, t = parse(data)
assert v == version
e = {"name": name, "data": data, "version": version,
"counts": {"sectors": len(t["sector"]), "walls": len(t["wall"]), "sprites": len(t["sprite"])},
"sums": {k: {f: sum(r[f] for r in rows) for f, _ in fields} for k, rows, fields in
(("sector", t["sector"], SECTOR), ("wall", t["wall"], WALL), ("sprite", t["sprite"], SPRITE))},
"loops": [loops_of(t, si) for si in range(len(t["sector"]))], "z": []}
for si, s in enumerate(t["sector"]):
for w in range(s["wallptr"], s["wallptr"] + s["wallnum"]):
x, y = t["wall"][w]["x"], t["wall"][w]["y"]
e["z"].append({"sector": si, "x": x, "y": y, "floor": float(slope_z(t, si, True, x, y)),
"ceiling": float(slope_z(t, si, False, x, y))})
if name != "yax":
src, dst = os.path.join(tmp, name + ".map"), os.path.join(tmp, name + ".stl")
with open(src, "wb") as f:
f.write(m.write(7))
subprocess.run([tools["map2stl"], src, dst], capture_output=True, check=True)
e["stl"] = stl_stats(open(dst, "rb").read())
maps.append(e)
finally:
shutil.rmtree(tmp)
ctx.emit("buildmap", {"maps": maps})
+38
View File
@@ -0,0 +1,38 @@
# Docs inputs for the Build engine sections of the image / scene pages (tools/fixtures.py; tools/docs_check.py explains
# the inputs): an ART file of three tiles and a random PALETTE.DAT written here (BUILDINF.TXT layout), and the two-room
# map of tools/fixtures/buildmap.py.
# tests/gen/docs_build.luau { files = { [name] = bytes }, vars = { artBytes = "TILES000.ART", ... } }
import importlib.util, os, struct
INPUTS = ["tools/docs_check.py", "tools/fixtures/buildmap.py"]
def mod(ctx, path, name):
spec = importlib.util.spec_from_file_location(name, os.path.join(ctx.root, path))
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
def art(rng, first, tiles):
"""tiles: [(w, h, picanm)]; column-major random indices"""
out = bytearray(struct.pack("<4I", 1, 0, first, first + len(tiles) - 1))
out += b"".join(struct.pack("<h", w) for w, _, _ in tiles)
out += b"".join(struct.pack("<h", h) for _, h, _ in tiles)
out += b"".join(struct.pack("<I", a) for _, _, a in tiles)
for w, h, _ in tiles:
out += bytes(rng.randrange(255) for _ in range(w * h))
return bytes(out)
def generate(ctx):
rng = ctx.rng(5)
check = mod(ctx, "tools/docs_check.py", "docs_check")
bm = mod(ctx, "tools/fixtures/buildmap.py", "fx_buildmap")
pal = bytes(rng.randrange(64) for _ in range(768)) + struct.pack("<H", 1) + bytes(range(256))
files = {
"TILES000.ART": art(rng, 0, [(16, 16, 0), (8, 4, 2 | (2 << 6) | (3 << 24)), (0, 0, 0)]),
"PALETTE.DAT": pal,
"E1L1.MAP": bm.rooms(rng).write(7),
}
check.emit_inputs(ctx, files, {"artBytes": "TILES000.ART", "paletteBytes": "PALETTE.DAT", "buildmapBytes": "E1L1.MAP"})