Skip to content

Commit

Permalink
add method for systems
Browse files Browse the repository at this point in the history
  • Loading branch information
DynamicGoose committed Oct 25, 2024
1 parent 0bf6210 commit aa990b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "magma_ecs"
version = "0.2.0-alpha.1"
version = "0.2.0-alpha.2"
edition = "2021"
license = "MIT"
description = "Entity-Component-System for the Magma3D game engine"
Expand Down
19 changes: 19 additions & 0 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ impl Systems {
self
}

/// Add a system
pub fn add(
&mut self,
run: fn(&World),
name: &'static str,
deps: &'static [&'static str],
) -> &mut Self {
self.0.push(System::new(run, name, deps));
self
}

/// Build a [`Dispatcher`] from the [`Systems`] to be run on the [`World`].
pub fn build_dispatcher(self) -> Dispatcher {
Dispatcher::from_systems(self)
Expand All @@ -63,6 +74,14 @@ mod tests {
assert_eq!(systems.0[1].name, "system_2");
}

#[test]
fn add_systems() {
let mut systems = Systems::new();
systems
.add(system_1, "system_1", &[])
.add(system_2, "system_2", &["system_1"]);
}

#[test]
fn build_dispatcher() {
let systems = Systems::new().with(system_1, "system_1", &[]).with(
Expand Down

0 comments on commit aa990b8

Please sign in to comment.