Skip to content

Architecture: level mods as recipes

Decided 23 November 2026. A level mod holds only the modder's own work, and the port builds the playable scene from the player's own disc. This page is the design the level tools are moving to; knowledge-base.md has the reasons.

What a level mod contains

my_level/
  mod.json             manifest with a "levels" entry pointing at the recipe
  levels/my_level/
    level.json         the recipe: base scene, rooms, actors, mission, text
    my_level.glb       geometry, materials, textures, lights, rooms, portals,
                       navigation, 47's start, actor spawns and routes
    mission.lua        the mission logic, run by the port's Lua mod runtime while the
                       level is loaded; named in level.json by mission.script
    photos/*.png       target photos for the briefing
    sounds/*.wav       sounds placed in rooms or played by mission events
    map.png            optional: the pause map
    news/*.png         optional: the newspaper page and its pictures

Nothing in it comes from the disc. The Blender naming conventions are in new-scene.md, Making a level in Blender, and the recipe format is recipe-format.md. The example is tools/port/scene/examples/gallery_contract/; tools/port/scene/build_level.py builds it (phase A).

Planned build-on-first-play cache

  1. Builds on first play. When the player starts a level that isn't built, or whose recipe, assets or builder version changed, the launcher builds it:
    • reads the base scene named in the recipe from the player's disc;
    • strips its world;
    • adds the recipe's geometry, collision, rooms, sound graph, navigation, actors, mission data, text, sounds and photos;
    • writes the result to a cache in the player's folder (<user>/level_cache/<mod id>/<level id>/).
  2. Serves from the cache. The disc overlay (port/engine/system/_sdl/cdreadsdl.cpp) serves cached files the way it serves a mod's raw/ files today.

What the builder and port support today

  1. Front-end scenes are the level's own. The briefing (with the target photos and text), the pause map, the news and the debriefing are built from the base mission's scenes with the recipe's content. A custom level gets its own row of scene names in the level table (ZLevelLinking): the launcher renames the campaign slot's row to the level's scene_code while it plays, so the disc's own scenes never need replacing (front-end-scenes.md). The front-end scenes are edited in place (text, texels, names); no geom is added to them.
  2. Mission logic is Lua, like the rest of the modding system. The level mod's mission.lua runs in the port's Lua runtime while its level is loaded. A small standard library covers the common cases: targets, exits, objectives, completion and failure, and events that play a sound or show text. The script drives the game's own level bookkeeping through obm.api and the obm.mission functions, and can take over a scene object's script with obm.scripts.replace. Nobody compiles C for a level. The scene keeps the base mission’s scripts compiled into the port (native code) and its level control runs the shared alllevels\levelcontrol, which has no mission logic; the level's mod.json entry names the file ("mission": "levels/<id>/mission.lua"), and the runtime loads it with the scene and removes everything it registered when the scene goes. mission-script.md is the reference.

The builder in two languages

The Python tools in tools/port/scene/ are the reference. They were proved against all 71 disc scenes, and they stay the place where formats are explored. The port gets a C++ builder that follows them. The test between the two is the same one that proved the formats: for every recipe in the repository, the C++ builder must write byte-identical archives to the Python builder. Future format work lands in Python first, with its round-trip test, and then in C++.

Phases

Phase Content State
A The combined mission as a recipe: the showcase geometry, three targets, our text, sounds, target photos, map and front-end scenes, built by the Python reference done (the debriefing backdrop's shapes and the music are still M01's)
B Lua missions: running a level's mission.lua, the mission library, and any Lua API the engine bookkeeping needs done: level missions in the runtime, obm.mission.define, obm.world.ref, script-message hooks; the contract spec plays with its Lua mission (mission-script.md)
C The C++ builder in the port, the launcher's build-on-first-play with progress and cache, the equivalence test against Python next
D Blender Level Editor Extension using the scene tools and a separate game process for playtests Available for Blender 4.2+ LTS (all 14 campaign missions, custom multi-story levels, and external 3D map porting)

What stays out

  • The PS2 build. Level support is port-only, as with every mod feature.
  • Shipping game data. Recipes, the tools and the cache rule out any path where a built archive travels between players.