summaryrefslogtreecommitdiff
path: root/ecs/src/system.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/system.rs')
-rw-r--r--ecs/src/system.rs89
1 files changed, 15 insertions, 74 deletions
diff --git a/ecs/src/system.rs b/ecs/src/system.rs
index 40eba8d..fdf87f8 100644
--- a/ecs/src/system.rs
+++ b/ecs/src/system.rs
@@ -7,12 +7,7 @@ use std::ops::{Deref, DerefMut};
use ecs_macros::Component;
use seq_macro::seq;
-use crate::component::{
- Component,
- FromLockedOptional as FromLockedOptionalComponent,
- FromOptional as FromOptionalComponent,
- FromOptionalMut as FromOptionalMutComponent,
-};
+use crate::component::{Component, FromLockedOptional as FromLockedOptionalComponent};
use crate::lock::{
Error as LockError,
Lock,
@@ -221,49 +216,22 @@ impl<'a, ComponentT: Component> ComponentRefMut<'a, ComponentT>
}
}
-impl<'component, ComponentT: Component> FromOptionalMutComponent<'component>
+impl<'component, ComponentT: Component> FromLockedOptionalComponent<'component>
for ComponentRefMut<'component, ComponentT>
{
- fn from_optional_mut_component(
- inner: Option<WriteGuard<'component, Box<dyn Component>>>,
+ fn from_locked_optional_component(
+ optional_component: Option<&'component crate::lock::Lock<Box<dyn Component>>>,
_world: &'component World,
- ) -> Self
+ ) -> Result<Self, LockError>
{
- Self::new(inner.unwrap_or_else(|| {
+ let component = optional_component.unwrap_or_else(|| {
panic!(
"Component {} was not found in entity",
type_name::<ComponentT>()
);
- }))
- }
-}
-
-impl<'component, ComponentT: Component> FromLockedOptionalComponent<'component>
- for ComponentRefMut<'component, ComponentT>
-{
- fn from_locked_optional_component(
- optional_component: Option<&'component crate::lock::Lock<Box<dyn Component>>>,
- world: &'component World,
- ) -> Result<Self, LockError>
- {
- Ok(Self::from_optional_mut_component(
- optional_component.map(Lock::write_nonblock).transpose()?,
- world,
- ))
- }
-}
+ });
-impl<'comp, ComponentT> FromOptionalMutComponent<'comp>
- for Option<ComponentRefMut<'comp, ComponentT>>
-where
- ComponentT: Component,
-{
- fn from_optional_mut_component(
- optional_component: Option<WriteGuard<'comp, Box<dyn Component>>>,
- _world: &'comp World,
- ) -> Self
- {
- optional_component.map(|component| ComponentRefMut::new(component))
+ Ok(Self::new(component.write_nonblock()?))
}
}
@@ -327,49 +295,22 @@ impl<'a, ComponentT: Component> ComponentRef<'a, ComponentT>
}
}
-impl<'component, ComponentT: Component> FromOptionalComponent<'component>
+impl<'component, ComponentT: Component> FromLockedOptionalComponent<'component>
for ComponentRef<'component, ComponentT>
{
- fn from_optional_component(
- inner: Option<ReadGuard<'component, Box<dyn Component>>>,
+ fn from_locked_optional_component(
+ optional_component: Option<&'component crate::lock::Lock<Box<dyn Component>>>,
_world: &'component World,
- ) -> Self
+ ) -> Result<Self, LockError>
{
- Self::new(inner.unwrap_or_else(|| {
+ let component = optional_component.unwrap_or_else(|| {
panic!(
"Component {} was not found in entity",
type_name::<ComponentT>()
);
- }))
- }
-}
-
-impl<'component, ComponentT: Component> FromLockedOptionalComponent<'component>
- for ComponentRef<'component, ComponentT>
-{
- fn from_locked_optional_component(
- optional_component: Option<&'component crate::lock::Lock<Box<dyn Component>>>,
- world: &'component World,
- ) -> Result<Self, LockError>
- {
- Ok(Self::from_optional_component(
- optional_component.map(Lock::read_nonblock).transpose()?,
- world,
- ))
- }
-}
+ });
-impl<'comp, ComponentT> FromOptionalComponent<'comp>
- for Option<ComponentRef<'comp, ComponentT>>
-where
- ComponentT: Component,
-{
- fn from_optional_component(
- optional_component: Option<ReadGuard<'comp, Box<dyn Component>>>,
- _world: &'comp World,
- ) -> Self
- {
- optional_component.map(|component| ComponentRef::new(component))
+ Ok(Self::new(component.read_nonblock()?))
}
}