# Wolfenstein 3D fixtures (tools/fixtures.py). id's data and source are not redistributable / GPL, so everything is # written here by this script's own writers from the ModdingWiki format descriptions: a random 6-bit palette; a VSWAP # with walls, sprites (t_compshape posts, with gaps), sound pages and the sound info page; a GAMEMAPS + MAPHEAD pair # with two maps (slots 1 and 3) whose planes are RLEW then Carmack compressed (near and far copies, literal 0xA7xx / # 0xA8xx words, RLEW runs and a literal tag value). The references are the source pixels / tiles: CRC-32 of the RGBA # (6-bit values scaled as (v << 2) | (v >> 4), sprite holes 0) and of the tiles as u16 LE. # tests/gen/wolf3d.luau { palette, vswap = { data, walls = { crc }, sprites = { crc }, sounds = { { bytes, crc } } }, # gamemaps, maphead, maps = { { slot, name, width, height, planes = { crc } } } } import struct, zlib TAG = 0xABCD def rgba(pal, idx, holes=None): out = bytearray() for k, i in enumerate(idx): if holes is not None and holes[k]: out += b"\0\0\0\0" else: r, g, b = (pal[i * 3 + c] for c in range(3)) out += bytes([(r << 2) | (r >> 4), (g << 2) | (g >> 4), (b << 2) | (b >> 4), 255]) return zlib.crc32(bytes(out)) def sprite(rng): # columns left..right, each with 1-2 posts; pixel data first, then the column post lists left, right = rng.randint(0, 10), rng.randint(40, 63) img = [None] * 4096 # row-major y * 64 + x: palette index, None = hole pix = bytearray() cols = [] hdr = 4 + (right - left + 1) * 2 for x in range(left, right + 1): posts = [] y = rng.randint(0, 8) for _ in range(rng.randint(1, 2)): y0 = y y1 = min(64, y0 + rng.randint(4, 30)) if y0 >= y1: break base = hdr + len(pix) for yy in range(y0, y1): v = rng.randrange(256) img[yy * 64 + x] = v pix.append(v) posts.append((y1 * 2, base - y0, y0 * 2)) y = y1 + rng.randint(2, 10) if y >= 60: break cols.append(posts) body = bytearray(pix) ofs = [] for posts in cols: ofs.append(hdr + len(body)) for e, s, st in posts: body += struct.pack(" 3 or words[i] == TAG: out += [TAG, j - i, words[i]] else: out += words[i:j] i = j return out def carmack(words): out = bytearray() pos = {} i = 0 while i < len(words): best, bo = 0, 0 for cand in reversed(pos.get((words[i], words[i + 1]) if i + 1 < len(words) else None, [])[-32:]): k = 0 while i + k < len(words) and words[cand + k] == words[i + k] and k < 255 and cand + k < i: k += 1 if k > best: best, bo = k, cand if best >= 2: if i - bo <= 255: out += struct.pack("> 8 in (0xA7, 0xA8): out += struct.pack("