A Petri net plugin for Bevy Engine. 🍾
About
petnat will equip you with Petri nets to use in your Bevy projects.
It's a powerful way to model states, processes, resources, and more.
This is a very experimental project, and actual Bevy integration is unavailable yet. Feedback and thoughts are welcome!
Rough idea
- Model something using places and transitions.
- Define a
PetriNet<NetId>resource. - Add a
Token<NetId>component to an entity. - Mark places with the
Tokenaccording to the context. - Transitions will be scheduled or triggered with Events (needs experimenting).
- Implement game logic based on the current marking of the
Token. - Hopefully add static analysis on the net somehow via Rust's type system?
Example
Here is an example of how Petri nets are defined and used.
// impl NetId
// impl Place<Choice>
// impl Trans<Choice>
/// Two transitions sharing a preset place (P1).
/// When one of them fires, the other ceases to be enabled.
///
/// ## Before (asterisks denote the current marking):
///
/// (P0)* --> |T0| -\
/// (P1)* -< >-> (P3)
/// (P2)* --> |T1| -/
///
/// ## After T0 fires:
///
/// (P0) --> |T0| -\
/// (P1) -< >-> (P3)*
/// (P2)* --> |T1| -/