summaryrefslogtreecommitdiff
path: root/ecs/src
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src')
-rw-r--r--ecs/src/component.rs53
-rw-r--r--ecs/src/lib.rs2
2 files changed, 22 insertions, 33 deletions
diff --git a/ecs/src/component.rs b/ecs/src/component.rs
index 59b737e..70ce9ba 100644
--- a/ecs/src/component.rs
+++ b/ecs/src/component.rs
@@ -7,7 +7,7 @@ use seq_macro::seq;
use crate::system::{Input as SystemInput, Param as SystemParam, System};
use crate::ComponentStorage;
-pub trait Component: Any
+pub trait Component: SystemInput + Any
{
#[doc(hidden)]
fn as_any_mut(&mut self) -> &mut dyn Any;
@@ -16,19 +16,6 @@ pub trait Component: Any
fn as_any(&self) -> &dyn Any;
}
-impl<Value: Any> Component for Value
-{
- fn as_any_mut(&mut self) -> &mut dyn Any
- {
- self
- }
-
- fn as_any(&self) -> &dyn Any
- {
- self
- }
-}
-
impl dyn Component
{
pub fn downcast_mut<Real: 'static>(&mut self) -> Option<&mut Real>
@@ -117,27 +104,27 @@ seq!(C in 0..=64 {
/// Holds a component which is local to a single system.
#[derive(Debug)]
-pub struct Local<'world, Value: SystemInput>
+pub struct Local<'world, LocalComponent: Component>
{
- value: &'world mut Value,
+ local_component: &'world mut LocalComponent,
}
-impl<'world, Value> Local<'world, Value>
+impl<'world, LocalComponent> Local<'world, LocalComponent>
where
- Value: SystemInput,
+ LocalComponent: Component,
{
- fn new(value: &'world mut Value) -> Self
+ fn new(local_component: &'world mut LocalComponent) -> Self
{
- Self { value }
+ Self { local_component }
}
}
-unsafe impl<'world, Value: 'static> SystemParam<'world> for Local<'world, Value>
+unsafe impl<'world, LocalComponent> SystemParam<'world> for Local<'world, LocalComponent>
where
- Value: SystemInput,
+ LocalComponent: Component,
{
type Flags = ();
- type Input = Value;
+ type Input = LocalComponent;
fn initialize<SystemImpl>(system: &mut impl System<SystemImpl>, input: Self::Input)
{
@@ -150,7 +137,7 @@ where
) -> Self
{
let local_component = system
- .get_local_component_mut::<Value>()
+ .get_local_component_mut::<LocalComponent>()
.expect("Local component is uninitialized");
Self::new(local_component)
@@ -164,33 +151,33 @@ where
return true;
};
- TypeId::of::<Value>() != *other_type_id
+ TypeId::of::<LocalComponent>() != *other_type_id
}
fn get_comparable() -> Box<dyn Any>
{
- Box::new(TypeId::of::<Value>())
+ Box::new(TypeId::of::<LocalComponent>())
}
}
-impl<'world, Value> Deref for Local<'world, Value>
+impl<'world, LocalComponent> Deref for Local<'world, LocalComponent>
where
- Value: SystemInput,
+ LocalComponent: Component,
{
- type Target = Value;
+ type Target = LocalComponent;
fn deref(&self) -> &Self::Target
{
- self.value
+ self.local_component
}
}
-impl<'world, Value> DerefMut for Local<'world, Value>
+impl<'world, LocalComponent> DerefMut for Local<'world, LocalComponent>
where
- Value: SystemInput,
+ LocalComponent: Component,
{
fn deref_mut(&mut self) -> &mut Self::Target
{
- self.value
+ self.local_component
}
}
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index 84009e0..573aa41 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -18,6 +18,8 @@ use crate::system::{
pub mod component;
pub mod system;
+pub use ecs_macros::Component;
+
#[derive(Debug)]
struct Entity
{