sequencer

A way to create a dependency graph of items to be executed.

Data and Execution model

This crate allows you to create a Directed Acyclic Graph of items and track which items are currently "active". Once an item is marked as completed, any child nodes of that item that have all their parents completed are marked as active.

Intended uses

This crate was made for sequencing/scripting events for a game though it could be used for anything that can be modeled as a dependency graph.

Cargo

Add the following to Cargo.toml:

toml sequencer = "0.1"

Examples

A simple linear sequence such as wait for 5 ticks and then print something can be expressed as:

```rust enum Actions { Wait(usize) Print(String) }

impl Actions { fn tick(&mut self) -> bool { match self { ... } } }

fn main() { let mut sequencer = Sequencer::default(); sequencer.newseq(vec![Wait(5usize), Print("Done waiting".tostring())]); while sequencer.isactive() { // Activate next nodes ready for processing sequencer.drainqueue(|key, action| {}); // Process active nodes. Returning true means the node was finishes. sequencer.foreachactive(|key, item| item.tick()); } } ```

Check examples dir for complete examples.

Features to add: