summaryrefslogtreecommitdiff
path: root/ecs/src/component.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-02-21 23:54:37 +0100
committerHampusM <hampus@hampusmat.com>2024-02-22 19:27:52 +0100
commit9f65dba3afd4e8f20881914fc86fa997cb64a13d (patch)
treed760f8f478af6591648ef3f53d4e0cb34ee76908 /ecs/src/component.rs
parentb0ef7f2cf8787c5732e0eb5554161ad75179a4b3 (diff)
feat(ecs): add support for system local components
Diffstat (limited to 'ecs/src/component.rs')
-rw-r--r--ecs/src/component.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/ecs/src/component.rs b/ecs/src/component.rs
index 4829050..8119e93 100644
--- a/ecs/src/component.rs
+++ b/ecs/src/component.rs
@@ -1,5 +1,6 @@
use std::any::{Any, TypeId};
use std::fmt::Debug;
+use std::ops::{Deref, DerefMut};
use seq_macro::seq;
@@ -112,3 +113,36 @@ macro_rules! inner {
seq!(C in 0..=64 {
inner!(C);
});
+
+/// Holds a component which is local to a single system.
+#[derive(Debug)]
+pub struct Local<'world, Value>
+{
+ value: &'world mut Value,
+}
+
+impl<'world, Value> Local<'world, Value>
+{
+ pub(crate) fn new(value: &'world mut Value) -> Self
+ {
+ Self { value }
+ }
+}
+
+impl<'world, Value> Deref for Local<'world, Value>
+{
+ type Target = Value;
+
+ fn deref(&self) -> &Self::Target
+ {
+ self.value
+ }
+}
+
+impl<'world, Value> DerefMut for Local<'world, Value>
+{
+ fn deref_mut(&mut self) -> &mut Self::Target
+ {
+ &mut self.value
+ }
+}