summaryrefslogtreecommitdiff
path: root/ecs/src
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src')
-rw-r--r--ecs/src/actions.rs68
-rw-r--r--ecs/src/sole.rs68
2 files changed, 3 insertions, 133 deletions
diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs
index 549e341..3d8afe6 100644
--- a/ecs/src/actions.rs
+++ b/ecs/src/actions.rs
@@ -1,7 +1,3 @@
-use std::any::type_name;
-use std::marker::PhantomData;
-use std::rc::{Rc, Weak};
-
use crate::component::{Parts as ComponentParts, Sequence as ComponentSequence};
use crate::event::component::Removed;
use crate::pair::Pair;
@@ -151,28 +147,6 @@ impl Actions<'_>
{
self.action_queue.push(Action::Stop);
}
-
- /// Returns a struct which holds a weak reference to the [`World`] that `Actions`
- /// references and that can be used to aquire a new `Actions` instance if the
- /// referenced [`World`] is still alive.
- ///
- /// # Panics
- /// This function will panic if `self` was retrieved from a [`WeakRef`].
- #[must_use]
- pub fn to_weak_ref(&self) -> WeakRef
- {
- let world = self.world.unwrap_or_else(|| {
- panic!(
- "This function cannot be called if the {} was retrieved from a {}",
- type_name::<Self>(),
- type_name::<WeakRef>()
- )
- });
-
- WeakRef {
- action_queue: Rc::downgrade(&world.data.action_queue),
- }
- }
}
impl<'world> SystemParam<'world> for Actions<'world>
@@ -188,48 +162,6 @@ impl<'world> SystemParam<'world> for Actions<'world>
}
}
-#[derive(Debug, Clone)]
-pub struct WeakRef
-{
- action_queue: Weak<ActionQueue>,
-}
-
-impl WeakRef
-{
- /// Returns a struct which can be used to retrieve a [`Actions`].
- ///
- /// Returns [`None`] if the referenced [`World`] has been dropped.
- #[must_use]
- pub fn access(&self) -> Option<Ref<'_>>
- {
- Some(Ref {
- action_queue: self.action_queue.upgrade()?,
- _pd: PhantomData,
- })
- }
-}
-
-/// Intermediate between [`Actions`] and [`WeakRef`]. Contains a strong reference to
-/// a world which is not allowed direct access to.
-#[derive(Debug, Clone)]
-pub struct Ref<'weak_ref>
-{
- action_queue: Rc<ActionQueue>,
- _pd: PhantomData<&'weak_ref ()>,
-}
-
-impl Ref<'_>
-{
- #[must_use]
- pub fn to_actions(&self) -> Actions<'_>
- {
- Actions {
- action_queue: &self.action_queue,
- world: None,
- }
- }
-}
-
/// A action for a [`System`] to perform.
#[derive(Debug)]
pub(crate) enum Action
diff --git a/ecs/src/sole.rs b/ecs/src/sole.rs
index 7cfcc24..82e5e0f 100644
--- a/ecs/src/sole.rs
+++ b/ecs/src/sole.rs
@@ -1,12 +1,12 @@
-use std::any::{type_name, Any};
+use std::any::{Any, type_name};
use std::fmt::Debug;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
-use std::sync::{Arc, Weak};
+use std::sync::Arc;
+use crate::World;
use crate::lock::{Lock, WriteGuard};
use crate::system::{Metadata as SystemMetadata, Param as SystemParam};
-use crate::World;
/// A type which has a single instance and is shared globally.
pub trait Sole: Any
@@ -44,7 +44,6 @@ impl Debug for dyn Sole
pub struct Single<'world, SoleT: Sole>
{
sole: WriteGuard<'world, Box<dyn Sole>>,
- sole_weak: Weak<Lock<Box<dyn Sole>>>,
_ph: PhantomData<SoleT>,
}
@@ -52,18 +51,6 @@ impl<'world, SoleT> Single<'world, SoleT>
where
SoleT: Sole,
{
- /// Returns a struct which holds a weak reference to the [`World`] that `Single`
- /// references and that can be used to aquire a new `Single` if the referenced
- /// [`World`] is still alive.
- #[must_use]
- pub fn to_weak_ref(&self) -> SingleWeakRef<SoleT>
- {
- SingleWeakRef {
- sole: self.sole_weak.clone(),
- _ph: PhantomData,
- }
- }
-
pub(crate) fn new(sole: &'world Arc<Lock<Box<dyn Sole>>>) -> Self
{
Self {
@@ -73,7 +60,6 @@ where
type_name::<SoleT>()
)
}),
- sole_weak: Arc::downgrade(sole),
_ph: PhantomData,
}
}
@@ -116,51 +102,3 @@ where
self.sole.downcast_mut().unwrap()
}
}
-
-#[derive(Debug, Clone)]
-pub struct SingleWeakRef<SoleT>
-where
- SoleT: Sole,
-{
- sole: Weak<Lock<Box<dyn Sole>>>,
- _ph: PhantomData<SoleT>,
-}
-
-impl<SoleT> SingleWeakRef<SoleT>
-where
- SoleT: Sole,
-{
- /// Returns a struct which can be used to retrieve a [`Single`].
- ///
- /// Returns [`None`] if the referenced [`World`] has been dropped.
- #[must_use]
- pub fn access(&self) -> Option<SingleRef<'_, SoleT>>
- {
- Some(SingleRef {
- sole: self.sole.upgrade()?,
- _pd: PhantomData,
- })
- }
-}
-
-/// Intermediate between [`Single`] and [`SingleWeakRef`]. Contains a strong reference to
-/// a world which is not allowed direct access to.
-#[derive(Debug, Clone)]
-pub struct SingleRef<'weak_ref, SoleT>
-where
- SoleT: Sole,
-{
- sole: Arc<Lock<Box<dyn Sole>>>,
- _pd: PhantomData<&'weak_ref SoleT>,
-}
-
-impl<SoleT> SingleRef<'_, SoleT>
-where
- SoleT: Sole,
-{
- #[must_use]
- pub fn to_single(&self) -> Single<'_, SoleT>
- {
- Single::new(&self.sole)
- }
-}