summaryrefslogtreecommitdiff
path: root/ecs/src/relationship.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-08-16 20:13:22 +0200
committerHampusM <hampus@hampusmat.com>2024-08-16 20:13:22 +0200
commit7d218b2525f90dfedcae02f3b3d0d2f7b9c99bd2 (patch)
treebc9523b82d138a7048ff583dd75e0a8c26fe5e6b /ecs/src/relationship.rs
parent0f7811f3cba24c8a5927d5bcdfb30dd94de87102 (diff)
feat(ecs): make relationships creatable without reference to world
Diffstat (limited to 'ecs/src/relationship.rs')
-rw-r--r--ecs/src/relationship.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/ecs/src/relationship.rs b/ecs/src/relationship.rs
index 82c9e70..fa3f761 100644
--- a/ecs/src/relationship.rs
+++ b/ecs/src/relationship.rs
@@ -1,6 +1,5 @@
use std::any::{type_name, Any};
use std::marker::PhantomData;
-use std::sync::{Arc, Weak};
use crate::component::storage::Storage as ComponentStorage;
use crate::component::{
@@ -11,7 +10,7 @@ use crate::component::{
Metadata as ComponentMetadata,
};
use crate::entity::Uid as EntityUid;
-use crate::lock::{Lock, ReadGuard};
+use crate::lock::ReadGuard;
use crate::system::{ComponentRefMut, Input as SystemInput};
use crate::type_name::TypeName;
use crate::World;
@@ -20,7 +19,6 @@ use crate::World;
pub struct Relationship<Kind, ComponentT: Component>
{
entity_uid: EntityUid,
- component_storage: Weak<Lock<ComponentStorage>>,
_pd: PhantomData<(Kind, ComponentT)>,
}
@@ -28,13 +26,9 @@ impl<Kind, ComponentT> Relationship<Kind, ComponentT>
where
ComponentT: Component,
{
- pub fn new(world: &World, entity_uid: EntityUid) -> Self
+ pub fn new(entity_uid: EntityUid) -> Self
{
- Self {
- entity_uid,
- component_storage: Arc::downgrade(&world.data.component_storage),
- _pd: PhantomData,
- }
+ Self { entity_uid, _pd: PhantomData }
}
}
@@ -86,7 +80,6 @@ where
{
component_storage_lock: ReadGuard<'static, ComponentStorage>,
relationship_comp: ComponentRefMut<'rel_comp, Relationship<Kind, ComponentT>>,
- _component_storage: Arc<Lock<ComponentStorage>>,
}
impl<'rel_comp, Kind, ComponentT> ComponentFromOptional<'rel_comp>
@@ -98,19 +91,18 @@ where
optional_component: Option<
crate::lock::WriteGuard<'rel_comp, Box<dyn Component>>,
>,
+ world: &'rel_comp World,
) -> Self
{
let relationship_comp =
ComponentRefMut::<Relationship<Kind, ComponentT>>::from_optional_component(
optional_component,
+ world,
);
- let component_storage = relationship_comp
+ let component_storage_lock = world
+ .data
.component_storage
- .upgrade()
- .expect("World has been dropped");
-
- let component_storage_lock = component_storage
.read_nonblock()
.expect("Failed to aquire read-only component storage lock");
@@ -119,7 +111,6 @@ where
// SAFETY: The component lock is not used for longer than the original
// lifetime
component_storage_lock: unsafe { component_storage_lock.upgrade_lifetime() },
- _component_storage: component_storage,
}
}
}