Skip to content

Commit

Permalink
remove startup. update updates the world once
Browse files Browse the repository at this point in the history
  • Loading branch information
DynamicGoose committed Dec 5, 2023
1 parent dca2118 commit de25a14
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
23 changes: 1 addition & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl World {
This takes a `Vec` of references to functions that take a reference to `World` as well as a `Vec` of references to functions that take a mutable reference to `World`.
It runs all of the supplied functions once on the `World`.
*/
pub fn startup(
pub fn update(
&mut self,
systems_ref: Vec<&dyn Fn(&Self)>,
systems_mut: Vec<&dyn Fn(&mut Self)>,
Expand All @@ -139,27 +139,6 @@ impl World {
system(self);
}
}

/**
This takes a `Vec` of references to functions that take a reference to `World` as well as a `Vec` of references to functions that take a mutable reference to `World`.
It runs all of the supplied functions once on each update.
It also takes an update condition, which must return `true` for the update loop to run.
*/
pub fn update(
&mut self,
update_condition: &dyn Fn(&Self) -> bool,
systems_ref: Vec<&dyn Fn(&Self)>,
systems_mut: Vec<&dyn Fn(&mut Self)>,
) {
while update_condition(self) {
for system in &systems_ref {
system(self);
}
for system in &systems_mut {
system(self);
}
}
}
}

#[cfg(test)]
Expand Down
16 changes: 1 addition & 15 deletions tests/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,11 @@ use magma_ecs::World;
fn startup() {
let mut world = World::new();
world.register_component::<u32>();
world.startup(vec![], vec![&create_u32_entity]);
world.update(vec![], vec![&create_u32_entity]);
let query = world.query().with_component::<u32>().unwrap().run();
assert_eq!(query.indexes.len(), 1);
}

#[test]
fn update() {
let mut world = World::new();
world.register_component::<u32>();
world.update(&break_update_loop, vec![], vec![&create_u32_entity]);
let query = world.query().with_component::<u32>().unwrap().run();
assert_eq!(query.indexes.len(), 2);
}

fn break_update_loop(world: &World) -> bool {
let query = world.query().with_component::<u32>().unwrap().run();
query.indexes.len() != 2
}

fn create_u32_entity(world: &mut World) {
world.spawn().with_component(10_u32).unwrap();
}

0 comments on commit de25a14

Please sign in to comment.