codecs/model/DoomMap: the Doom map-to-Scene builder moved out of archive/wad, plus a UDMF 1.1 TEXTMAP parser (fields kept, namespace flag bits); Wad.map loads UDMF maps; model/udmf for a standalone TEXTMAP; codecs/text/Lexer (C-style tokens for id Tech / UDMF text)
STYLE.md: layout block and the 2a table list DoomMap and Lexer. tests/archive/wad: the UDMF stub map now loads (empty) instead of UNSUPPORTED.
This commit is contained in:
1 parent
01c044805f
commit
7d4e0381fe
20 files changed
+3857
-1979
No files matched your search
@@ -0,0 +1,21 @@
|
||||
# Docs inputs for the id Tech sections of the scene / tilemap / archive pages (tools/fixtures.py; tools/docs_check.py
|
||||
# explains the inputs), made by the format fixtures' writers: the hand-written UDMF room (udmf.py).
|
||||
# tests/gen/docs_idtech.luau { files = { [name] = bytes }, vars = { udmfText = "room.udmf", ... } }
|
||||
import importlib.util, os
|
||||
|
||||
INPUTS = ["tools/docs_check.py"]
|
||||
|
||||
|
||||
def mod(ctx, name):
|
||||
spec = importlib.util.spec_from_file_location("fx_" + name, os.path.join(ctx.root, "tools", name + ".py") if name == "docs_check"
|
||||
else 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):
|
||||
check = mod(ctx, "docs_check")
|
||||
files = {"room.udmf": mod(ctx, "udmf").ROOM.encode()}
|
||||
vars = {"udmfText": "room.udmf"}
|
||||
check.emit_inputs(ctx, files, vars)
|
||||
@@ -0,0 +1,112 @@
|
||||
# UDMF fixtures (tools/fixtures.py). Freedoom has no UDMF maps, so Freedoom MAP01 (BSD, licenses/freedoom-COPYING.txt;
|
||||
# the nix freedoom package, cut down as in wad.py) is converted here to a "Doom"-namespace TEXTMAP by the UDMF 1.1
|
||||
# conversion rules (tag -> id and arg0, flag bits -> booleans). The test checks that the TEXTMAP map gives the same
|
||||
# tables and the same Scene geometry as the binary lumps. Plus a hand-written ZDoom-namespace room (comments, octal /
|
||||
# hex, escapes, user_ and unknown keys, an unknown block) with exact areas.
|
||||
# tests/gen/udmf.luau { binary = <IWAD>, textmap = <PWAD with MAP01 as UDMF>, text = <the TEXTMAP>, room = <text> }
|
||||
import importlib.util, os, struct
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def wadgen():
|
||||
spec = importlib.util.spec_from_file_location("_wadfx", os.path.join(HERE, "wad.py"))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
return m
|
||||
|
||||
|
||||
def q(s):
|
||||
return '"' + s.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
||||
|
||||
|
||||
def to_udmf(d):
|
||||
out = ['namespace = "Doom";', ""]
|
||||
nm = lambda b: b.split(b"\0")[0].decode("latin1")
|
||||
for i in range(0, len(d["THINGS"]), 10):
|
||||
x, y, a, t, f = struct.unpack_from("<hhHHH", d["THINGS"], i)
|
||||
kv = ["x = %d.0;" % x, "y = %d.0;" % y, "angle = %d;" % a, "type = %d;" % t]
|
||||
for k, on in [("skill1", f & 1), ("skill2", f & 1), ("skill3", f & 2), ("skill4", f & 4), ("skill5", f & 4),
|
||||
("ambush", f & 8), ("single", not f & 16), ("dm", not f & 32), ("coop", not f & 64), ("friend", f & 128)]:
|
||||
if on:
|
||||
kv.append("%s = true;" % k)
|
||||
out.append("thing // %d\n{\n%s\n}\n" % (i // 10, "\n".join(kv)))
|
||||
for i in range(0, len(d["VERTEXES"]), 4):
|
||||
x, y = struct.unpack_from("<hh", d["VERTEXES"], i)
|
||||
out.append("vertex { x = %d.000; y = %d.000; }" % (x, y))
|
||||
bits = ["blocking", "blockmonsters", "twosided", "dontpegtop", "dontpegbottom", "secret", "blocksound", "dontdraw", "mapped"]
|
||||
for i in range(0, len(d["LINEDEFS"]), 14):
|
||||
v1, v2, f, sp, tag, fr, bk = struct.unpack_from("<HHHHHHH", d["LINEDEFS"], i)
|
||||
kv = ["id = %d;" % tag, "v1 = %d;" % v1, "v2 = %d;" % v2, "sidefront = %d;" % fr]
|
||||
if bk != 0xFFFF:
|
||||
kv.append("sideback = %d;" % bk)
|
||||
if sp:
|
||||
kv += ["special = %d;" % sp, "arg0 = %d;" % tag]
|
||||
kv += ["%s = true;" % b for k, b in enumerate(bits) if f & (1 << k)]
|
||||
out.append("linedef\n{\n%s\n}\n" % "\n".join(kv))
|
||||
for i in range(0, len(d["SIDEDEFS"]), 30):
|
||||
xo, yo, up, lo, mid, sec = struct.unpack_from("<hh8s8s8sH", d["SIDEDEFS"], i)
|
||||
kv = ["sector = %d;" % sec]
|
||||
if xo:
|
||||
kv.append("offsetx = %d;" % xo)
|
||||
if yo:
|
||||
kv.append("offsety = %d;" % yo)
|
||||
for k, v in [("texturetop", up), ("texturebottom", lo), ("texturemiddle", mid)]:
|
||||
if nm(v) != "-":
|
||||
kv.append("%s = %s;" % (k, q(nm(v))))
|
||||
out.append("sidedef\n{\n%s\n}\n" % "\n".join(kv))
|
||||
for i in range(0, len(d["SECTORS"]), 26):
|
||||
fl, ce, ff, cf, li, sp, tag = struct.unpack_from("<hh8s8sHHH", d["SECTORS"], i)
|
||||
kv = ["heightfloor = %d;" % fl, "heightceiling = %d;" % ce, "texturefloor = %s;" % q(nm(ff)),
|
||||
"textureceiling = %s;" % q(nm(cf)), "lightlevel = %d;" % li]
|
||||
if sp:
|
||||
kv.append("special = %d;" % sp)
|
||||
if tag:
|
||||
kv.append("id = %d;" % tag)
|
||||
out.append("sector\n{\n%s\n}\n" % "\n".join(kv))
|
||||
return "\n".join(out) + "\n"
|
||||
|
||||
|
||||
ROOM = r'''// a 256 x 256 room (sector 0) with a 64 x 64 pillar sector (1), pillar floor 32
|
||||
/* written by hand
|
||||
for the rosetta tests */
|
||||
NameSpace = "ZDoom";
|
||||
user_note = "a \"quoted\" \\ note";
|
||||
vertex { x = 0; y = 0.0; } // 0
|
||||
vertex { x = 0x100; y = 0; } // 1: hex
|
||||
vertex { x = 256.0; y = 256e0; } // 2
|
||||
vertex { x = 0; y = 0400; } // 3: octal 256
|
||||
vertex { x = 96; y = 96; } vertex { x = 160; y = 96; } vertex { x = 160; y = 160; } vertex { x = 96; y = 160; }
|
||||
sidedef { sector = 0; texturemiddle = "Wall"; }
|
||||
sidedef { sector = 0; texturemiddle = "WALL"; }
|
||||
sidedef { sector = 0; texturemiddle = "WALL"; }
|
||||
sidedef { sector = 0; texturemiddle = "WALL"; }
|
||||
sidedef { sector = 0; texturebottom = "STEP"; offsetx_bottom = 4.0; } sidedef { sector = 0; texturebottom = "STEP"; }
|
||||
sidedef { sector = 0; texturebottom = "STEP"; } sidedef { sector = 0; texturebottom = "STEP"; }
|
||||
sidedef { sector = 1; } sidedef { sector = 1; } sidedef { sector = 1; } sidedef { sector = 1; }
|
||||
linedef { v1 = 0; v2 = 3; sidefront = 0; blocking = true; }
|
||||
linedef { v1 = 3; v2 = 2; sidefront = 1; Blocking = TRUE; }
|
||||
linedef { v1 = 2; v2 = 1; sidefront = 2; blocking = true; }
|
||||
linedef { v1 = 1; v2 = 0; sidefront = 3; blocking = true; id = 7; special = 80; arg0 = 3; playeruse = true; repeatspecial = true; }
|
||||
linedef { v1 = 4; v2 = 5; sidefront = 4; sideback = 8; twosided = true; }
|
||||
linedef { v1 = 5; v2 = 6; sidefront = 5; sideback = 9; twosided = true; }
|
||||
linedef { v1 = 6; v2 = 7; sidefront = 6; sideback = 10; twosided = true; }
|
||||
linedef { v1 = 7; v2 = 4; sidefront = 7; sideback = 11; twosided = true; }
|
||||
sector { heightfloor = 0; heightceiling = 128; texturefloor = "FLOOR"; textureceiling = "CEIL"; user_gravity = 0.5; }
|
||||
sector { heightfloor = 32; heightceiling = 128; texturefloor = "FLOOR"; textureceiling = "CEIL"; lightlevel = 200; id = 3; }
|
||||
thing { x = 32; y = 32; angle = 90; type = 1; skill1 = true; single = true; }
|
||||
thing { x = 128.5; y = 128; height = 8; type = 2014; id = 5; special = 80; arg0 = 1; dormant = true; }
|
||||
vavoombox { foo = 1; } // unknown block, kept
|
||||
'''
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
W = wadgen()
|
||||
root = ctx.nix("freedoom", ["sh", "-c", "dirname $(dirname $(readlink -f $(command -v freedoom2)))"]).decode().strip()
|
||||
full = open(os.path.join(root, W.FREEDOOM), "rb").read()
|
||||
sel, rng = W.cut(full)
|
||||
sel += rng("P_START", "P_END", 40) + rng("F_START", "F_END", 40)
|
||||
binary = W.write(b"IWAD", sel)
|
||||
text = to_udmf(dict(sel[1:11]))
|
||||
textmap = W.write(b"PWAD", [("MAP01", b""), ("TEXTMAP", text.encode()), ("ENDMAP", b"")] + sel[11:])
|
||||
ctx.emit("udmf", {"binary": binary, "textmap": textmap, "text": text, "room": ROOM})
|
||||
Reference in new issue
Block a user