bevy_system_graph
This crate provides the utilities for creating strictly ordered execution graphs of systems for the Bevy game engine.
Bevy Version Supported
Bevy Version | bevy_system_graph |
---|---|
0.8 | 0.3 |
0.7 | 0.2 |
0.6 | 0.1 |
Starting a Graph
To start building a system graph, one or more systems must be added to the graph as root nodes. Root systems have no dependencies within the graph.
let graph = new;
// Create a root system for the graph.
let root_a = graph.root;
// Graphs can have multiple root nodes.
let root_b = graph.root;
let root_c = graph.root;
Using SystemLabels
Systems can still use labels to establish the ordering of systems relative to other systems outside of the graph.
let graph = new;
let root_a = graph.root;
Conversion into SystemSet
To ease adding all of the graph's systems into a Schedule
, both
SystemGraph
and SystemGraphNode
implement Into<SystemSet>
.
let graph = new;
let root_a = graph.root;
// Convert into a SystemSet
let system_set: SystemSet = graph.into;
Sequential Execution
Graph nodes can be sequentially chained via SystemGraphNode::then
. This
creates a new node from a system and adds a "after" dependency on the original
system.
let graph = new;
graph
.root
.then
.then;
// Convert into a SystemSet
let system_set: SystemSet = graph.into;
Fan Out
SystemGraphNode::fork
can be used to fan out into multiple branches. All fanned out systems will not execute
until the original has finished, but do not have a mutual dependency on each other.
let graph = new;
// Fork out from one original node.
// sys_b, sys_c, and sys_d will only start when sys_a finishes.
let = graph.root
.fork;
// Alternatively, calling "then" repeatedly achieves the same thing.
let e = d.then;
let f = d.then;
// Convert into a SystemSet
let system_set: SystemSet = graph.into;
Fan In
A graph node can wait on multiple systems before running via SystemJoin::join
.
The system will not run until all prior systems are finished.
let graph = new;
let start_a = graph.root;
let start_b = graph.root;
let start_c = graph.root;
.join
.then;
// Convert into a SystemSet
let system_set: SystemSet = graph.into;
Fan Out into Fan In
The types used to implement fork
and join
are composable.
let graph = new;
graph.root
.fork
.join
.then;
// Convert into a SystemSet
let system_set: SystemSet = graph.into;
Cloning
Individual [graph nodes] are backed by a Rc
, so cloning it will still
point to the same logical underlying graph.