summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-06-29 18:45:45 +0200
committerHampusM <hampus@hampusmat.com>2024-06-29 18:45:45 +0200
commit3cdef8ac2a96a91c9ab62a7ca49c128516c44efa (patch)
treeb5d617f4c6535152e8f58150b95616a9f94b6662
parent93f9f840da11b82c8a13f31f0ba5db8b10e4e9ad (diff)
chore(ecs): remove weak queries
-rw-r--r--ecs/src/query.rs77
1 files changed, 1 insertions, 76 deletions
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<Lock<ComponentStorage>>,
_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<Comps, OptionsT>
- {
- WeakRef {
- component_storage: self.component_storage_lock.clone(),
- comps_pd: PhantomData,
- }
- }
-
pub(crate) fn new(component_storage: &'world Arc<Lock<ComponentStorage>>) -> 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<Comps, OptionsT>
-where
- Comps: ComponentSequence,
-{
- component_storage: Weak<Lock<ComponentStorage>>,
- comps_pd: PhantomData<(Comps, OptionsT)>,
-}
-
-impl<Comps, OptionsT> WeakRef<Comps, OptionsT>
-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<Ref<'_, Comps, OptionsT>>
- {
- Some(Ref {
- component_storage: self.component_storage.upgrade()?,
- _pd: PhantomData,
- })
- }
-}
-
-impl<Comps, OptionsT> Clone for WeakRef<Comps, OptionsT>
-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<Lock<ComponentStorage>>,
- _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<EntityComponent>];
type ComponentIterFilterFn = for<'a, 'b> fn(&'a &'b Vec<EntityComponent>) -> bool;