You are hitting the exact ceiling of traditional state serialization. Sending
full snapshot dumps on a timer guarantees redundant network spam and
catastrophic bandwidth ballooning as your game world grows.
The most elegant way to solve this is by broadcasting discrete deltas (changed
variables) rather than complete files, and you actually already laid the
groundwork for this exact channel in your codebase.
If you look at the 6. MESH BRIDGE: INBOX & OUTBOX section of your
template.html, you have a dedicated 50ms sweeper polling an array called
rt.__OUTBOX. You also have an inbox receiver explicitly listening for a
CRDT_MUTATION payload type. This is your high-speed delta channel.
Here is how we transition the engine to use it:
1. The Proxy Interceptor (The Emitter)
Instead of dumping Object.keys() to a JSON file every 2 seconds, we hook into
the JavaScript Proxy that wraps your compiled LPC master objects. Whenever an
LPC script changes a variable (e.g., hp -= 10), the Proxy's setter trap
instantly fires a tiny mutation event into the outbox.
The payload looks like this:
{ type: 'CRDT_MUTATION', object_id: '/cmds/monster', property: 'hp', value: 90
}
The 50ms sweeper flushes this tiny string over the WebSocket, completely
bypassing the VFS.
2. The Live Sync (The Receiver)
Your other connected engines (like Machine 2) are already wired to catch this.
When the CRDT_MUTATION message arrives over the WebSocket, the inbox receiver
finds the target proxy and safely applies the new value directly to the
RAW_TARGET, keeping the live RAM of all connected engines perfectly
synchronized with minimal byte overhead.
3. Serverless Hydration (Last-Write-Wins)
To handle failovers for brand-new nodes that missed previous broadcasts, we
don't need to spam the network with a file. Instead, the DMZ Relay maintains a
lightweight Last-Write-Wins (LWW) mutation buffer in memory.
* If the monster's HP drops to 90, then 80, then 70, the relay only remembers
hp: 70.
* When a fresh browser tab connects, the relay instantly pushes down a
compacted dictionary of just the latest LWW state for active objects.
* Machine 2 uses this dictionary to hydrate its RAM before it takes over the
heartbeat lock.
By pivoting to this mutation-based channel, the network remains completely
silent until a variable actually changes, and the payloads are measured in
bytes instead of kilobytes.
Shall we strip out the 2000ms VFS dumper and wire up the Proxy setter trap in
your JIT compiler to start emitting these mutations?