summaryrefslogtreecommitdiff
path: root/ecs/src/component.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/component.rs')
-rw-r--r--ecs/src/component.rs118
1 files changed, 1 insertions, 117 deletions
diff --git a/ecs/src/component.rs b/ecs/src/component.rs
index f4c29ae..49265b3 100644
--- a/ecs/src/component.rs
+++ b/ecs/src/component.rs
@@ -51,21 +51,6 @@ pub trait Component: SystemInput + Any
/// Returns the component UID of a component event for this component.
fn get_event_uid(&self, event_kind: ComponentEventKind) -> Uid;
-
- /// Returns whether the component `self` is optional.
- fn self_is_optional(&self) -> bool
- {
- false
- }
-
- /// Returns whether this component is optional.
- #[must_use]
- fn is_optional() -> bool
- where
- Self: Sized,
- {
- false
- }
}
impl dyn Component
@@ -94,46 +79,6 @@ impl Debug for dyn Component
}
}
-impl<ComponentT> Component for Option<ComponentT>
-where
- ComponentT: Component,
- for<'a> Option<ComponentT::Handle<'a>>: HandleFromEntityComponentRef<'a>,
- for<'a> Option<ComponentT::HandleMut<'a>>: HandleFromEntityComponentRef<'a>,
-{
- type Component = ComponentT;
- type Handle<'component> = Option<ComponentT::Handle<'component>>;
- type HandleMut<'component> = Option<ComponentT::HandleMut<'component>>;
-
- fn id() -> Uid
- {
- ComponentT::id()
- }
-
- fn name(&self) -> &'static str
- {
- type_name::<Self>()
- }
-
- fn get_event_uid(&self, event_kind: ComponentEventKind) -> Uid
- {
- match event_kind {
- ComponentEventKind::Removed => ComponentRemovedEvent::<Self>::id(),
- }
- }
-
- fn self_is_optional(&self) -> bool
- {
- true
- }
-
- fn is_optional() -> bool
- {
- true
- }
-}
-
-impl<ComponentT> SystemInput for Option<ComponentT> where ComponentT: Component {}
-
/// A sequence of components.
pub trait Sequence
{
@@ -180,24 +125,14 @@ where
pub struct Metadata
{
pub id: Uid,
- pub is_optional: bool,
}
impl Metadata
{
#[must_use]
- pub fn new_non_optional(id: Uid) -> Self
- {
- Self { id, is_optional: false }
- }
-
- #[must_use]
pub fn of<ComponentT: Component>() -> Self
{
- Self {
- id: ComponentT::id(),
- is_optional: ComponentT::is_optional(),
- }
+ Self { id: ComponentT::id() }
}
}
@@ -257,31 +192,6 @@ impl<'comp, ComponentT: Component> HandleFromEntityComponentRef<'comp>
}
}
-impl<'comp, ComponentT> HandleFromEntityComponentRef<'comp>
- for Option<Handle<'comp, ComponentT>>
-where
- ComponentT: Component,
-{
- type Error = HandleError;
-
- fn from_entity_component_ref(
- entity_component_ref: Option<EntityComponentRef<'comp>>,
- _world: &'comp World,
- ) -> Result<Self, Self::Error>
- {
- entity_component_ref
- .map(|entity_comp| {
- Ok(Handle::new(
- entity_comp
- .component()
- .read_nonblock()
- .map_err(AcquireComponentLockFailed)?,
- ))
- })
- .transpose()
- }
-}
-
impl<ComponentT: Component> Deref for Handle<'_, ComponentT>
{
type Target = ComponentT;
@@ -337,31 +247,6 @@ impl<'comp, ComponentT: Component> HandleFromEntityComponentRef<'comp>
}
}
-impl<'comp, ComponentT> HandleFromEntityComponentRef<'comp>
- for Option<HandleMut<'comp, ComponentT>>
-where
- ComponentT: Component,
-{
- type Error = HandleError;
-
- fn from_entity_component_ref(
- entity_component_ref: Option<EntityComponentRef<'comp>>,
- _world: &'comp World,
- ) -> Result<Self, Self::Error>
- {
- entity_component_ref
- .map(|entity_comp| {
- Ok(HandleMut::new(
- entity_comp
- .component()
- .write_nonblock()
- .map_err(AcquireComponentLockFailed)?,
- ))
- })
- .transpose()
- }
-}
-
impl<ComponentT: Component> Deref for HandleMut<'_, ComponentT>
{
type Target = ComponentT;
@@ -422,7 +307,6 @@ macro_rules! inner {
#(
Metadata {
id: IntoComp~I::Component::id(),
- is_optional: IntoComp~I::Component::is_optional(),
},
)*
]