summaryrefslogtreecommitdiff
path: root/ecs/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r--ecs/src/lib.rs49
1 files changed, 20 insertions, 29 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index c93781d..e568fb8 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -13,6 +13,7 @@ use crate::actions::Action;
use crate::component::{Component, Sequence as ComponentSequence};
use crate::event::{Event, Id as EventId, Ids, Sequence as EventSequence};
use crate::lock::Lock;
+use crate::sole::Sole;
use crate::system::{System, TypeErased as TypeErasedSystem};
use crate::type_name::TypeName;
@@ -21,6 +22,7 @@ pub mod component;
pub mod event;
pub mod lock;
pub mod query;
+pub mod sole;
pub mod system;
pub mod tuple;
pub mod type_name;
@@ -89,18 +91,15 @@ impl World
});
}
- /// Adds a single component. This component will be globally shared.
+ /// Adds a globally shared singleton value.
///
/// # Errors
- /// Returns `Err` if this component has already been added as a single component.
- pub fn add_single_component<SingleComponent>(
- &mut self,
- single_component: SingleComponent,
- ) -> Result<(), SingleComponentAlreadyExistsError>
+ /// Returns `Err` if this [`Sole`] has already been added.
+ pub fn add_sole<SoleT>(&mut self, sole: SoleT) -> Result<(), SoleAlreadyExistsError>
where
- SingleComponent: Component,
+ SoleT: Sole,
{
- self.data.single_component_storage.insert(single_component)
+ self.data.sole_storage.insert(sole)
}
pub fn register_system<'this, EventT, SystemImpl>(
@@ -227,7 +226,7 @@ pub struct WorldData
{
events: HashMap<EventId, Vec<usize>>,
component_storage: Arc<Lock<ComponentStorage>>,
- single_component_storage: SingleComponentStorage,
+ sole_storage: SoleStorage,
action_queue: Arc<Lock<ActionQueue>>,
}
@@ -348,39 +347,31 @@ impl Drop for ComponentStorage
}
#[derive(Debug, thiserror::Error)]
-#[error("Single component {0} already exists")]
-pub struct SingleComponentAlreadyExistsError(pub &'static str);
+#[error("Sole {0} already exists")]
+pub struct SoleAlreadyExistsError(pub &'static str);
#[derive(Debug, Default)]
-struct SingleComponentStorage
+struct SoleStorage
{
- storage: HashMap<TypeId, Lock<Box<dyn Component>>>,
+ storage: HashMap<TypeId, Lock<Box<dyn Sole>>>,
}
-impl SingleComponentStorage
+impl SoleStorage
{
- fn get<SingleComponent: Component>(&self) -> Option<&Lock<Box<dyn Component>>>
+ fn get<SoleT: Sole>(&self) -> Option<&Lock<Box<dyn Sole>>>
{
- self.storage.get(&TypeId::of::<SingleComponent>())
+ self.storage.get(&TypeId::of::<SoleT>())
}
- fn insert<SingleComponent: Component>(
- &mut self,
- single_component: SingleComponent,
- ) -> Result<(), SingleComponentAlreadyExistsError>
+ fn insert<SoleT: Sole>(&mut self, sole: SoleT) -> Result<(), SoleAlreadyExistsError>
{
- let single_component_type_id = TypeId::of::<SingleComponent>();
+ let sole_type_id = TypeId::of::<SoleT>();
- if self.storage.contains_key(&single_component_type_id) {
- return Err(SingleComponentAlreadyExistsError(type_name::<
- SingleComponent,
- >()));
+ if self.storage.contains_key(&sole_type_id) {
+ return Err(SoleAlreadyExistsError(type_name::<SoleT>()));
}
- self.storage.insert(
- single_component_type_id,
- Lock::new(Box::new(single_component)),
- );
+ self.storage.insert(sole_type_id, Lock::new(Box::new(sole)));
Ok(())
}