If you've worked on a game with an editor preview, you've probably seen this one. Something works in the editor and breaks in the build, or the reverse. We had it a lot early this year. When we finally sat down and looked into it, we found the same NAL game was being run by three separate pieces of code.
How we ended up with three
We never planned it. Each one showed up because, at the time, it was the fastest way to get something on screen.
NativeWorldwas the real game loop, in Rust. It had all of NAL v2, events, 3D, deferred spawning and named input actions.WasmWorldwas a second Rust world (47 KB of it) built for the browser. It only understood the older JSON version of NAL, had basic box collisions and no 3D.- The IDE's JavaScript game loop kept track of entities itself and called into WebAssembly to run one transform at a time. Particles, timers, events and the camera all lived in TypeScript.
Inside the third one was a function called compileTransform, which translated NAL into JavaScript using regular expressions. It was meant as a fallback. Our write-up when we audited all three called it "the root cause of IDE/native behavioral divergence", and that was about right.
Where they disagreed
Once we put them side by side, the differences were easy to find:
| Behaviour | Native | Browser |
|---|---|---|
| Event timing | Handled inside the same tick | Sent back to JS and handled a frame later |
| Pausing | pause_exempt systems keep running | No equivalent, just enabled |
| Collisions | Pushes objects apart and applies game effects (goals, hazards, pickups) | Detects overlaps, nothing more |
for e in World.all(...) | Works | Not supported |
| 3D | Full render data and camera | None |
Most people would have seen a game in the browser preview first, which is exactly where the gaps were. (This table is how things stood at the time of the audit. Native event handling has since changed to always run on the next frame, and with only one implementation left, that's now the only behaviour.)
One session, with JSON in between
The fix was to keep exactly one implementation of the game rules and make everything else talk to it through a narrow interface. That interface is GameSession. It wraps NativeWorld, and everything that crosses it is JSON:
GameSession::create(nal_source) // parse, resolve, load
GameSession::step_frame(input_json) // → render data JSON:
// sprites, 3D entities, camera,
// audio commands, UI, pending_scene
GameSession::get_state() // full entity snapshot
GameSession::load_scene(name, source)
We did the removal in steps. First WasmWorld was replaced by WasmSession, a thin wasm_bindgen wrapper around the same GameSession. Next the IDE preview was switched over to it. Then we deleted the JavaScript simulation, regex translator included. An older crate called resonance-runtime got archived along the way.
A few things stayed in JavaScript on purpose, because they're about presentation: the preview camera, playing sound through WebAudio, and reading scene files off disk. For sound, the session returns commands and the browser plays them. The IDE docs now describe the preview as "a thin TypeScript shell with zero game-world simulation code", and we hold ourselves to that.
A fourth way in
Getting rid of the extra runtimes still left the matter of how games got loaded. In September we went through every tool that opens a game (the native player, sessions, the validator, the MCP server, Rezzy, the packager and the IDE) and made them all use one project and module resolver.
We missed a spot. In October, if you launched Ember Colony by pointing the player straight at src/game.nal, it loaded that one file before looking for the project manifest. Imports were never resolved, and components were missing their default values. Every frame printed
transform error: UnknownField { component: "Colony", field: "time_of_day" }The tests didn't catch it, because they go through GameSession, which always resolves imports. It was the same problem as before on a smaller scale: a second way of doing something will eventually behave differently from the first. The fix made the direct-file path find the project folder first and then use the shared loader.
We now count loading and project setup as part of a game's behaviour, the same as the rules themselves. The JSON boundary has paid off in ways we didn't expect when we drew it. It turned out to be what the MCP server, Rezzy and the test suite all needed too.