summaryrefslogtreecommitdiff
path: root/ecs/examples
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/examples')
-rw-r--r--ecs/examples/event_loop.rs37
-rw-r--r--ecs/examples/extension.rs13
-rw-r--r--ecs/examples/multiple_queries.rs6
-rw-r--r--ecs/examples/optional_component.rs11
-rw-r--r--ecs/examples/relationship.rs6
-rw-r--r--ecs/examples/simple.rs6
-rw-r--r--ecs/examples/with_local.rs18
-rw-r--r--ecs/examples/with_sole.rs26
8 files changed, 49 insertions, 74 deletions
diff --git a/ecs/examples/event_loop.rs b/ecs/examples/event_loop.rs
index 8d8d84f..c9f7757 100644
--- a/ecs/examples/event_loop.rs
+++ b/ecs/examples/event_loop.rs
@@ -1,6 +1,7 @@
use ecs::actions::Actions;
-use ecs::event::Event;
-use ecs::{Component, Query, World};
+use ecs::phase::{Phase, UPDATE as UPDATE_PHASE};
+use ecs::relationship::{ChildOf, Relationship};
+use ecs::{static_entity, Component, Query, World};
#[derive(Component)]
struct Wool
@@ -64,28 +65,28 @@ fn age(query: Query<(Health, Name)>, mut actions: Actions)
}
}
-#[derive(Debug)]
-struct EventA;
+static_entity!(
+ SHEER_PHASE,
+ (Phase, <Relationship<ChildOf, Phase>>::new(*UPDATE_PHASE))
+);
-impl Event for EventA {}
+static_entity!(
+ FEED_PHASE,
+ (Phase, <Relationship<ChildOf, Phase>>::new(*SHEER_PHASE))
+);
-#[derive(Debug)]
-struct EventB;
-
-impl Event for EventB {}
-
-#[derive(Debug)]
-struct EventC;
-
-impl Event for EventC {}
+static_entity!(
+ AGE_PHASE,
+ (Phase, <Relationship<ChildOf, Phase>>::new(*FEED_PHASE))
+);
fn main()
{
let mut world = World::new();
- world.register_system(EventA, sheer);
- world.register_system(EventB, feed);
- world.register_system(EventC, age);
+ world.register_system(*SHEER_PHASE, sheer);
+ world.register_system(*FEED_PHASE, feed);
+ world.register_system(*AGE_PHASE, age);
world.create_entity((
Wool { remaining: 30 },
@@ -93,5 +94,5 @@ fn main()
Name { name: "Bessy" },
));
- world.event_loop::<(EventA, EventB, EventC)>();
+ world.start_loop();
}
diff --git a/ecs/examples/extension.rs b/ecs/examples/extension.rs
index 2022b05..ddde32c 100644
--- a/ecs/examples/extension.rs
+++ b/ecs/examples/extension.rs
@@ -1,6 +1,6 @@
use ecs::actions::Actions;
-use ecs::event::Event;
use ecs::extension::{Collector as ExtensionCollector, Extension};
+use ecs::phase::UPDATE as UPDATE_PHASE;
use ecs::{Component, Query, World};
#[derive(Debug, Component)]
@@ -19,11 +19,6 @@ enum EvilnessLevel
Medium,
}
-#[derive(Debug)]
-struct Update;
-
-impl Event for Update {}
-
fn spawn_enemies(
spawner_query: Query<(EnemySpawnSource, Position)>,
enemies_query: Query<(EvilnessLevel,)>,
@@ -57,7 +52,7 @@ impl Extension for EnemySpawningExtension
{
fn collect(self, mut collector: ExtensionCollector<'_>)
{
- collector.add_system(Update, spawn_enemies);
+ collector.add_system(*UPDATE_PHASE, spawn_enemies);
collector.add_entity((Position { x: 187, y: 30 }, EnemySpawnSource));
}
@@ -70,8 +65,6 @@ fn main()
world.add_extension(EnemySpawningExtension);
for _ in 0..7 {
- world.emit(Update);
-
- world.perform_queued_actions();
+ world.step();
}
}
diff --git a/ecs/examples/multiple_queries.rs b/ecs/examples/multiple_queries.rs
index 2736bce..1ae9d19 100644
--- a/ecs/examples/multiple_queries.rs
+++ b/ecs/examples/multiple_queries.rs
@@ -1,6 +1,6 @@
use std::fmt::Display;
-use ecs::event::start::Start as StartEvent;
+use ecs::phase::START as START_PHASE;
use ecs::{Component, Query, World};
#[derive(Component)]
@@ -61,7 +61,7 @@ fn main()
{
let mut world = World::new();
- world.register_system(StartEvent, do_attacks);
+ world.register_system(*START_PHASE, do_attacks);
world.create_entity((
Health { health: 100 },
@@ -81,5 +81,5 @@ fn main()
world.create_entity((AttackStrength::Strong,));
world.create_entity((AttackStrength::Weak,));
- world.emit(StartEvent);
+ world.step();
}
diff --git a/ecs/examples/optional_component.rs b/ecs/examples/optional_component.rs
index e47bf2e..bcc0c54 100644
--- a/ecs/examples/optional_component.rs
+++ b/ecs/examples/optional_component.rs
@@ -1,4 +1,4 @@
-use ecs::event::Event;
+use ecs::phase::UPDATE as UPDATE_PHASE;
use ecs::{Component, Query, World};
#[derive(Debug, Component)]
@@ -48,16 +48,11 @@ fn pet_cats(query: Query<(CatName, PettingCapacity, Option<Aggressivity>)>)
}
}
-#[derive(Debug)]
-struct PettingTime;
-
-impl Event for PettingTime {}
-
fn main()
{
let mut world = World::new();
- world.register_system(PettingTime, pet_cats);
+ world.register_system(*UPDATE_PHASE, pet_cats);
world.create_entity((
CatName { name: "Jasper".to_string() },
@@ -82,5 +77,5 @@ fn main()
Aggressivity::Low,
));
- world.emit(PettingTime);
+ world.step();
}
diff --git a/ecs/examples/relationship.rs b/ecs/examples/relationship.rs
index e8fb327..1b3d1de 100644
--- a/ecs/examples/relationship.rs
+++ b/ecs/examples/relationship.rs
@@ -1,4 +1,4 @@
-use ecs::event::start::Start as StartEvent;
+use ecs::phase::START as START_PHASE;
use ecs::relationship::Relationship;
use ecs::{Component, Query, World};
@@ -34,7 +34,7 @@ fn main()
{
let mut world = World::new();
- world.register_system(StartEvent, print_player_stats);
+ world.register_system(*START_PHASE, print_player_stats);
let sword_uid = world.create_entity((Sword { attack_strength: 17 },));
@@ -44,5 +44,5 @@ fn main()
Relationship::<Holding, Sword>::new(sword_uid),
));
- world.emit(StartEvent);
+ world.step();
}
diff --git a/ecs/examples/simple.rs b/ecs/examples/simple.rs
index 4057c84..6429035 100644
--- a/ecs/examples/simple.rs
+++ b/ecs/examples/simple.rs
@@ -1,4 +1,4 @@
-use ecs::event::start::Start as StartEvent;
+use ecs::phase::START as START_PHASE;
use ecs::{Component, Query, World};
#[derive(Component)]
@@ -24,7 +24,7 @@ fn main()
{
let mut world = World::new();
- world.register_system(StartEvent, say_hello);
+ world.register_system(*START_PHASE, say_hello);
world.create_entity((
SomeData { num: 987_654 },
@@ -38,5 +38,5 @@ fn main()
Greeting { greeting: "Good evening".to_string() },
));
- world.emit(StartEvent);
+ world.step();
}
diff --git a/ecs/examples/with_local.rs b/ecs/examples/with_local.rs
index 5890b90..0872dfc 100644
--- a/ecs/examples/with_local.rs
+++ b/ecs/examples/with_local.rs
@@ -1,5 +1,5 @@
use ecs::component::local::Local;
-use ecs::event::Event;
+use ecs::phase::UPDATE as UPDATE_PHASE;
use ecs::system::{Into, System};
use ecs::{Component, Query, World};
@@ -42,24 +42,19 @@ fn say_whats_up(query: Query<(SomeData, Name)>, mut state: Local<SayHelloState>)
}
}
-#[derive(Debug)]
-struct Update;
-
-impl Event for Update {}
-
fn main()
{
let mut world = World::new();
world.register_system(
- Update,
+ *UPDATE_PHASE,
say_hello
.into_system()
.initialize((SayHelloState { cnt: 0 },)),
);
world.register_system(
- Update,
+ *UPDATE_PHASE,
say_whats_up
.into_system()
.initialize((SayHelloState { cnt: 0 },)),
@@ -69,9 +64,6 @@ fn main()
world.create_entity((SomeData { num: 345 },));
- world.emit(Update);
-
- println!("Haha");
-
- world.emit(Update);
+ world.step();
+ world.step();
}
diff --git a/ecs/examples/with_sole.rs b/ecs/examples/with_sole.rs
index a387bea..47aa0b3 100644
--- a/ecs/examples/with_sole.rs
+++ b/ecs/examples/with_sole.rs
@@ -1,6 +1,7 @@
-use ecs::event::Event;
+use ecs::phase::{Phase, UPDATE as UPDATE_PHASE};
+use ecs::relationship::{ChildOf, Relationship};
use ecs::sole::Single;
-use ecs::{Component, Query, Sole, World};
+use ecs::{static_entity, Component, Query, Sole, World};
#[derive(Component)]
struct Ammo
@@ -30,22 +31,17 @@ fn print_total_ammo_count(ammo_counter: Single<AmmoCounter>)
assert_eq!(ammo_counter.counter, 19);
}
-#[derive(Debug)]
-struct EventA;
-
-impl Event for EventA {}
-
-#[derive(Debug)]
-struct EventB;
-
-impl Event for EventB {}
+static_entity!(
+ PRINT_AMMO_COUNT_PHASE,
+ (Phase, <Relationship<ChildOf, Phase>>::new(*UPDATE_PHASE))
+);
fn main()
{
let mut world = World::new();
- world.register_system(EventA, count_ammo);
- world.register_system(EventB, print_total_ammo_count);
+ world.register_system(*UPDATE_PHASE, count_ammo);
+ world.register_system(*PRINT_AMMO_COUNT_PHASE, print_total_ammo_count);
world.create_entity((Ammo { ammo_left: 4 },));
world.create_entity((Ammo { ammo_left: 7 },));
@@ -53,7 +49,5 @@ fn main()
world.add_sole(AmmoCounter::default()).unwrap();
- world.emit(EventA);
-
- world.emit(EventB);
+ world.step();
}