From 3cdef8ac2a96a91c9ab62a7ca49c128516c44efa Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 29 Jun 2024 18:45:45 +0200 Subject: chore(ecs): remove weak queries --- ecs/src/query.rs | 77 +------------------------------------------------------- 1 file changed, 1 insertion(+), 76 deletions(-) (limited to 'ecs') diff --git a/ecs/src/query.rs b/ecs/src/query.rs index 79ad292..6b06e9a 100644 --- a/ecs/src/query.rs +++ b/ecs/src/query.rs @@ -2,7 +2,7 @@ use std::any::Any; use std::collections::HashSet; use std::iter::{Filter, Flatten, Map}; use std::marker::PhantomData; -use std::sync::{Arc, Weak}; +use std::sync::Arc; use crate::component::storage::{ Archetype, @@ -31,7 +31,6 @@ where Comps: ComponentSequence, { component_storage: ReadGuard<'world, ComponentStorage>, - component_storage_lock: Weak>, _pd: PhantomData<(Comps, OptionsT)>, } @@ -61,23 +60,12 @@ where } } - /// Returns a weak reference query to the same components. - #[must_use] - pub fn to_weak_ref(&self) -> WeakRef - { - WeakRef { - component_storage: self.component_storage_lock.clone(), - comps_pd: PhantomData, - } - } - pub(crate) fn new(component_storage: &'world Arc>) -> Self { Self { component_storage: component_storage .read_nonblock() .expect("Failed to acquire read-only component storage lock"), - component_storage_lock: Arc::downgrade(component_storage), _pd: PhantomData, } } @@ -167,69 +155,6 @@ where } } -/// A entity query containing a weak reference to the world. -#[derive(Debug)] -pub struct WeakRef -where - Comps: ComponentSequence, -{ - component_storage: Weak>, - comps_pd: PhantomData<(Comps, OptionsT)>, -} - -impl WeakRef -where - Comps: ComponentSequence, -{ - /// Returns a struct which can be used to retrieve a [`Query`]. - /// - /// Returns [`None`] if the [`World`] has been dropped. - #[must_use] - pub fn access(&self) -> Option> - { - Some(Ref { - component_storage: self.component_storage.upgrade()?, - _pd: PhantomData, - }) - } -} - -impl Clone for WeakRef -where - Comps: ComponentSequence, -{ - fn clone(&self) -> Self - { - Self { - component_storage: self.component_storage.clone(), - comps_pd: PhantomData, - } - } -} - -/// Intermediate between [`Query`] and [`WeakRefQuery`]. Contains a strong reference to -/// the world which is not allowed direct access to. -#[derive(Debug, Clone)] -pub struct Ref<'weak_ref, Comps, OptionsT> -where - Comps: ComponentSequence, -{ - component_storage: Arc>, - _pd: PhantomData<(&'weak_ref Comps, OptionsT)>, -} - -impl<'weak_ref, Comps, OptionsT> Ref<'weak_ref, Comps, OptionsT> -where - Comps: ComponentSequence, - OptionsT: Options, -{ - #[must_use] - pub fn to_query(&self) -> Query<'_, Comps, OptionsT> - { - Query::new(&self.component_storage) - } -} - type ComponentIterMapFn = for<'a> fn(&'a Archetype) -> &'a [Vec]; type ComponentIterFilterFn = for<'a, 'b> fn(&'a &'b Vec) -> bool; -- cgit v1.2.3-18-g5258