weopqrst/moonroll/examples/scene does not have a README file

    LinkSpec

    pub struct LinkSpec {
    delay : Int
    jitter : Int
    loss : Int
    reorder : Int
    }

    一条确定性链路的参数。时间单位是逻辑帧(60fps 下 1 帧 ≈ 16.7ms), loss / reorder 是百分比。

    LinkSpec::new

    fn LinkSpec::new(delay : Int, jitter : Int, loss : Int, reorder : Int) -> LinkSpec

    LinkStats

    pub struct LinkStats {
    p0_confirmed : Int
    p1_confirmed : Int
    p0_rollbacks : Int
    p1_rollbacks : Int
    mismatches : Int
    first_divergence : Int
    hash0 : UInt64
    hash1 : UInt64
    replayed_p0 : Int64
    max_depth : Int
    dropped : Int
    synced : Bool
    }

    一条链路的运行结果。

    Scene

    pub struct Scene {
    x : UInt64
    }

    示例共用的小世界,支持 1..8 个玩家。

    每个玩家各有 3 个按键,状态是单个 64 位整数,每帧把所有人的输入按下标 混进同一个数:只要漏掉一帧输入、或者重放顺序不对,状态就会立刻分叉。 示例里看到的回滚与分叉检测因此是真实发生的,不是摆拍。
    impl Sim for Scene

    Scene::hash

    fn Scene::hash(self : Scene) -> UInt64

    显式声明「把 Sim 的方法提升为 Scene 的方法」,消除 W0079。

    Scene::new

    fn Scene::new() -> Scene

    Scene::restore

    fn Scene::restore(self : Scene, bytes : Bytes) -> Unit

    显式声明「把 Sim 的方法提升为 Scene 的方法」,消除 W0079。

    Scene::save

    fn Scene::save(self : Scene) -> Bytes

    显式声明「把 Sim 的方法提升为 Scene 的方法」,消除 W0079。

    Scene::state

    fn Scene::state(self : Scene) -> UInt64

    Scene::step_players

    fn Scene::step_players(self : Scene, inputs : Array[UInt64]) -> Unit

    显式声明「把 Sim 的方法提升为 Scene 的方法」,消除 W0079。

    apply

    fn apply(payload : Bytes, s :
    Session
    [Scene]) -> Int

    把一条链路上的字节解成消息并投递,返回本次发现的校验失配数。
    fn run_link(spec : LinkSpec, frames : Int, corrupt_frame : Int) -> LinkStats

    跑一局两个对等体的对局,返回统计结果。

    corrupt_frame 不为 0 时,P1 在那一帧「本地执行 A、发出去的是 B」—— 用来验证分叉检测确实能在正确的帧上报出来。

    之所以不去直接改内存里的状态:回滚会从快照恢复并重放,任何没有被 记录进输入流的改动都会被洗掉;只有输入流本身出错才会留下痕迹。

    scripted_input

    fn scripted_input(frame : Int, player : Int) -> UInt64

    确定性的「玩家操作脚本」:每 6 帧换一次按键组合,各玩家相位错开。

    示例不接键盘,是为了让输出可以逐位复现——moon run 两次结果必须一样。

    Source Files