Skip to main content

Module queue

Module queue 

Source
Expand description

One ordered action queue: the view pushes, the sim drains.

All thirteen hand-rolled copies in the games are the same type — a Sink = Arc<Mutex<Vec<UiAction>>> plus a drain_actions(&mut World) free function plus a boolean Intents resource that the drained actions are folded into. This module is that whole pattern once, split into two pieces with fixed semantics:

  • ActionQueue<A> and Sink<A> are two handles on one buffer. The sink goes into click closures; the queue stays where the frame can drain it. Order is preserved across any interleaving of pushes and drains, and a drained batch never contains an action that was pushed after the drain started.
  • Intents<A> is the ordered edge view of the drained batch: ask Intents::take for one occurrence of an action and it is consumed, so a boolean flag per action is no longer needed. Payload-carrying actions go through Intents::take_matching.

Neither type has to be an ECS resource, so this crate carries no bevy_ecs dependency: a game puts the handles inside the resource wrapper it already declares (all thirteen copies already have one). A sim system reads them through that resource exactly as it reads any other:

ⓘ
fn absorb_ui(ui: Res<UiActions>, mut intents: ResMut<UiIntents>) {
    repame_ui::absorb(&ui.0, &mut intents.0);
}

or, without a resource at all, a closure system holding the queue:

ⓘ
let queue = ActionQueue::<UiAction>::new();
let sink = queue.sink();
sim.add_system(move || {
    for action in queue.drain() {
        // answer it
    }
});

Structs§

ActionQueue
The drain side of an action queue: the same buffer as its Sink.
Intents
The actions drained for the current tick, consumed by the systems that answer them.
Sink
The push side of an ActionQueue. Hand it to click closures.

Traits§

UiAction
An action a UI control can raise.

Functions§

absorb
Fold a drained batch into an intent buffer.