diff options
author | HampusM <hampus@hampusmat.com> | 2024-02-16 19:58:53 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-02-18 18:23:03 +0100 |
commit | de5c3ff1320ea0f0452afde4c1f42676d9eeab52 (patch) | |
tree | 5394c42d76301f68526816552689a0beeb2ffdfb /ecs/examples/simple.rs | |
parent | 12f73be1bf0a7dd7d67bab2eb44d0f0629d37028 (diff) |
feat: add entity component system library
Diffstat (limited to 'ecs/examples/simple.rs')
-rw-r--r-- | ecs/examples/simple.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ecs/examples/simple.rs b/ecs/examples/simple.rs new file mode 100644 index 0000000..b58d2ba --- /dev/null +++ b/ecs/examples/simple.rs @@ -0,0 +1,32 @@ +use ecs::{Query, World}; + +struct SomeData +{ + num: u64, +} + +fn say_hello(mut query: Query<(SomeData, String)>) +{ + for (data, text) in query.iter_mut() { + println!("Hello {}: {}", text, data.num); + } +} + +#[derive(Debug, PartialEq, Eq, Hash)] +enum Event +{ + Start, +} + +fn main() +{ + let mut world = World::<Event>::new(); + + world.register_system(Event::Start, say_hello); + + world.create_entity((SomeData { num: 987_654 }, "Yoo".to_string())); + + world.create_entity((SomeData { num: 345 }, "Haha".to_string())); + + world.emit(&Event::Start); +} |