Skip to content

mdenchev/sequencer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

sequencer = "0.1"

Examples

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

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

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

fn main() {
    let mut sequencer = Sequencer::default();
    sequencer.new_seq(vec![Wait(5usize), Print("Done waiting".to_string())]);
    while sequencer.is_active() {
        // Activate next nodes ready for processing
        sequencer.drain_queue(|_key, action| {});
        // Process active nodes. Returning true means the node was finishes.
        sequencer.for_each_active(|_key, item| item.tick());
    }
}

Check examples dir for complete examples.

Features to add:

  • More ergonomic methods for creating graphs, especially ones with parallel execution
  • Optional serde support
  • Visual debugging of the graphs
  • Visual editting of the graphs
  • Methods for garbage collecting completed nodes

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages