Module systems

Expand description

Prepared, bounded sequential execution over the existing SystemOrder.

Register at most 256 named entries (systems and flush boundaries combined), declare dependencies, then prepare once before running. The cached sequence preserves SystemOrder::resolve’s earliest-ready rule, not flattened layer order. Successful edits invalidate preparation; rejected edits leave the previous prepared sequence usable.

Each run starts at the beginning. Disabled entries bypass their predicates; otherwise an optional predicate is evaluated immediately before invocation. Skipping an entry does not skip its dependents: edges constrain ordering, not whether prerequisites executed. Flush entries are ordinary named callbacks marking explicit synchronization points, enabled unconditionally by default. There is no implicit flush at the start, end, stop or error of a run.

Stop/error suppresses the unvisited tail, including its predicates and flushes. Mutations already made remain; no callback is rolled back or automatically retried. Panics propagate with the same tail suppression and no returned report. A later explicit run starts over, so the host must decide whether reuse is safe. Clearing the schedule drops callbacks without invoking them. It does not reset the caller’s context, pending commands, session, or captured external state.

Registration/preparation may allocate. Prepared execution performs no runner allocations or name lookup; callback/predicate work and payload size are host controlled. No clock, renderer, platform I/O, parallelism or borrow inference is involved. Run once per executed tick; predicates must not freeze required authoritative network/replay work just because a local menu is visible.

§Fixed ticks and an explicit command flush

This headless recipe uses the existing command queue. Only the named flush publishes queued changes.

use ferravex_engine::{app::TickContext, commands::CommandBuffer, session::GameSession};
use ferravex_engine::systems::{SystemControl, SystemSchedule};

struct Simulation {
    tick: TickContext,
    position: f32,
    commands: CommandBuffer<f32>,
    published: f32,
}
let mut schedule = SystemSchedule::<Simulation, &'static str>::default();
schedule.register("publish-check", |sim| {
    assert_eq!(sim.published, sim.position);
    Ok(SystemControl::Continue)
}).unwrap();
schedule.register("motion", |sim| {
    sim.position += 4.0 * sim.tick.dt;
    let position = sim.position;
    sim.commands.push(move |published| *published = position)
        .map_err(|_| "command capacity")?;
    Ok(SystemControl::Continue)
}).unwrap();
schedule.register_flush("flush", |sim| {
    sim.commands.apply(&mut sim.published, usize::MAX);
    Ok(SystemControl::Continue)
}).unwrap();
schedule.before_checked("motion", "flush").unwrap();
schedule.before_checked("flush", "publish-check").unwrap();
schedule.prepare().unwrap();
assert_eq!(schedule.prepared_names().unwrap().collect::<Vec<_>>(),
           ["motion", "flush", "publish-check"]);
let mut sim = Simulation {
    tick: TickContext { tick: 0, batch_index: 0, dt: 1.0 / 64.0 },
    position: 0.0, commands: CommandBuffer::new(1), published: 0.0,
};
let mut session = GameSession::new(64.0, 4, true);
assert_eq!(session.advance_batch(0.5 / 64.0).ticks().len(), 0);
let batch = session.advance_batch(2.0 / 64.0);
let mut executed = 0;
for tick in batch.ticks() {
    sim.tick = tick;
    executed += 1; // Includes a run that returns Stop or Err; not a commit count.
    let report = schedule.run(&mut sim).unwrap();
    assert_eq!((report.invoked, report.flushes), (3, 1));
    if report.control == SystemControl::Stop { break; }
}
assert_eq!(executed, 2);
assert_eq!(sim.tick.tick, 2);
assert_eq!(sim.published, 8.0 / 64.0);

Structs§

ScheduleReport
Counts for one run, including partial progress on callback error.
SystemSchedule
A reusable sequential runner with one SystemOrder as its dependency graph.

Enums§

SchedulePrepareError
Preparation rejected the entire schedule; no callback or predicate ran.
ScheduleRunError
A run failure. Names borrow the schedule, avoiding allocation on failure.
SystemControl
Whether to continue this schedule invocation. Stop is not a permanent latch.
SystemEntryKind
The role of a named callback; both kinds obey the same ordering and predicates.