summaryrefslogtreecommitdiff
path: root/ecs/examples
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-04-10 20:37:53 +0200
committerHampusM <hampus@hampusmat.com>2024-04-10 20:38:47 +0200
commitca51244e9d462c661d29dc60ce5bf6f9056c569b (patch)
treee5ee42ef550cc9a10feab918fa54fe342bb8dfed /ecs/examples
parentc70e06c6d879208eb2822f6207ea7b29d47c2087 (diff)
chore(ecs): make shared singletons not components
Diffstat (limited to 'ecs/examples')
-rw-r--r--ecs/examples/with_single.rs59
1 files changed, 0 insertions, 59 deletions
diff --git a/ecs/examples/with_single.rs b/ecs/examples/with_single.rs
deleted file mode 100644
index d222f76..0000000
--- a/ecs/examples/with_single.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-use ecs::component::single::Single;
-use ecs::event::Event;
-use ecs::{Component, Query, World};
-
-#[derive(Component)]
-struct Ammo
-{
- ammo_left: u32,
-}
-
-#[derive(Component, Default)]
-struct AmmoCounter
-{
- counter: u32,
-}
-
-fn count_ammo(query: Query<(Ammo,)>, mut ammo_counter: Single<AmmoCounter>)
-{
- for (ammo,) in &query {
- println!("Found {} ammo", ammo.ammo_left);
-
- ammo_counter.counter += ammo.ammo_left;
- }
-}
-
-fn print_total_ammo_count(ammo_counter: Single<AmmoCounter>)
-{
- println!("Total ammo count: {}", ammo_counter.counter);
-
- assert_eq!(ammo_counter.counter, 19);
-}
-
-#[derive(Debug)]
-struct EventA;
-
-impl Event for EventA {}
-
-#[derive(Debug)]
-struct EventB;
-
-impl Event for EventB {}
-
-fn main()
-{
- let mut world = World::new();
-
- world.register_system(EventA, count_ammo);
- world.register_system(EventB, print_total_ammo_count);
-
- world.create_entity((Ammo { ammo_left: 4 },));
- world.create_entity((Ammo { ammo_left: 7 },));
- world.create_entity((Ammo { ammo_left: 8 },));
-
- world.add_single_component(AmmoCounter::default()).unwrap();
-
- world.emit(EventA);
-
- world.emit(EventB);
-}