use ecs::component::local::Local; use ecs::event::Event; use ecs::system::{Into, System}; use ecs::{Component, Query, World}; #[derive(Component)] struct SomeData { num: u64, } #[derive(Component)] struct Name { name: String, } #[derive(Component)] struct SayHelloState { cnt: usize, } fn say_hello(query: Query<(SomeData,)>, mut state: Local) { for (data,) in &query { println!("Hello there. Count {}: {}", state.cnt, data.num); state.cnt += 1; } } fn say_whats_up(query: Query<(SomeData, Name)>, mut state: Local) { for (data, name) in &query { println!( "Whats up, {}. Number is {}. Count {}", name.name, data.num, state.cnt ); state.cnt += 1; } } #[derive(Debug)] struct Update; impl Event for Update {} fn main() { let mut world = World::new(); world.register_system( Update, say_hello .into_system() .initialize((SayHelloState { cnt: 0 },)), ); world.register_system( Update, say_whats_up .into_system() .initialize((SayHelloState { cnt: 0 },)), ); world.create_entity((SomeData { num: 987_654 }, Name { name: "Bob".to_string() })); world.create_entity((SomeData { num: 345 },)); world.emit(Update); println!("Haha"); world.emit(Update); }