// Load a destination game scene before detaching the current scene and discard stale load callbacks. use std::cli; pub fn scene_stream_start() -> vector { [0, 0, 0] } pub fn scene_stream_step(snapshot: vector, event: str, value: f64) -> vector { if len(snapshot) != 3 { return []; } let phase = at(snapshot, 0); let saved = at(snapshot, 1); let previous = at(snapshot, 2); if !(phase >= 0.0 && phase < 4.0 && phase % 1.0 == 0.0 && previous >= 0.0 && previous < 5.0 && previous % 1.0 == 0.0 && saved >= 0.0 && saved <= 9007199254740991.0 && saved % 1.0 == 0.0) { return []; } if !(value >= 0.0 && value <= 1000000000.0 && value % 1.0 == 0.0) { return [phase, saved, 0]; } // idle if phase == 0.0 { if event == "go" && value>0.0 { return [1, value, 1]; // load_scene } } // loading if phase == 1.0 { if event == "go" && value!=saved { return [1, value, 2]; // replace_request } if event == "loaded" && value==saved { return [2, saved, 3]; // attach_scene } } // swapping if phase == 2.0 { if event == "active" && value==saved { return [3, saved, 4]; // detach_previous } } // ready if phase == 3.0 { if event == "go" && value!=saved { return [1, value, 1]; // load_scene } } [phase, saved, 0] } pub fn scene_stream_command(snapshot: vector) -> str { if len(snapshot) != 3 { return "invalid"; } let action = at(snapshot, 2); if action == 0.0 { return "reject"; } if action == 1.0 { return "load_scene"; } if action == 2.0 { return "replace_request"; } if action == 3.0 { return "attach_scene"; } if action == 4.0 { return "detach_previous"; } "invalid" } // Stop at the first rejected event. No host effects run during replay. pub fn scene_stream_replay(events: arglist, values: vector) -> vector { if args_len(events) != len(values) { return []; } let mut state = scene_stream_start(); let mut i = 0; while i < len(values) { state = scene_stream_step(state, args_at(events, i), at(values, i)); if at(state, 2) == 0.0 { return []; } i += 1; } state }