examples/waypoint in Reactor
Runtime 3.11.9, and the code below is simplified from it.
Files
examples/waypoint/
Waypoint, the model class. Waypoint calls WaypointModel, which runs the weights through
Overworld’s world_engine and imports nothing from Reactor. The two
classes exchange WaypointInput and WaypointResult. Model Structure
describes this split.
Contract
The contract declares the output track and the controls that a client can set:waypoint.py (simplified)
- Video track:
WaypointOutputdeclares the outboundmain_videotrack. The attribute name is the track name that the client receives. - Commands: each field becomes a command named
set_<field>. For example,set_actionsetsaction. The runtime rejects a value outside the field’s limits, such aschoicesorgeandle.
@event: set_image and reset.
Loading
The runtime callsload() once, when the instance starts and before any session:
waypoint.py (simplified)
config_path points to config.yml. get_weights_path() returns the folder that holds the Waypoint-1.5-1B weights:
the weights the deploy pinned with --weights, or runtime.weights_path in reactor.yaml for a local run.
Waypoint passes the folder to WaypointModel, so the world model class still imports nothing from Reactor.
WaypointModel.load() reads config.yml, loads the weights from the folder onto the GPU, and runs 50 warmup steps.
The warmup compiles the kernels, so the first session does not wait for them. The engine also downloads a small
autoencoder, about 23 MB, from Hugging Face, because the checkpoint’s own configuration names it.
The step
The runtime runs the model in a loop of steps. Each step calls 3 methods in order:Read the controls
process_input() builds the input for each step:
waypoint.py (simplified)
process_input() turns the session state into a WaypointInput, the input that WaypointModel can generate from.
The state holds the controls the way a client sets them: a movement name such as forward, extra key codes, and mouse
and scroll values. The world engine reads a set of pressed keys instead, so button_set() converts action and
buttons into one set of key codes. For example, forward becomes the W key. The mouse and scroll values pass
through unchanged.
The seed image is the image that starts the world: the client uploads it with set_image, and it becomes the first
frame. The input carries it only on the first step after set_image or reset. On every other step, seed is
None, and the world model continues the world that it holds.
When the state is not enough to make frames, the step is skipped. While the session is paused, or before a seed image
arrives, process_input() raises ApplicationError. The runtime skips the step and calls process_input() again on
the next one.
Make the frames
Each step then callsgenerate() with the WaypointInput from process_input(). On Waypoint, it only passes the
input on to the model:
waypoint.py (simplified)
WaypointModel.generate() does the GPU work. When the seed has changed, it starts a new world from it. Then it makes
the next 4 frames and returns them in a WaypointResult:
waypoint_model.py (simplified)
Send the frames
process_output() receives the result of generate() and sends the 4 frames to the client on main_video:
waypoint.py (simplified)
generate() fails, the error arrives in outcome.error. process_output() raises it again, and the runtime ends the
session with an error that the client sees.
The full method also tags each frame with its step number, notes which seed the world model holds, and sends
waypoint_status every 50 steps.
Commands written by hand
Two commands need more than a field write, so the model class declares them with@event:
waypoint.py (simplified)
set_imagestores the uploaded image as the new seed. The new_seed_idtells the next step to start a new world from it.resetclears the world model. The next step starts again from the seed image that the session already has.
waypoint_status.
Sessions and reset
- Client connects:
@connectedsends the currentwaypoint_statusto the client that joined. - Session end:
@session_endedcallsWaypointModel.reset()and drops the frames that are not sent yet. The seed image and the controls reset with the rest of the state, so the next session starts with no world. resetcommand: starts the world again from the current seed image, in the same session.