summaryrefslogtreecommitdiff
path: root/ecs/src
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src')
-rw-r--r--ecs/src/lib.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index 5b8942b..f824ebc 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -22,13 +22,7 @@ pub struct World<Event>
{
systems: Vec<Box<dyn AnySystem>>,
events: HashMap<Event, Vec<usize>>,
- extra: WorldExtra,
-}
-
-#[derive(Debug)]
-struct WorldExtra
-{
- entities: Vec<Entity>,
+ component_storage: ComponentStorage,
}
impl<Event> World<Event>
@@ -38,7 +32,7 @@ impl<Event> World<Event>
{
Self {
systems: Vec::new(),
- extra: WorldExtra { entities: Vec::new() },
+ component_storage: ComponentStorage { entities: Vec::new() },
events: HashMap::new(),
}
}
@@ -47,7 +41,7 @@ impl<Event> World<Event>
where
Comps: ComponentSequence,
{
- self.extra
+ self.component_storage
.entities
.push(Entity { components: components.into_vec() });
}
@@ -81,7 +75,7 @@ impl<Event> World<Event>
for system_index in system_indices {
let system = self.systems.get_mut(system_index).unwrap();
- system.call(&mut self.extra);
+ system.call(&mut self.component_storage);
}
}
@@ -89,7 +83,7 @@ impl<Event> World<Event>
where
Comps: ComponentSequence,
{
- Query::new(&mut self.extra)
+ Query::new(&mut self.component_storage)
}
}
@@ -105,16 +99,16 @@ pub type System<Comps> = fn(Query<Comps>);
trait AnySystem
{
- fn call(&self, world: &mut WorldExtra);
+ fn call(&self, component_storage: &mut ComponentStorage);
}
impl<Comps> AnySystem for System<Comps>
where
Comps: ComponentSequence,
{
- fn call(&self, world: &mut WorldExtra)
+ fn call(&self, component_storage: &mut ComponentStorage)
{
- self(Query::new(world));
+ self(Query::new(component_storage));
}
}
@@ -129,15 +123,18 @@ impl Debug for dyn AnySystem
#[derive(Debug)]
pub struct Query<'world, Comps>
{
- world: &'world mut WorldExtra,
+ component_storage: &'world mut ComponentStorage,
comps_pd: PhantomData<Comps>,
}
impl<'world, Comps> Query<'world, Comps>
{
- fn new(world: &'world mut WorldExtra) -> Self
+ fn new(component_storage: &'world mut ComponentStorage) -> Self
{
- Self { world, comps_pd: PhantomData }
+ Self {
+ component_storage,
+ comps_pd: PhantomData,
+ }
}
}
@@ -148,7 +145,7 @@ where
pub fn iter_mut(&mut self) -> QueryComponentIter<Comps>
{
QueryComponentIter {
- entity_iter: self.world.entities.iter_mut(),
+ entity_iter: self.component_storage.entities.iter_mut(),
component_type_ids: Comps::type_ids(),
comps_pd: PhantomData,
}
@@ -192,3 +189,9 @@ where
Some(Comps::from_components(&mut entity.components))
}
}
+
+#[derive(Debug)]
+pub struct ComponentStorage
+{
+ entities: Vec<Entity>,
+}