merge ws/idtech: UDMF (codecs/model/DoomMap), Doom 3 / Quake 4 .map + .proc, Wolf3D VSWAP + GAMEMAPS, codecs/text/Lexer

This commit is contained in:
4DBug committed 2026-11-01 19:48:30 -06:00
commit 0e0b213a80
38 files changed
+11791 -2566

No files matched your search

+61 -1
View File
@@ -770,6 +770,18 @@ local list: { Entry } = {
return require("@rosetta/model/buildmap")
end,
},
{
name = "d3map",
category = "model",
path = "model/d3map",
extensions = { "map" },
mime = { "text/x-doom3-map" },
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/Brush", "codecs/model/Patch", "codecs/model/Mat4", "codecs/text/Lexer" },
caps = { decode = true, encode = false, patches = true, variants = { "doom3", "quake4" } },
load = function()
return require("@rosetta/model/d3map")
end,
},
{
name = "dae",
category = "model",
@@ -974,6 +986,18 @@ local list: { Entry } = {
return require("@rosetta/model/pmx")
end,
},
{
name = "proc",
category = "model",
path = "model/proc",
extensions = { "proc" },
mime = { "model/x-doom3-proc" },
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Lexer" },
caps = { decode = true, encode = false, portals = true },
load = function()
return require("@rosetta/model/proc")
end,
},
{
name = "qb",
category = "model",
@@ -1070,6 +1094,18 @@ local list: { Entry } = {
return require("@rosetta/model/stl")
end,
},
{
name = "udmf",
category = "model",
path = "model/udmf",
extensions = { "udmf", "textmap" },
mime = { "text/x-udmf" },
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/DoomMap" },
caps = { decode = true, encode = false, maps = true },
load = function()
return require("@rosetta/model/udmf")
end,
},
{
name = "usda",
category = "model",
@@ -1586,13 +1622,25 @@ local list: { Entry } = {
return require("@rosetta/archive/vpk")
end,
},
{
name = "vswap",
category = "archive",
path = "archive/vswap",
extensions = { "wl6", "wl1", "sod", "sdm", "vswap" },
mime = { "application/x-wolf3d-vswap" },
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels" },
caps = { decode = true, encode = false, images = true, sounds = true },
load = function()
return require("@rosetta/archive/vswap")
end,
},
{
name = "wad",
category = "archive",
path = "archive/wad",
extensions = { "wad" },
mime = { "application/x-doom" },
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/Polygon" },
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/DoomMap" },
caps = { decode = true, encode = true, images = true, maps = true, variants = { "iwad", "pwad" } },
load = function()
return require("@rosetta/archive/wad")
@@ -1814,6 +1862,18 @@ local list: { Entry } = {
return require("@rosetta/data/yaml")
end,
},
{
name = "gamemaps",
category = "vector",
path = "vector/gamemaps",
extensions = { "wl6", "wl1", "sod", "sdm" },
mime = { "application/x-wolf3d-gamemaps" },
deps = { "core/Err", "core/Bytes", "core/Input", "Types" },
caps = { decode = true, encode = false, tilemap = true },
load = function()
return require("@rosetta/vector/gamemaps")
end,
},
{
name = "svg",
category = "vector",
+268
View File
@@ -0,0 +1,268 @@
--!strict
-- archive/vswap: Wolfenstein 3D / Spear of Destiny page files (VSWAP.WL1 / .WL6 / .SOD / .SDM: u16 chunks, sprite
-- start, sound start; u32 offsets, u16 lengths; ModdingWiki "VSWAP Format", no code taken), read only. Pages load as
-- entries walls/NNN, sprites/NNN, sounds/NNN and soundinfo; Vswap.image turns walls (64 x 64 column-major) and
-- sprites (t_compshape posts) into Images through a palette passed in (the game's palette is not redistributable),
-- Vswap.sound the digitized sounds into Audio (u8 PCM, 7042 Hz). Not supported: writing, Blake Stone / Corridor 7.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Types = require("@rosetta/Types")
local Archive = require("@rosetta/containers/Archive")
local Pixels = require("@rosetta/codecs/image/Pixels")
-- ------------------------------------------------------------------------------------------------ contract
local Vswap = {
name = "vswap",
category = "archive",
extensions = { "wl6", "wl1", "sod", "sdm", "vswap" },
mime = { "application/x-wolf3d-vswap" },
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels" },
caps = { decode = true, encode = false, images = true, sounds = true },
}
-- ------------------------------------------------------------------------------------------------ types
export type DecodeOptions = { maxChunks: number? } -- default 65535
export type ImageOptions = {
palette: (buffer | string)?, -- 768 bytes RGB (6-bit VGA values are scaled up when no byte is above 63); default grey
sixBit: boolean?, -- force the 6-bit reading of the palette
}
export type Page = { kind: "wall" | "sprite" | "sound" | "soundinfo", index: number, offset: number, size: number }
-- ------------------------------------------------------------------------------------------------ constants
local readu8, readu16, readi16, writeu32 = buffer.readu8, buffer.readu16, buffer.readi16, buffer.writeu32
local SAMPLE_RATE = 7042 -- the digitized sounds' rate (wolf4sdl ORIGSAMPLERATE)
-- ------------------------------------------------------------------------------------------------ sniff
local function header(r: Bytes.Reader): (number?, number, number)
if r:remaining() < 6 then
return nil, 0, 0
end
local n, ss, so = readu16(r.buf, r.base), readu16(r.buf, r.base + 2), readu16(r.buf, r.base + 4)
if n == 0 or ss > so or so > n or 6 + n * 6 > r:remaining() then
return nil, 0, 0
end
return n, ss, so
end
function Vswap.sniff(r: Bytes.Reader): number
local n = header(r)
if not n then
return 0
end
local size = r.limit - r.base
local b = r.buf
local last = 6 + n * 6
local nonzero = 0
for i = 0, n - 1 do
local o = buffer.readu32(b, r.base + 6 + i * 4)
local l = readu16(b, r.base + 6 + n * 4 + i * 2)
if o ~= 0 then
if o < last or o + l > size then
return 0
end
last = o
nonzero += 1
end
end
return if nonzero > 0 then 0.6 else 0
end
-- ------------------------------------------------------------------------------------------------ decode
function Vswap.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
if r:remaining() < 6 then
return nil, Err.new(Err.TRUNCATED, "header", 0)
end
local n, ss, so = header(r)
if not n then
return nil, Err.new(if 6 + readu16(r.buf, r.base) * 6 > r:remaining() then Err.TRUNCATED else Err.CORRUPT, "bad page directory", 0)
end
if n > (opts and opts.maxChunks or 65535) then
return nil, Err.new(Err.LIMIT, "too many pages: " .. n)
end
local size = r.limit - r.base
local b = r.buf
local a = Archive.new("vswap")
local pages: { Page } = {}
local counts: { [string]: number } = { wall = 0, sprite = 0, sound = 0 }
for i = 0, n - 1 do
local o = buffer.readu32(b, r.base + 6 + i * 4)
local l = readu16(b, r.base + 6 + n * 4 + i * 2)
if o == 0 then
l = 0 -- a sparse page (Spear of Destiny)
elseif o + l > size then
return nil, Err.new(Err.TRUNCATED, "page " .. i .. " past the end", 6 + i * 4)
end
local kind: string, idx: number = "sound", i - so
if i < ss then
kind, idx = "wall", i
elseif i < so then
kind, idx = "sprite", i - ss
elseif i == n - 1 and so < n then
kind, idx = "soundinfo", 0
end
local name = if kind == "soundinfo" then "soundinfo" else kind .. "s/" .. string.format("%03d", idx)
if kind ~= "soundinfo" then
counts[kind] += 1
end
table.insert(pages, { kind = kind :: any, index = idx, offset = o, size = l })
Archive.put(a, { name = name, size = l, dir = false, method = "store", page = i, kind = kind, load = Archive.slice(b, r.base + o, l) })
end
a.meta.source = { format = "vswap", chunks = n, spriteStart = ss, soundStart = so, walls = counts.wall, sprites = counts.sprite, soundPages = counts.sound }
a.meta.vswap = { pages = pages, buf = b, base = r.base, spriteStart = ss, soundStart = so }
return a, nil
end
-- ------------------------------------------------------------------------------------------------ extras
local function info(a: any): any
return type(a) == "table" and type(a.meta) == "table" and a.meta.vswap or nil
end
local function palette(opts: ImageOptions?): (buffer, boolean)
local p = opts and opts.palette
if p == nil then
local g = buffer.create(768)
for i = 0, 255 do
buffer.fill(g, i * 3, i, 3)
end
return Pixels.palette(g, 0, 256), false
end
local src = if type(p) == "string" then buffer.fromstring(p) else p
local n = math.min(buffer.len(src), 768)
local six = opts and opts.sixBit
if six == nil then
six = true
for i = 0, n - 1 do
if readu8(src, i) > 63 then
six = false
break
end
end
end
if six then
local s = buffer.create(768)
for i = 0, n - 1 do
local v = bit32.band(readu8(src, i), 63)
buffer.writeu8(s, i, bit32.bor(bit32.lshift(v, 2), bit32.rshift(v, 4)))
end
src = s
end
return Pixels.palette(src, 0, n // 3), true
end
function Vswap.pages(a: any): { Page }?
local v = info(a)
return v and v.pages
end
function Vswap.image(a: any, kind: "wall" | "sprite", index: number, opts: ImageOptions?): (Types.Image?, Err.Err?)
local v = info(a)
if not v then
return nil, Err.new(Err.ARG, "expected a decoded VSWAP archive")
end
local page: Page? = nil
for _, p in v.pages do
if p.kind == kind and p.index == index then
page = p
break
end
end
if not page then
return nil, Err.new(Err.ARG, "no " .. tostring(kind) .. " " .. tostring(index))
end
local pal, given = palette(opts)
local b, at, n = v.buf, v.base + page.offset, page.size
local img = Types.Image.new(64, 64)
local px = img.pixels
if kind == "wall" then
if n < 4096 then
return nil, Err.new(Err.CORRUPT, "wall page shorter than 4096 bytes", page.offset)
end
for x = 0, 63 do
for y = 0, 63 do
writeu32(px, (y * 64 + x) * 4, buffer.readu32(pal, readu8(b, at + x * 64 + y) * 4))
end
end
else
if n < 4 then
return nil, Err.new(Err.CORRUPT, "sprite page too short", page.offset)
end
local left, right = readu16(b, at), readu16(b, at + 2)
if right < left or right > 63 or 4 + (right - left + 1) * 2 > n then
return nil, Err.new(Err.CORRUPT, "bad sprite columns", page.offset)
end
for x = left, right do
local p = readu16(b, at + 4 + (x - left) * 2)
for _ = 1, 64 do
if p + 2 > n then
return nil, Err.new(Err.CORRUPT, "sprite post past the page", page.offset + p)
end
local endy = readu16(b, at + p) // 2
if endy == 0 then
break
end
if p + 6 > n then
return nil, Err.new(Err.CORRUPT, "sprite post past the page", page.offset + p)
end
local src, starty = readi16(b, at + p + 2), readu16(b, at + p + 4) // 2
if endy > 64 or starty > endy or src + starty < 0 or src + endy > n then
return nil, Err.new(Err.CORRUPT, "bad sprite post", page.offset + p)
end
for y = starty, endy - 1 do
writeu32(px, (y * 64 + x) * 4, buffer.readu32(pal, readu8(b, at + src + y) * 4))
end
p += 6
end
end
end
img.meta.source = { format = "vswap", kind = kind, index = index, palette = given }
return img, nil
end
function Vswap.sounds(a: any): number
local v = info(a)
if not v then
return 0
end
local last = v.pages[#v.pages]
return if last and last.kind == "soundinfo" then last.size // 4 else 0
end
function Vswap.sound(a: any, index: number): (Types.Audio?, Err.Err?)
local v = info(a)
if not v then
return nil, Err.new(Err.ARG, "expected a decoded VSWAP archive")
end
local si = v.pages[#v.pages]
if not si or si.kind ~= "soundinfo" or index < 1 or index > si.size // 4 or index % 1 ~= 0 then
return nil, Err.new(Err.ARG, "no sound " .. tostring(index))
end
local b = v.buf
local start = readu16(b, v.base + si.offset + (index - 1) * 4)
local len = readu16(b, v.base + si.offset + (index - 1) * 4 + 2)
local au = Types.Audio.new(SAMPLE_RATE, 1, len)
local s = au.samples
local got = 0
local p = v.soundStart + start + 1
while got < len do
local page = v.pages[p]
if not page or page.kind ~= "sound" then
return nil, Err.new(Err.CORRUPT, "sound " .. index .. " runs past the sound pages")
end
local take = math.min(page.size, len - got)
local at = v.base + page.offset
for i = 0, take - 1 do
buffer.writef32(s, (got + i) * 4, (readu8(b, at + i) - 128) / 128)
end
got += take
p += 1
if page.size == 0 then
return nil, Err.new(Err.CORRUPT, "empty sound page in sound " .. index)
end
end
au.meta.source = { format = "vswap", sound = index, startPage = start, bytes = len, encoding = "u8" }
return au, nil
end
return Vswap
+14 -10
View File
@@ -1,7 +1,7 @@
--!strict
-- archive/wad: Doom-engine WADs (IWAD / PWAD; Unofficial Doom Specs, w_wad.c / r_data.c; no code taken), plus lumps,
-- palettes, pictures, wall textures and maps. Entry names: "<map>/<lump>", repeats "<name>~<n>". Not supported: UDMF
-- geometry (lumps listed), Strife's TEXTURE variant, big-endian (Jaguar) WADs, compressed Jaguar lumps.
-- palettes, pictures, wall textures and maps (binary and UDMF TEXTMAP). Entry names: "<map>/<lump>", repeats
-- "<name>~<n>". Not supported: Strife's TEXTURE variant, big-endian (Jaguar) WADs, compressed Jaguar lumps.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
@@ -10,7 +10,7 @@ local Types = require("@rosetta/Types")
local Archive = require("@rosetta/containers/Archive")
local Pixels = require("@rosetta/codecs/image/Pixels")
local Picture = require("@rosetta/archive/wad/Picture")
local Map = require("@rosetta/archive/wad/Map")
local Map = require("@rosetta/codecs/model/DoomMap")
-- ------------------------------------------------------------------------------------------------ contract
local Wad = {
@@ -18,7 +18,7 @@ local Wad = {
category = "archive",
extensions = { "wad" },
mime = { "application/x-doom" },
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/Polygon" },
deps = { "core/Err", "core/Bytes", "Types", "containers/Archive", "codecs/image/Pixels", "codecs/model/DoomMap" },
caps = { decode = true, encode = true, images = true, maps = true, variants = { "iwad", "pwad" } },
}
@@ -38,6 +38,7 @@ export type Lump = {
export type MapOptions = {
textures: boolean?, -- default true
palette: number?, -- default 0
maxBlocks: number?, -- UDMF, default 2^22
}
-- ------------------------------------------------------------------------------------------------ constants
@@ -377,7 +378,7 @@ function Wad.maps(a: any): { string }
return out
end
function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
function Wad.mapData(a: any, name: string, opts: MapOptions?): (Map.MapData?, Err.Err?)
local w = info(a)
if not w then
return nil, Err.new(Err.ARG, "expected a decoded WAD archive")
@@ -392,10 +393,13 @@ function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
if not next(lumps) then
return nil, Err.new(Err.ARG, "no map named " .. tostring(name))
end
if lumps.TEXTMAP then
return nil, Err.new(Err.UNSUPPORTED, "UDMF (TEXTMAP) maps")
local m, msg
local tm = lumps.TEXTMAP
if tm then
m, msg = Map.udmf(buffer.readstring(tm.buf, tm.at, tm.size), opts and opts.maxBlocks)
else
m, msg = Map.parse(lumps, lumps.BEHAVIOR ~= nil)
end
local m, msg = Map.parse(lumps, lumps.BEHAVIOR ~= nil)
if not m then
return nil, Err.from(msg)
end
@@ -403,7 +407,7 @@ function Wad.mapData(a: any, name: string): (Map.MapData?, Err.Err?)
end
function Wad.map(a: any, name: string, opts: MapOptions?): (Types.Scene?, Err.Err?)
local m, err = Wad.mapData(a, name)
local m, err = Wad.mapData(a, name, opts)
if not m then
return nil, err
end
@@ -441,7 +445,7 @@ function Wad.map(a: any, name: string, opts: MapOptions?): (Types.Scene?, Err.Er
image = if images then image else nil,
}
local scene = Map.scene(m, tex, string.upper(name))
scene.meta.source = { format = "wad", map = string.upper(name), mapFormat = m.format, things = #m.things, linedefs = #m.linedefs, sectors = #m.sectors, vertices = #m.vertices // 2 }
scene.meta.source = { format = "wad", map = string.upper(name), mapFormat = m.format, namespace = m.namespace, things = #m.things, linedefs = #m.linedefs, sectors = #m.sectors, vertices = #m.vertices // 2 }
return scene, nil
end
+248
View File
@@ -0,0 +1,248 @@
--!strict
-- codecs/model/DoomMap/Udmf: UDMF 1.1 TEXTMAP text (zdoom.org specs/udmf.txt; no code taken) to the DoomMap tables.
-- Every block keeps its fields (lower-case keys, namespace and user_ keys included); unknown blocks and global
-- assignments are kept as data. Flags are rebuilt in the binary layout of the namespace (Doom or Hexen bits).
local Lexer = require("@rosetta/codecs/text/Lexer")
local Udmf = {}
export type Block = { type: string, fields: { [string]: any } }
export type Document = { namespace: string?, globals: { [string]: any }, blocks: { Block } }
-- ------------------------------------------------------------------------------------------------ parse
local function value(L: Lexer.Lexer): (any, string?)
local k, v = L:next()
if k == "number" then
local raw = L.raw :: string
-- integer := ... | 0[0-9]+ (octal) | 0x[0-9A-Fa-f]+
if string.match(raw, "^[+-]?0[0-7]+$") then
local neg = string.sub(raw, 1, 1) == "-"
local o = tonumber((string.gsub(raw, "^[+-]?0", "")), 8) :: number
return if neg then -o else o, nil
end
return v, nil
elseif k == "string" then
return v, nil
elseif k == "word" then
local w = string.lower(v)
if w == "true" then
return true, nil
elseif w == "false" then
return false, nil
end
return v, nil
end
return nil, L.err or "expected a value"
end
function Udmf.parse(text: string, maxBlocks: number?): (Document?, string?)
local L = Lexer.new(text)
local doc: Document = { namespace = nil, globals = {}, blocks = {} }
local limit = maxBlocks or 2 ^ 22
while true do
local k, id = L:next()
if k == nil then
if L.err then
return nil, L.err .. " at line " .. L:line()
end
break
end
if k ~= "word" then
return nil, "expected an identifier at line " .. L:line()
end
local name = string.lower(id)
local pk, pv = L:next()
if pk == "punct" and pv == "=" then
local v, err = value(L)
if err then
return nil, err .. " at line " .. L:line()
end
local sk, sv = L:next()
if sk ~= "punct" or sv ~= ";" then
return nil, "expected ; at line " .. L:line()
end
doc.globals[name] = v
if name == "namespace" and type(v) == "string" then
doc.namespace = v
end
elseif pk == "punct" and pv == "{" then
if #doc.blocks >= limit then
return nil, "limit: more than " .. limit .. " blocks"
end
local fields: { [string]: any } = {}
while true do
local fk, fv = L:next()
if fk == "punct" and fv == "}" then
break
end
if fk ~= "word" then
return nil, (L.err or "expected a field name") .. " at line " .. L:line()
end
local ek, ev = L:next()
if ek ~= "punct" or ev ~= "=" then
return nil, "expected = at line " .. L:line()
end
local v, err = value(L)
if err then
return nil, err .. " at line " .. L:line()
end
local sk, sv = L:next()
if sk ~= "punct" or sv ~= ";" then
return nil, "expected ; at line " .. L:line()
end
fields[string.lower(fv)] = v
end
table.insert(doc.blocks, { type = name, fields = fields })
else
return nil, "expected = or { at line " .. L:line()
end
end
return doc, nil
end
-- ------------------------------------------------------------------------------------------------ map
local LINE_FLAGS: { [string]: number } = { blocking = 1, blockmonsters = 2, twosided = 4, dontpegtop = 8, dontpegbottom = 16, secret = 32, blocksound = 64, dontdraw = 128, mapped = 256 }
-- Hexen SPAC activation (bits 10..12) and repeat (bit 9)
local SPAC: { [string]: number } = { playercross = 0, playeruse = 1, monstercross = 2, impact = 3, playerpush = 4, missilecross = 5 }
local function num(f: { [string]: any }, k: string, default: number): number
local v = f[k]
return if type(v) == "number" then v else default
end
local function flag(f: { [string]: any }, k: string): boolean
return f[k] == true
end
local function tex(f: { [string]: any }, k: string, default: string): string
local v = f[k]
return if type(v) == "string" then string.upper(v) else default
end
local function args(f: { [string]: any }): { number }
return { num(f, "arg0", 0), num(f, "arg1", 0), num(f, "arg2", 0), num(f, "arg3", 0), num(f, "arg4", 0) }
end
local function index(f: { [string]: any }, k: string): number?
local v = f[k]
return if type(v) == "number" and v >= 0 and v % 1 == 0 then v + 1 else nil
end
function Udmf.map(doc: Document): (any, string?)
local ns = string.lower(doc.namespace or "")
local hexenBits = ns ~= "doom" and ns ~= "heretic" and ns ~= "strife"
local m = { format = "udmf", namespace = doc.namespace, globals = doc.globals, things = {}, linedefs = {}, sidedefs = {}, vertices = {}, sectors = {}, blocks = {} }
for _, b in doc.blocks do
local f = b.fields
if b.type == "vertex" then
local x, y = f.x, f.y
if type(x) ~= "number" or type(y) ~= "number" then
return nil, "vertex " .. (#m.vertices // 2) .. " has no x / y"
end
table.insert(m.vertices, x)
table.insert(m.vertices, y)
elseif b.type == "linedef" then
local flags = 0
for k, bit in LINE_FLAGS do
if flag(f, k) then
flags += bit
end
end
if hexenBits then
if flag(f, "repeatspecial") then
flags += 512
end
for k, a in SPAC do
if flag(f, k) then
flags = bit32.bor(bit32.band(flags, bit32.bnot(0x1C00)), a * 1024)
end
end
end
local v1, v2 = index(f, "v1"), index(f, "v2")
if not v1 or not v2 then
return nil, "linedef " .. #m.linedefs .. " has no v1 / v2"
end
local a = args(f)
table.insert(m.linedefs, {
v1 = v1,
v2 = v2,
flags = flags,
special = num(f, "special", 0),
tag = if hexenBits then num(f, "id", -1) else a[1],
args = a,
front = index(f, "sidefront"),
back = index(f, "sideback"),
fields = f,
})
elseif b.type == "sidedef" then
local s = index(f, "sector")
if not s then
return nil, "sidedef " .. #m.sidedefs .. " has no sector"
end
table.insert(m.sidedefs, {
xoff = num(f, "offsetx", 0),
yoff = num(f, "offsety", 0),
upper = tex(f, "texturetop", "-"),
lower = tex(f, "texturebottom", "-"),
middle = tex(f, "texturemiddle", "-"),
sector = s,
fields = f,
})
elseif b.type == "sector" then
table.insert(m.sectors, {
floor = num(f, "heightfloor", 0),
ceiling = num(f, "heightceiling", 0),
floorFlat = tex(f, "texturefloor", "-"),
ceilingFlat = tex(f, "textureceiling", "-"),
light = num(f, "lightlevel", 160),
special = num(f, "special", 0),
tag = num(f, "id", 0),
fields = f,
})
elseif b.type == "thing" then
local x, y = f.x, f.y
if type(x) ~= "number" or type(y) ~= "number" then
return nil, "thing " .. #m.things .. " has no x / y"
end
local fl = 0
if flag(f, "skill1") or flag(f, "skill2") then
fl += 1
end
if flag(f, "skill3") then
fl += 2
end
if flag(f, "skill4") or flag(f, "skill5") then
fl += 4
end
if flag(f, "ambush") then
fl += 8
end
if hexenBits then
fl += (if flag(f, "dormant") then 16 else 0) + (if flag(f, "class1") then 32 else 0) + (if flag(f, "class2") then 64 else 0)
+ (if flag(f, "class3") then 128 else 0) + (if flag(f, "single") then 256 else 0) + (if flag(f, "coop") then 512 else 0)
+ (if flag(f, "dm") then 1024 else 0)
else
-- Doom / Boom / MBF: 16 not in single player, 32 not in deathmatch, 64 not in coop, 128 friend
fl += (if flag(f, "single") then 0 else 16) + (if flag(f, "dm") then 0 else 32) + (if flag(f, "coop") then 0 else 64)
+ (if flag(f, "friend") then 128 else 0)
end
table.insert(m.things, {
x = x,
y = y,
z = num(f, "height", 0),
angle = num(f, "angle", 0),
type = num(f, "type", 0),
flags = fl,
tid = num(f, "id", 0),
special = num(f, "special", 0),
args = args(f),
fields = f,
})
else
table.insert(m.blocks, b)
end
end
return m, nil
end
return Udmf
@@ -1,9 +1,10 @@
--!strict
-- archive/wad/Map: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) to tables and a Scene, with
-- vanilla texture alignment (offsets, unpegged) and the sky hack; z up, map units. From the Unofficial Doom Specs and
-- the Hexen specs; no code taken. Not supported: UDMF (TEXTMAP).
-- codecs/model/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to
-- tables and a Scene, with vanilla texture alignment (offsets, unpegged) and the sky hack; z up, map units. From the
-- Unofficial Doom Specs, the Hexen specs and UDMF 1.1; no code taken. Not supported: UDMF slopes / per-part offsets.
local Types = require("@rosetta/Types")
local Polygon = require("@rosetta/codecs/model/Polygon")
local Udmf = require("@rosetta/codecs/model/DoomMap/Udmf")
local Map = {}
@@ -12,12 +13,16 @@ local readu8, readi16, readu16 = buffer.readu8, buffer.readi16, buffer.readu16
local writef32, writeu32 = buffer.writef32, buffer.writeu32
export type Lump = { buf: buffer, at: number, size: number }
export type Thing = { x: number, y: number, z: number?, angle: number, type: number, flags: number, tid: number?, special: number?, args: { number }? }
export type Linedef = { v1: number, v2: number, flags: number, special: number, tag: number?, args: { number }?, front: number?, back: number? }
export type Sidedef = { xoff: number, yoff: number, upper: string, lower: string, middle: string, sector: number }
export type Sector = { floor: number, ceiling: number, floorFlat: string, ceilingFlat: string, light: number, special: number, tag: number }
export type Fields = { [string]: any } -- UDMF: the block's fields as written (lower-case keys)
export type Thing = { x: number, y: number, z: number?, angle: number, type: number, flags: number, tid: number?, special: number?, args: { number }?, fields: Fields? }
export type Linedef = { v1: number, v2: number, flags: number, special: number, tag: number?, args: { number }?, front: number?, back: number?, fields: Fields? }
export type Sidedef = { xoff: number, yoff: number, upper: string, lower: string, middle: string, sector: number, fields: Fields? }
export type Sector = { floor: number, ceiling: number, floorFlat: string, ceilingFlat: string, light: number, special: number, tag: number, fields: Fields? }
export type MapData = {
format: "doom" | "hexen",
format: "doom" | "hexen" | "udmf",
namespace: string?, -- UDMF
globals: Fields?, -- UDMF global assignments
blocks: { Udmf.Block }?, -- UDMF blocks other than vertex / linedef / sidedef / sector / thing
things: { Thing },
linedefs: { Linedef },
sidedefs: { Sidedef },
@@ -136,6 +141,16 @@ function Map.parse(lumps: { [string]: Lump }, hexen: boolean): (MapData?, string
return m, nil
end
function Map.udmf(text: string, maxBlocks: number?): (MapData?, string?)
local doc, err = Udmf.parse(text, maxBlocks)
if not doc then
return nil, err
end
return Udmf.map(doc)
end
Map.parseUdmf = Udmf.parse
-- ------------------------------------------------------------------------------------------------ sector outlines
-- sector loops: front sides v1 -> v2, back sides v2 -> v1, lines with the sector on both sides left out; the sharpest
-- right turn at forks; unclosed chains dropped
+130
View File
@@ -0,0 +1,130 @@
--!strict
-- codecs/text/Lexer: C-style tokens for id Tech / UDMF text (idLib idLexer conventions, UDMF 1.1 §I; no code taken):
-- // and /* */ comments, "strings" with backslash escapes, numbers (decimal, float, 0x hex), bare words, and single
-- punctuation characters { } ( ) [ ] ; = ,.
local Lexer = {}
export type Kind = "word" | "number" | "string" | "punct"
export type Lexer = {
s: string,
p: number, -- next byte to read, 1-based
n: number,
raw: string?, -- the last token's text as written
err: string?,
next: (self: Lexer) -> (Kind?, any),
peek: (self: Lexer) -> (Kind?, any),
line: (self: Lexer, at: number?) -> number,
}
local find, sub, byte, match = string.find, string.sub, string.byte, string.match
local ESC: { [string]: string } = { n = "\n", t = "\t", r = "\r", ["0"] = "\0" }
local function skip(L: Lexer): number?
local s, p = L.s, L.p
while true do
p = find(s, "[^ \t\r\n\f\v]", p)
if not p then
return nil
end
if byte(s, p) == 47 then
local c2 = byte(s, p + 1)
if c2 == 47 then
local e = find(s, "\n", p + 2, true)
if not e then
return nil
end
p = e + 1
elseif c2 == 42 then
local _, e = find(s, "*/", p + 2, true)
if not e then
L.err = "unterminated comment"
return nil
end
p = e + 1
else
return p
end
else
return p
end
end
end
local function token(L: Lexer): (Kind?, any, number)
local p = skip(L)
if not p then
return nil, nil, L.n + 1
end
local s = L.s
local c = byte(s, p)
if c == 34 then
local parts: { string }? = nil
local q = p + 1
while true do
local e = find(s, "[\"\\]", q)
if not e then
L.err = "unterminated string"
return nil, nil, L.n + 1
end
if byte(s, e) == 34 then
local tail = sub(s, q, e - 1)
if parts then
table.insert(parts, tail)
L.raw = sub(s, p, e)
return "string", table.concat(parts), e + 1
end
L.raw = sub(s, p, e)
return "string", tail, e + 1
end
parts = parts or {}
local ch = sub(s, e + 1, e + 1)
table.insert(parts :: { string }, sub(s, q, e - 1))
table.insert(parts :: { string }, ESC[ch] or ch)
q = e + 2
end
end
if find("{}()[];=,", string.char(c), 1, true) then
L.raw = string.char(c)
return "punct", L.raw, p + 1
end
local w = match(s, "^[^ \t\r\n\f\v{}()%[%];=,\"]+", p) :: string
local e = p + #w
-- a comment right after a word ends it
local cm = find(w, "/[/*]")
if cm then
w = sub(w, 1, cm - 1)
e = p + #w
end
L.raw = w
if (c >= 48 and c <= 57) or c == 45 or c == 43 or c == 46 then
local v = tonumber(w)
if v and not find(w, "[iInN]") then
return "number", v, e
end
end
return "word", w, e
end
local function nextToken(L: Lexer): (Kind?, any)
local k, v, e = token(L)
L.p = e
return k, v
end
local function peek(L: Lexer): (Kind?, any)
local raw = L.raw
local k, v = token(L)
L.raw = raw
return k, v
end
local function line(L: Lexer, at: number?): number
local _, n = string.gsub(sub(L.s, 1, (at or L.p) - 1), "\n", "")
return n + 1
end
function Lexer.new(s: string): Lexer
return { s = s, p = 1, n = #s, raw = nil, err = nil, next = nextToken, peek = peek, line = line }
end
return Lexer
+196
View File
@@ -0,0 +1,196 @@
--!strict
-- model/d3map/Parse: Doom 3 / Quake 4 editor .map text ("Version 2" / "Version 3"; idMapFile / idMapEntity /
-- idMapBrush / idMapPatch layouts of the Doom 3 GPL source docs, no code taken) to entities with brushDef3 sides
-- (plane a b c d with a x + b y + c z + d = 0, normal out of the brush; 2 x 3 texture matrix) and patchDef2 / 3.
local Lexer = require("@rosetta/codecs/text/Lexer")
local Parse = {}
export type Side = { plane: { number }, matrix: { { number } }, material: string, flags: { number } }
export type Prim = {
type: string, -- "brushDef3" | "patchDef2" | "patchDef3"
sides: { Side }?,
material: string?,
info: { number }?, -- patchDef2: width height 0 0 0; patchDef3: width height subdivX subdivY 0 0 0
width: number?,
height: number?,
points: { number }?, -- x y z s t per control point, in file order (column by column)
}
export type Entity = { keys: { [string]: string }, prims: { Prim }, skipped: number }
export type Map = { version: number, entities: { Entity } }
type P = { L: Lexer.Lexer, err: string? }
local function fail(p: P, msg: string)
if not p.err then
p.err = (p.L.err or msg) .. " at line " .. p.L:line()
end
end
local function want(p: P, c: string)
local k, v = p.L:next()
if k ~= "punct" or v ~= c then
fail(p, "expected " .. c)
end
end
local function number(p: P): number
local k, v = p.L:next()
if k ~= "number" then
fail(p, "expected a number")
return 0
end
return v
end
local function tuple(p: P, n: number): { number }
want(p, "(")
local out = table.create(n, 0)
for i = 1, n do
out[i] = number(p)
end
want(p, ")")
return out
end
local function name(p: P): string
local k, v = p.L:next()
if k == "string" or k == "word" then
return v
end
fail(p, "expected a material name")
return ""
end
local function brushDef3(p: P): Prim
want(p, "{")
local sides: { Side } = {}
while not p.err do
local k, v = p.L:peek()
if k == "punct" and v == "}" then
p.L:next()
break
end
local plane = tuple(p, 4)
want(p, "(")
local m1 = tuple(p, 3)
local m2 = tuple(p, 3)
want(p, ")")
local material = name(p)
local flags: { number } = {}
while not p.err do
local fk = p.L:peek()
if fk ~= "number" then
break
end
table.insert(flags, number(p))
end
table.insert(sides, { plane = plane, matrix = { m1, m2 }, material = material, flags = flags })
end
return { type = "brushDef3", sides = sides }
end
local function patchDef(p: P, kind: string, maxPoints: number): Prim
want(p, "{")
local material = name(p)
local info = tuple(p, if kind == "patchDef3" then 7 else 5)
local w, h = info[1], info[2]
if p.err then
return { type = kind }
end
if w < 1 or h < 1 or w % 1 ~= 0 or h % 1 ~= 0 or w * h > maxPoints then
fail(p, "limit: patch size " .. w .. " x " .. h)
return { type = kind }
end
local pts: { number } = table.create(w * h * 5, 0)
want(p, "(")
for i = 0, w - 1 do
want(p, "(")
for j = 0, h - 1 do
local v = tuple(p, 5)
if p.err then
return { type = kind }
end
table.move(v, 1, 5, (i * h + j) * 5 + 1, pts)
end
want(p, ")")
end
want(p, ")")
want(p, "}")
return { type = kind, material = material, info = info, width = w, height = h, points = pts }
end
function Parse.parse(text: string, maxPrims: number?): (Map?, string?)
local p: P = { L = Lexer.new(text), err = nil }
local k, v = p.L:next()
if k ~= "word" or v ~= "Version" then
return nil, "missing the Version line"
end
local version = number(p)
local m: Map = { version = version, entities = {} }
local limit = maxPrims or 2 ^ 20
local count = 0
while not p.err do
local ek, ev = p.L:next()
if not ek then
if p.L.err then
fail(p, p.L.err)
end
break
end
if ek ~= "punct" or ev ~= "{" then
fail(p, "expected an entity")
break
end
local ent: Entity = { keys = {}, prims = {}, skipped = 0 }
while not p.err do
local tk, tv = p.L:next()
if tk == "string" then
local vk, vv = p.L:next()
if vk ~= "string" then
fail(p, "expected a key value")
break
end
ent.keys[tv] = vv
elseif tk == "punct" and tv == "{" then
count += 1
if count > limit then
p.err = "limit: more than " .. limit .. " primitives"
break
end
local pk, pv = p.L:peek()
if pk == "word" and (pv == "brushDef3" or pv == "patchDef2" or pv == "patchDef3") then
p.L:next()
local prim = if pv == "brushDef3" then brushDef3(p) else patchDef(p, pv, 2 ^ 16)
want(p, "}")
table.insert(ent.prims, prim)
else
-- brushDef (Quake III brush primitives) and Version 1 brushes are not read
ent.skipped += 1
local depth = 1
while not p.err and depth > 0 do
local sk, sv = p.L:next()
if not sk then
fail(p, "unterminated primitive")
elseif sk == "punct" and sv == "{" then
depth += 1
elseif sk == "punct" and sv == "}" then
depth -= 1
end
end
end
elseif tk == "punct" and tv == "}" then
break
else
fail(p, if tk then "unexpected " .. tostring(tv) else "unterminated entity")
end
end
table.insert(m.entities, ent)
end
if p.err then
return nil, p.err
end
return m, nil
end
return Parse
+280
View File
@@ -0,0 +1,280 @@
--!strict
-- model/d3map: Doom 3 / Quake 4 / Prey editor .map ("Version 2" / "Version 3"), read only. brushDef3 sides (plane
-- equations, Doom 3 texture matrices on the ComputeAxisBase axes) become polygons through codecs/model/Brush,
-- patchDef2 / patchDef3 surfaces grids through codecs/model/Patch (patchDef3: its explicit subdivisions); a mesh per
-- entity with geometry, entities as nodes (keys in extras; origin / rotation / angle on point entities), materials as
-- URIs. From the Doom 3 GPL source docs (MapFile.cpp layout; no code taken). Not supported: writing, brushDef (Quake
-- III brush primitives) and Version 1 brushes (counted in meta.skipped), compiling (see model/proc for dmap output).
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Sniff = require("@rosetta/core/Sniff")
local Types = require("@rosetta/Types")
local Brush = require("@rosetta/codecs/model/Brush")
local Patch = require("@rosetta/codecs/model/Patch")
local Mat4 = require("@rosetta/codecs/model/Mat4")
local Parse = require("@rosetta/model/d3map/Parse")
-- ------------------------------------------------------------------------------------------------ contract
local D3map = {
name = "d3map",
category = "model",
extensions = { "map" },
mime = { "text/x-doom3-map" },
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/Brush", "codecs/model/Patch", "codecs/model/Mat4", "codecs/text/Lexer" },
caps = { decode = true, encode = false, patches = true, variants = { "doom3", "quake4" } },
}
-- ------------------------------------------------------------------------------------------------ types
export type DecodeOptions = {
hull: boolean?, -- drop faces inside / touching other brushes of the same entity, default false
merge: boolean?, -- merge coplanar faces with the same material and projection, default false
epsilon: number?, -- default 1e-3
patchLevel: number?, -- patchDef2 segments per sub-patch, default 4
skip: { string }?, -- material names left out of the meshes ("textures/common/caulk", ...)
maxPrimitives: number?, -- brushes + patches, default 2^20
maxPolygons: number?, -- default 2^20
}
-- ------------------------------------------------------------------------------------------------ constants
local Scene = Types.Scene
local writef32, writeu32 = buffer.writef32, buffer.writeu32
-- ------------------------------------------------------------------------------------------------ sniff
function D3map.sniff(r: Bytes.Reader): number
local head = Sniff.text(r, 512, true)
for _ = 1, 16 do
local rest = string.match(head, "^//[^\n]*\n%s*(.*)$")
if not rest then
break
end
head = rest
end
return if string.match(head, "^Version%s+[123]%s") then 1 else 0
end
-- ------------------------------------------------------------------------------------------------ decode
type Grid = { pos: { number }, nrm: { number }, uv: { number }, idx: { number } }
local function side(s: Parse.Side): Brush.Face?
local a, b, c, d = s.plane[1], s.plane[2], s.plane[3], s.plane[4]
local l = math.sqrt(a * a + b * b + c * c)
if l < 1e-9 then
return nil
end
-- a x + b y + c z + d = 0 with the normal outward: inside is n . p <= -d
return { plane = { a / l, b / l, c / l, -d / l }, texture = s.material, bp = s.matrix, flags = s.flags }
end
local function addPatch(prim: Parse.Prim, level: number, g: Grid): boolean
local w, h = prim.width :: number, prim.height :: number
local src = prim.points :: { number }
if not Patch.valid(w, h, #src // 5) then
return false
end
-- the file lists the grid column by column; Patch wants rows (point (i, j) at j * w + i)
local rows = table.create(w * h * 5, 0) :: { number }
for col = 0, w - 1 do
for row = 0, h - 1 do
table.move(src, (col * h + row) * 5 + 1, (col * h + row) * 5 + 5, (row * w + col) * 5 + 1, rows)
end
end
local info = prim.info :: { number }
local explicit = prim.type == "patchDef3"
local su: number = if explicit then math.max(1, info[3] or 1) else level
local sv: number = if explicit then math.max(1, info[4] or 1) else level
local pts, gw, gh = Patch.grid(rows, w, h, 5, su, sv)
if not pts then
return false
end
local normals = Patch.normals(pts, 5, gw, gh)
local first = #g.pos // 3
local P, N, U = g.pos, g.nrm, g.uv
for v = 0, gw * gh - 1 do
P[#P + 1], P[#P + 2], P[#P + 3] = pts[v * 5 + 1], pts[v * 5 + 2], pts[v * 5 + 3]
U[#U + 1], U[#U + 2] = pts[v * 5 + 4], pts[v * 5 + 5]
N[#N + 1], N[#N + 2], N[#N + 3] = normals[v * 3 + 1], normals[v * 3 + 2], normals[v * 3 + 3]
end
local I = g.idx
for _, t in Patch.triangles(gw, gh) do
I[#I + 1] = first + t
end
return true
end
local function gridPrimitive(g: Grid): Types.Primitive
local n, ni = #g.pos // 3, #g.idx
local bp, bn, bu, bi = buffer.create(n * 12), buffer.create(n * 12), buffer.create(n * 8), buffer.create(ni * 4)
for i = 0, n - 1 do
for c = 0, 2 do
writef32(bp, i * 12 + c * 4, g.pos[i * 3 + c + 1])
writef32(bn, i * 12 + c * 4, g.nrm[i * 3 + c + 1])
end
writef32(bu, i * 8, g.uv[i * 2 + 1])
writef32(bu, i * 8 + 4, g.uv[i * 2 + 2])
end
for i = 0, ni - 1 do
writeu32(bi, i * 4, g.idx[i + 1])
end
local attributes = { POSITION = Scene.accessor(bp, "f32", 3, n), NORMAL = Scene.accessor(bn, "f32", 3, n), TEXCOORD_0 = Scene.accessor(bu, "f32", 2, n) }
return { attributes = attributes, indices = Scene.accessor(bi, "u32", 1, ni), mode = "triangles" :: any }
end
local function numbers(s: string?, n: number): { number }?
if type(s) ~= "string" then
return nil
end
local out = {}
for w in string.gmatch(s, "%S+") do
local v = tonumber(w)
if not v then
return nil
end
table.insert(out, v)
end
return if #out == n then out else nil
end
-- "rotation": the 3 x 3 axis matrix by rows (row k = local axis k in the world); "angle": yaw in degrees
local function orientation(keys: { [string]: string }): { number }?
local m = numbers(keys.rotation, 9)
if m then
return Mat4.quat({ m[1], m[2], m[3], 0, m[4], m[5], m[6], 0, m[7], m[8], m[9], 0, 0, 0, 0, 1 })
end
local a = tonumber(keys.angle)
if a then
local h = math.rad(a) / 2
return { 0, 0, math.sin(h), math.cos(h) }
end
return nil
end
function D3map.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
local text = Sniff.dropBom(r:string(r:remaining()))
if r.err then
return nil, r.err
end
local m, msg = Parse.parse(text, opts and opts.maxPrimitives)
if not m then
return nil, Err.from(msg)
end
if #m.entities == 0 then
return nil, Err.new(Err.CORRUPT, "no entities")
end
local skip: { [string]: boolean } = {}
for _, s in opts and opts.skip or {} do
skip[string.lower(s)] = true
end
local scene = Scene.new()
scene.meta.up = "z"
local root: Types.Node = { name = "map", children = {} }
scene.nodes[1] = root
scene.roots[1] = 1
local matIndex: { [string]: number } = {}
local function material(nm: string): number
local i = matIndex[nm]
if not i then
table.insert(scene.textures, { name = nm, uri = nm })
local mat = Scene.material(nm)
mat.metallic = 0
mat.baseColorTexture = { texture = #scene.textures }
table.insert(scene.materials, mat)
i = #scene.materials
matIndex[nm] = i
end
return i
end
local stats = { brushes = 0, patches = 0, skippedPrimitives = 0, skippedSides = 0, badPatches = 0 }
local entities: { { [string]: string } } = {}
local total = 0
local maxPolys = opts and opts.maxPolygons or 2 ^ 20
for ei, ent in m.entities do
local keys = ent.keys
table.insert(entities, keys)
stats.skippedPrimitives += ent.skipped
local brushes: { { Brush.Face } } = {}
local grids: { [string]: Grid } = {}
local gridOrder: { string } = {}
for _, prim in ent.prims do
if prim.sides then
stats.brushes += 1
local faces: { Brush.Face } = {}
for _, s in prim.sides do
local f = side(s)
if f then
table.insert(faces, f)
else
stats.skippedSides += 1
end
end
table.insert(brushes, faces)
elseif prim.points then
stats.patches += 1
local mname = prim.material or ""
if not skip[string.lower(mname)] then
local g = grids[mname]
if not g then
g = { pos = {}, nrm = {}, uv = {}, idx = {} }
grids[mname] = g
table.insert(gridOrder, mname)
end
if not addPatch(prim, opts and opts.patchLevel or 4, g :: Grid) then
stats.badPatches += 1
end
end
end
end
local prims: { Types.Primitive } = {}
if #brushes > 0 then
local polys, perr = Brush.polygons(brushes, { hull = opts and opts.hull, merge = opts and opts.merge, epsilon = opts and opts.epsilon, maxPolygons = maxPolys })
if not polys then
return nil, Err.from(perr)
end
total += #polys
if total > maxPolys then
return nil, Err.new(Err.LIMIT, "too many polygons")
end
local keep: { Brush.Polygon } = {}
for _, poly in polys do
if not skip[string.lower(brushes[poly.brush][poly.face].texture or "")] then
table.insert(keep, poly)
end
end
-- Doom 3 texture matrices are in texture widths already: the size divides nothing
local function unit(_: string): (number, number)
return 1, 1
end
for _, built in Brush.primitives(keep, brushes, unit) do
built.primitive.material = material(built.texture)
built.primitive.extras = { d3map = { material = built.texture } }
table.insert(prims, built.primitive)
end
end
for _, mname in gridOrder do
local g = grids[mname]
if #g.idx > 0 then
local prim = gridPrimitive(g)
prim.material = material(mname)
prim.extras = { d3map = { material = mname, patch = true } }
table.insert(prims, prim)
end
end
local node: Types.Node = { name = keys.name or keys.classname or ("entity " .. (ei - 1)), children = {}, extras = { classname = keys.classname, keys = keys, entity = ei - 1 } }
if #prims > 0 then
table.insert(scene.meshes, { name = node.name, primitives = prims })
node.mesh = #scene.meshes
elseif #ent.prims == 0 then
node.translation = numbers(keys.origin, 3)
node.rotation = orientation(keys)
end
table.insert(scene.nodes, node)
table.insert(root.children, #scene.nodes)
end
scene.meta.entities = entities
scene.meta.counts = stats
scene.meta.source = { format = "d3map", version = m.version, variant = if m.version >= 3 then "quake4" else "doom3", entities = #m.entities, brushes = stats.brushes, patches = stats.patches }
return scene, nil
end
return D3map
+380
View File
@@ -0,0 +1,380 @@
--!strict
-- model/proc: Doom 3 / Quake 4 / Prey `.proc` render geometry (dmap output: "mapProcFile003", Quake 4 "PROC" "4"; the
-- Doom 3 GPL source's RenderWorld_load.cpp read for the layout, no code taken), read only. Every model (areas
-- "_areaN", inline entity models) is a mesh with a primitive per surface and a node; materials are URIs. Portals,
-- the BSP nodes and shadow models load as data in meta.proc. Triangles are clockwise-front in id Tech 4
-- (R_DeriveFacePlanes: normal = d2 x d1) and are turned counter-clockwise. Not supported: writing.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Sniff = require("@rosetta/core/Sniff")
local Types = require("@rosetta/Types")
local Lexer = require("@rosetta/codecs/text/Lexer")
-- ------------------------------------------------------------------------------------------------ contract
local Proc = {
name = "proc",
category = "model",
extensions = { "proc" },
mime = { "model/x-doom3-proc" },
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/text/Lexer" },
caps = { decode = true, encode = false, portals = true },
}
-- ------------------------------------------------------------------------------------------------ types
export type DecodeOptions = {
maxVertices: number?, -- default 2^24 over the file
shadows: boolean?, -- default true: keep shadow models in meta.proc.shadowModels
}
export type Portal = { positive: number, negative: number, points: { number } } -- areas; points x, y, z, ...
export type BspNode = { plane: { number }, positive: number, negative: number } -- children: > 0 node (1-based), 0 solid, < 0 area -1 - n
export type ShadowModel = { name: string, vertices: { number }, indices: { number }, noCaps: number, noFrontCaps: number, planeBits: number }
-- ------------------------------------------------------------------------------------------------ constants
local Scene = Types.Scene
local writef32, writeu32 = buffer.writef32, buffer.writeu32
-- ------------------------------------------------------------------------------------------------ sniff
function Proc.sniff(r: Bytes.Reader): number
local head = Sniff.text(r, 64, true)
if string.match(head, "^mapProcFile%d%d%d") then
return 1
end
if string.match(head, '^"?PROC"?%s+"?%d') then
return 0.9
end
return 0
end
-- ------------------------------------------------------------------------------------------------ decode
type P = { L: Lexer.Lexer, err: string? }
local function fail(p: P, msg: string)
if not p.err then
p.err = (p.L.err or msg) .. " at line " .. p.L:line()
end
end
local function num(p: P): number
local k, v = p.L:next()
if k ~= "number" then
fail(p, "expected a number")
return 0
end
return v
end
local function punct(p: P, c: string)
local k, v = p.L:next()
if k ~= "punct" or v ~= c then
fail(p, "expected " .. c)
end
end
local function str(p: P): string
local k, v = p.L:next()
if k ~= "string" and k ~= "word" then
fail(p, "expected a name")
return ""
end
return v
end
-- numbers up to the next punctuation (the counts after a model / surface name)
local function counts(p: P): { number }
local out = {}
while not p.err do
local k, v = p.L:peek()
if k ~= "number" then
break
end
p.L:next()
table.insert(out, v)
end
return out
end
local function skipBlock(p: P)
local depth = 1
while not p.err do
local k, v = p.L:next()
if not k then
fail(p, "unterminated block")
return
end
if k == "punct" then
if v == "{" then
depth += 1
elseif v == "}" then
depth -= 1
if depth == 0 then
return
end
end
end
end
end
type Surface = { material: string, verts: { number }, arity: number, indices: { number } }
local function surface(p: P, budget: { number }): Surface?
local material = str(p)
local c = counts(p)
if p.err then
return nil
end
if #c < 2 then
fail(p, "surface without vertex / index counts")
return nil
end
local nv, ni = c[#c - 1], c[#c]
if nv < 0 or ni < 0 or nv % 1 ~= 0 or ni % 1 ~= 0 or ni % 3 ~= 0 then
fail(p, "bad surface counts")
return nil
end
budget[1] -= nv
if budget[1] < 0 then
p.err = "limit: too many vertices"
return nil
end
local verts: { number } = {}
local arity = 0
for i = 1, nv do
punct(p, "(")
local n = 0
while not p.err do
local k, v = p.L:next()
if k == "number" then
n += 1
table.insert(verts, v)
elseif k == "punct" and v == ")" then
break
else
fail(p, "bad vertex")
end
end
if p.err then
return nil
end
if i == 1 then
arity = n
if n < 8 then
fail(p, "a vertex needs x y z s t nx ny nz")
return nil
end
elseif n ~= arity then
fail(p, "vertices of different sizes")
return nil
end
end
local idx: { number } = table.create(ni, 0)
for i = 1, ni do
local v = num(p)
if v < 0 or v >= nv or v % 1 ~= 0 then
fail(p, "index out of range")
return nil
end
idx[i] = v
end
punct(p, "}")
return { material = material, verts = verts, arity = arity, indices = idx }
end
local function primitive(scene: Types.Scene, s: Surface, matIndex: { [string]: number }): Types.Primitive
local a = s.arity
local n = #s.verts // a
local pb, nb, ub = buffer.create(n * 12), buffer.create(n * 12), buffer.create(n * 8)
local cb: buffer? = if a >= 12 then buffer.create(n * 16) else nil
local V = s.verts
for i = 0, n - 1 do
local o = i * a
writef32(pb, i * 12, V[o + 1])
writef32(pb, i * 12 + 4, V[o + 2])
writef32(pb, i * 12 + 8, V[o + 3])
writef32(ub, i * 8, V[o + 4])
writef32(ub, i * 8 + 4, V[o + 5])
writef32(nb, i * 12, V[o + 6])
writef32(nb, i * 12 + 4, V[o + 7])
writef32(nb, i * 12 + 8, V[o + 8])
if cb then
for k = 0, 3 do
local c = V[o + 9 + k]
writef32(cb, i * 16 + k * 4, if c > 1 then c / 255 else c)
end
end
end
local ni = #s.indices
local ib = buffer.create(ni * 4)
for t = 0, ni - 1, 3 do
writeu32(ib, t * 4, s.indices[t + 1])
writeu32(ib, t * 4 + 4, s.indices[t + 3])
writeu32(ib, t * 4 + 8, s.indices[t + 2])
end
local mi = matIndex[s.material]
if not mi then
table.insert(scene.textures, { name = s.material, uri = s.material })
local mat = Scene.material(s.material)
mat.metallic = 0
mat.baseColorTexture = { texture = #scene.textures }
table.insert(scene.materials, mat)
mi = #scene.materials
matIndex[s.material] = mi
end
local attrs: { [string]: Types.Accessor } = {
POSITION = Scene.accessor(pb, "f32", 3, n),
NORMAL = Scene.accessor(nb, "f32", 3, n),
TEXCOORD_0 = Scene.accessor(ub, "f32", 2, n),
}
if cb then
attrs.COLOR_0 = Scene.accessor(cb, "f32", 4, n)
end
return { attributes = attrs, indices = Scene.accessor(ib, "u32", 1, ni), mode = "triangles" :: any, material = mi, extras = { proc = { material = s.material } } }
end
function Proc.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
local text = Sniff.dropBom(r:string(r:remaining()))
if r.err then
return nil, r.err
end
local p: P = { L = Lexer.new(text), err = nil }
local k, head = p.L:next()
local version: string
if (k == "word" or k == "string") and string.match(head, "^mapProcFile%d+$") then
version = head
elseif (k == "word" or k == "string") and head == "PROC" then
local vk, vv = p.L:next()
if vk ~= "number" and vk ~= "string" then
return nil, Err.new(Err.CORRUPT, "PROC without a version")
end
version = "PROC " .. tostring(vv)
else
return nil, Err.new(Err.CORRUPT, "not a .proc file")
end
local scene = Scene.new()
scene.meta.up = "z"
local world: Types.Node = { name = "proc", children = {} }
table.insert(scene.nodes, world)
scene.roots[1] = 1
local info = { version = version, areas = 0, models = {}, portals = {} :: { Portal }, nodes = {} :: { BspNode }, shadowModels = {} :: { ShadowModel } }
local matIndex: { [string]: number } = {}
local budget = { opts and opts.maxVertices or 2 ^ 24 }
local keepShadows = not (opts and opts.shadows == false)
while not p.err do
local tk, tv = p.L:next()
if not tk then
if p.L.err then
fail(p, p.L.err)
end
break
end
if tk ~= "word" then
fail(p, "expected a section name")
break
end
punct(p, "{")
local section = string.lower(tv)
if section == "model" then
local name = str(p)
local c = counts(p)
local ns = c[1] or 0
local mesh: Types.Mesh = { name = name, primitives = {} }
for _ = 1, ns do
punct(p, "{")
local s = surface(p, budget)
if not s then
break
end
table.insert(mesh.primitives, primitive(scene, s, matIndex))
end
punct(p, "}")
if p.err then
break
end
table.insert(scene.meshes, mesh)
table.insert(scene.nodes, { name = name, children = {}, mesh = #scene.meshes })
table.insert(world.children, #scene.nodes)
table.insert(info.models, { name = name, surfaces = #mesh.primitives, area = tonumber(string.match(name, "^_area(%d+)$")) })
elseif section == "interareaportals" then
info.areas = num(p)
local n = num(p)
for _ = 1, n do
if p.err then
break
end
local np = num(p)
local pos, neg = num(p), num(p)
local pts = {}
for _ = 1, np do
punct(p, "(")
table.insert(pts, num(p))
table.insert(pts, num(p))
table.insert(pts, num(p))
punct(p, ")")
if p.err then
break
end
end
table.insert(info.portals, { positive = pos, negative = neg, points = pts })
end
punct(p, "}")
elseif section == "nodes" then
local n = num(p)
for _ = 1, n do
if p.err then
break
end
punct(p, "(")
local pl = { num(p), num(p), num(p), num(p) }
punct(p, ")")
local pos, neg = num(p), num(p)
table.insert(info.nodes, { plane = pl, positive = if pos > 0 then pos + 1 else pos, negative = if neg > 0 then neg + 1 else neg })
end
punct(p, "}")
elseif section == "shadowmodel" then
local name = str(p)
local c = counts(p)
if #c < 5 then
fail(p, "shadow model without counts")
break
end
local nv, ni = c[1], c[4]
budget[1] -= nv
if nv < 0 or ni < 0 or budget[1] < 0 then
p.err = if budget[1] < 0 then "limit: too many vertices" else "bad shadow model counts"
break
end
local verts, idx = {}, {}
for _ = 1, nv do
punct(p, "(")
table.insert(verts, num(p))
table.insert(verts, num(p))
table.insert(verts, num(p))
punct(p, ")")
if p.err then
break
end
end
for _ = 1, ni do
table.insert(idx, num(p))
if p.err then
break
end
end
punct(p, "}")
if keepShadows then
table.insert(info.shadowModels, { name = name, vertices = verts, indices = idx, noCaps = c[2], noFrontCaps = c[3], planeBits = c[5] })
end
else
skipBlock(p)
end
end
if p.err then
return nil, Err.from(p.err)
end
scene.meta.proc = info
scene.meta.source = { format = "proc", version = version, models = #info.models, portals = #info.portals, nodes = #info.nodes, areas = info.areas }
return scene, nil
end
return Proc
+81
View File
@@ -0,0 +1,81 @@
--!strict
-- model/udmf: a standalone UDMF TEXTMAP (UDMF 1.1, zdoom.org specs/udmf.txt) into a Scene through codecs/model/DoomMap,
-- read only. Texture sizes come from opts.textureSize (default 64 x 128 walls, 64 x 64 flats); textures are URIs.
-- Maps inside a WAD load through archive/wad (Wad.map). Not supported: writing, slopes, per-part offsets.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Sniff = require("@rosetta/core/Sniff")
local Types = require("@rosetta/Types")
local DoomMap = require("@rosetta/codecs/model/DoomMap")
-- ------------------------------------------------------------------------------------------------ contract
local Udmf = {
name = "udmf",
category = "model",
extensions = { "udmf", "textmap" },
mime = { "text/x-udmf" },
deps = { "core/Err", "core/Bytes", "core/Sniff", "Types", "codecs/model/DoomMap" },
caps = { decode = true, encode = false, maps = true },
}
-- ------------------------------------------------------------------------------------------------ types
export type DecodeOptions = {
textureSize: ((kind: string, name: string) -> (number?, number?))?, -- kind "texture" or "flat"
decodeTexture: ((kind: string, name: string) -> Types.Image?)?,
name: string?, -- the mesh name, default "MAP"
maxBlocks: number?, -- default 2^22
}
-- ------------------------------------------------------------------------------------------------ sniff
function Udmf.sniff(r: Bytes.Reader): number
local head = Sniff.text(r, 1024, true)
for _ = 1, 32 do
local rest = string.match(head, "^//[^\n]*\n%s*(.*)$") or string.match(head, "^/%*.-%*/%s*(.*)$")
if not rest then
break
end
head = rest
end
if string.match(head, "^[Nn][Aa][Mm][Ee][Ss][Pp][Aa][Cc][Ee]%s*=%s*\"") then
return 0.9
end
return 0
end
-- ------------------------------------------------------------------------------------------------ decode
function Udmf.data(r: Bytes.Reader, opts: DecodeOptions?): (DoomMap.MapData?, Err.Err?)
local text = Sniff.dropBom(r:string(r:remaining()))
if r.err then
return nil, r.err
end
local m, msg = DoomMap.udmf(text, opts and opts.maxBlocks)
if not m then
return nil, Err.from(msg)
end
return m, nil
end
function Udmf.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Scene?, Err.Err?)
local m, err = Udmf.data(r, opts)
if not m then
return nil, err
end
local size = opts and opts.textureSize
local tex: DoomMap.Textures = {
size = function(kind: string, name: string): (number?, number?)
if size then
return size(kind, name)
end
return nil, nil
end,
image = opts and opts.decodeTexture,
}
local name = opts and opts.name or "MAP"
local scene = DoomMap.scene(m, tex, name)
scene.meta.source = { format = "udmf", namespace = m.namespace, things = #m.things, linedefs = #m.linedefs, sectors = #m.sectors, vertices = #m.vertices // 2 }
return scene, nil
end
return Udmf
+95
View File
@@ -0,0 +1,95 @@
--!strict
--!native
-- vector/gamemaps/Expand: id's Carmack (near 0xA7 / far 0xA8 word copies) and RLEW (tag, count, value) expansion of
-- GAMEMAPS planes (ModdingWiki "Carmack compression", "RLEW compression"; no code taken). Words are u16 LE.
local Expand = {}
local readu8, readu16, writeu16 = buffer.readu8, buffer.readu16, buffer.writeu16
function Expand.carmack(b: buffer, at: number, n: number, outBytes: number): (buffer?, string?)
if outBytes % 2 ~= 0 then
return nil, "odd Carmack length"
end
local out = buffer.create(outBytes)
local words = outBytes // 2
local o = 0
local p, e = at, at + n
while o < words do
if p + 2 > e then
return nil, "truncated Carmack data"
end
local w = readu16(b, p)
p += 2
local hi = w // 256
if hi == 0xA7 or hi == 0xA8 then
local count = w % 256
if count == 0 then
if p + 1 > e then
return nil, "truncated Carmack data"
end
writeu16(out, o * 2, hi * 256 + readu8(b, p))
p += 1
o += 1
else
local from
if hi == 0xA7 then
if p + 1 > e then
return nil, "truncated Carmack data"
end
from = o - readu8(b, p)
p += 1
else
if p + 2 > e then
return nil, "truncated Carmack data"
end
from = readu16(b, p)
p += 2
end
if from < 0 or from >= o or o + count > words then
return nil, "bad Carmack copy"
end
for k = 0, count - 1 do
writeu16(out, (o + k) * 2, readu16(out, (from + k) * 2))
end
o += count
end
else
writeu16(out, o * 2, w)
o += 1
end
end
return out, nil
end
function Expand.rlew(b: buffer, at: number, n: number, outWords: number, tag: number): (buffer?, string?)
local out = buffer.create(outWords * 2)
local o = 0
local p, e = at, at + n
while o < outWords do
if p + 2 > e then
return nil, "truncated RLEW data"
end
local w = readu16(b, p)
p += 2
if w == tag then
if p + 4 > e then
return nil, "truncated RLEW data"
end
local count, v = readu16(b, p), readu16(b, p + 2)
p += 4
if o + count > outWords then
return nil, "RLEW run past the plane"
end
for k = 0, count - 1 do
writeu16(out, (o + k) * 2, v)
end
o += count
else
writeu16(out, o * 2, w)
o += 1
end
end
return out, nil
end
return Expand
+185
View File
@@ -0,0 +1,185 @@
--!strict
-- vector/gamemaps: Wolfenstein 3D / Spear of Destiny maps (GAMEMAPS "TED5v1.0" + MAPHEAD: RLEW tag, 100 header
-- offsets; map headers of 3 planes, Carmack then RLEW compressed; ModdingWiki "GameMaps Format", no code taken) into a
-- TileMap: one tile layer per plane ("walls", "objects", "plane3") with the raw tile values as data (no tileset).
-- Either file loads; the other comes through opts.files / opts.resolve. Not supported: writing, uncompressed
-- (MAPTEMP / Wolf3D 1.0) maps, Huffman-compressed (Keen) maps.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Input = require("@rosetta/core/Input")
local Types = require("@rosetta/Types")
local Expand = require("@rosetta/vector/gamemaps/Expand")
-- ------------------------------------------------------------------------------------------------ contract
local Gamemaps = {
name = "gamemaps",
category = "vector",
extensions = { "wl6", "wl1", "sod", "sdm" },
mime = { "application/x-wolf3d-gamemaps" },
deps = { "core/Err", "core/Bytes", "core/Input", "Types" },
caps = { decode = true, encode = false, tilemap = true },
}
-- ------------------------------------------------------------------------------------------------ types
export type DecodeOptions = {
map: number?, -- 1-based map slot, default the first present
name: string?, -- the file name: picks the sibling's extension (GAMEMAPS.WL6 <-> MAPHEAD.WL6)
files: { [string]: buffer | string }?,
resolve: ((uri: string) -> (buffer | string)?)?,
mapHead: (buffer | string)?, -- MAPHEAD given directly
gameMaps: (buffer | string)?, -- GAMEMAPS given directly
maxTiles: number?, -- default 2^20 per plane
}
export type MapInfo = { slot: number, name: string, width: number, height: number, offset: number }
-- ------------------------------------------------------------------------------------------------ constants
local MAGIC = "TED5v1.0"
local LAYERS = { "walls", "objects", "plane3" }
-- ------------------------------------------------------------------------------------------------ sniff
function Gamemaps.sniff(r: Bytes.Reader): number
if r:peek(8) == MAGIC then
return 1
end
-- MAPHEAD: the RLEW tag 0xABCD, then 100 offsets (0 / -1 when absent)
if r:remaining() >= 402 and r:remaining() <= 1024 and buffer.readu16(r.buf, r.base) == 0xABCD then
local first = buffer.readi32(r.buf, r.base + 2)
if first > 0 then
return 0.7
end
end
return 0
end
-- ------------------------------------------------------------------------------------------------ decode
local function asBuffer(v: any): buffer?
if type(v) == "string" then
return buffer.fromstring(v)
end
return if type(v) == "buffer" then v else nil
end
local function sibling(opts: DecodeOptions?, stem: string): buffer?
local name = opts and opts.name
local ext = name and string.match(name, "%.([^./\\]+)$") or "WL6"
local dir = name and string.match(name, "^(.*[/\\])") or ""
for _, n in { stem .. "." .. ext, string.upper(stem .. "." .. ext), string.lower(stem .. "." .. ext) } do
local got = Input.sibling(opts, dir .. n) or Input.sibling(opts, n)
if got then
return got
end
end
return nil
end
type Pair = { head: buffer, maps: buffer, tag: number }
local function pair(r: Bytes.Reader, opts: DecodeOptions?): (Pair?, Err.Err?)
local self = buffer.create(r.limit - r.base)
buffer.copy(self, 0, r.buf, r.base, r.limit - r.base)
local head: buffer, maps: buffer
if buffer.len(self) >= 8 and buffer.readstring(self, 0, 8) == MAGIC then
maps = self
local got = asBuffer(opts and opts.mapHead) or sibling(opts, "MAPHEAD")
if not got then
return nil, Err.new(Err.UNSUPPORTED, "MAPHEAD not available (opts.mapHead / opts.files / opts.resolve)")
end
head = got
else
head = self
local got = asBuffer(opts and opts.gameMaps) or sibling(opts, "GAMEMAPS")
if not got then
return nil, Err.new(Err.UNSUPPORTED, "GAMEMAPS not available (opts.gameMaps / opts.files / opts.resolve)")
end
maps = got
end
if buffer.len(head) < 2 then
return nil, Err.new(Err.TRUNCATED, "MAPHEAD")
end
return { head = head, maps = maps, tag = buffer.readu16(head, 0) }, nil
end
local function list(p: Pair): { MapInfo }
local out: { MapInfo } = {}
local hn = math.min(100, (buffer.len(p.head) - 2) // 4)
local size = buffer.len(p.maps)
for i = 0, hn - 1 do
local o = buffer.readi32(p.head, 2 + i * 4)
if o > 0 and o + 38 <= size then
local nm = buffer.readstring(p.maps, o + 22, 16)
local z = string.find(nm, "\0", 1, true)
table.insert(out, { slot = i + 1, name = if z then string.sub(nm, 1, z - 1) else nm, width = buffer.readu16(p.maps, o + 18), height = buffer.readu16(p.maps, o + 20), offset = o })
end
end
return out
end
function Gamemaps.maps(r: Bytes.Reader, opts: DecodeOptions?): ({ MapInfo }?, Err.Err?)
local p, err = pair(r, opts)
if not p then
return nil, err
end
return list(p), nil
end
function Gamemaps.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.TileMap?, Err.Err?)
local p, err = pair(r, opts)
if not p then
return nil, err
end
local maps = list(p)
if #maps == 0 then
return nil, Err.new(Err.CORRUPT, "no maps in MAPHEAD")
end
local want = opts and opts.map
local m: MapInfo? = if want then nil else maps[1]
for _, x in maps do
if x.slot == want then
m = x
end
end
if not m then
return nil, Err.new(Err.ARG, "no map in slot " .. tostring(want))
end
local w, h = m.width, m.height
if w == 0 or h == 0 or w * h > (opts and opts.maxTiles or 2 ^ 20) then
return nil, Err.new(if w * h == 0 then Err.CORRUPT else Err.LIMIT, "map size " .. w .. " x " .. h)
end
local b = p.maps
local size = buffer.len(b)
local tm = Types.TileMap.new(w, h, 64, 64)
for k = 0, 2 do
local at = buffer.readi32(b, m.offset + k * 4)
local n = buffer.readu16(b, m.offset + 12 + k * 2)
if at > 0 and n >= 2 then
if at + n > size then
return nil, Err.new(Err.TRUNCATED, "plane " .. (k + 1) .. " past the end", at)
end
local carmackLen = buffer.readu16(b, at)
local mid, msg = Expand.carmack(b, at + 2, n - 2, carmackLen)
if not mid then
return nil, Err.from(msg, at)
end
if carmackLen < 2 or buffer.readu16(mid, 0) ~= w * h * 2 then
return nil, Err.new(Err.CORRUPT, "plane " .. (k + 1) .. ": RLEW length is not width x height", at)
end
local plane, rmsg = Expand.rlew(mid, 2, carmackLen - 2, w * h, p.tag)
if not plane then
return nil, Err.from(rmsg, at)
end
local data = table.create(w * h, 0)
for i = 0, w * h - 1 do
data[i + 1] = buffer.readu16(plane, i * 2)
end
local layer: Types.TileLayer = { type = "tiles", id = k + 1, name = LAYERS[k + 1], width = w, height = h, data = data, visible = true, opacity = 1, properties = {} }
table.insert(tm.layers, layer)
end
end
tm.properties.name = m.name
tm.meta.source = { format = "gamemaps", map = m.slot, name = m.name, rlewTag = p.tag, maps = maps }
return tm, nil
end
return Gamemaps