From 9f65dba3afd4e8f20881914fc86fa997cb64a13d Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 21 Feb 2024 23:54:37 +0100 Subject: feat(ecs): add support for system local components --- ecs/src/component.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'ecs/src/component.rs') 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 + } +} -- cgit v1.2.3-18-g5258