summaryrefslogtreecommitdiff
path: root/engine-ecs/src
diff options
context:
space:
mode:
Diffstat (limited to 'engine-ecs/src')
-rw-r--r--engine-ecs/src/component/storage.rs9
-rw-r--r--engine-ecs/src/component/storage/archetype.rs11
-rw-r--r--engine-ecs/src/util.rs59
3 files changed, 11 insertions, 68 deletions
diff --git a/engine-ecs/src/component/storage.rs b/engine-ecs/src/component/storage.rs
index b208a90..6522d5d 100644
--- a/engine-ecs/src/component/storage.rs
+++ b/engine-ecs/src/component/storage.rs
@@ -4,6 +4,7 @@ use std::cell::RefCell;
use std::fmt::Debug;
use std::vec::IntoIter as VecIntoIter;
+use either::Either;
use hashbrown::HashMap;
use crate::component::storage::archetype::{
@@ -20,7 +21,7 @@ use crate::component::storage::graph::{
};
use crate::uid::{PairParams, Uid};
use crate::util::array_vec::ArrayVec;
-use crate::util::{BorrowedOrOwned, Either, StreamingIterator, VecExt};
+use crate::util::{BorrowedOrOwned, StreamingIterator, VecExt};
pub mod archetype;
@@ -156,7 +157,7 @@ impl Storage
if search_terms.contains_conflicting() {
return ArchetypeRefIter {
storage: self,
- pre_iter: Either::B(Vec::new().into_iter()),
+ pre_iter: Either::Right(Vec::new().into_iter()),
dfs_iter: ArchetypeAddEdgeDfsIter::new(&self.graph, &[]),
search_terms,
};
@@ -189,7 +190,7 @@ impl Storage
return ArchetypeRefIter {
storage: self,
- pre_iter: Either::B(found_archetypes.clone().into_iter()),
+ pre_iter: Either::Right(found_archetypes.clone().into_iter()),
dfs_iter: ArchetypeAddEdgeDfsIter::new(&self.graph, &found_archetypes),
search_terms,
};
@@ -197,7 +198,7 @@ impl Storage
ArchetypeRefIter {
storage: self,
- pre_iter: Either::A([archetype_id].into_iter()),
+ pre_iter: Either::Left([archetype_id].into_iter()),
dfs_iter: add_edge_recursive_iter,
search_terms,
}
diff --git a/engine-ecs/src/component/storage/archetype.rs b/engine-ecs/src/component/storage/archetype.rs
index e72126a..480a1da 100644
--- a/engine-ecs/src/component/storage/archetype.rs
+++ b/engine-ecs/src/component/storage/archetype.rs
@@ -5,11 +5,12 @@ use std::iter::{Enumerate, Filter, Map, RepeatN, Zip};
use std::option::IntoIter as OptionIntoIter;
use std::slice::Iter as SliceIter;
+use either::Either;
use hashbrown::HashMap;
use crate::lock::Lock;
use crate::uid::Uid;
-use crate::util::{Either, HashMapExt};
+use crate::util::HashMapExt;
#[derive(Debug)]
pub struct Archetype
@@ -126,7 +127,7 @@ impl Archetype
{
if component_id.is_pair() && component_id.target() == Uid::wildcard() {
return MatchingComponentIter {
- inner: Either::A(
+ inner: Either::Left(
self.component_ids
.iter()
.enumerate()
@@ -144,7 +145,7 @@ impl Archetype
}
MatchingComponentIter {
- inner: Either::B(
+ inner: Either::Right(
[component_id]
.into_iter()
.zip(self.get_index_for_component(component_id)),
@@ -190,7 +191,7 @@ impl Archetype
) -> impl Iterator<Item = Uid> + use<'_>
{
if component_id.is_pair() && component_id.target() == Uid::wildcard() {
- return Either::A(
+ return Either::Left(
self.component_ids
.iter()
.filter(move |other_comp_id| {
@@ -201,7 +202,7 @@ impl Archetype
);
}
- Either::B(
+ Either::Right(
(if self.contains_component_with_exact_id(component_id) {
Some(component_id)
} else {
diff --git a/engine-ecs/src/util.rs b/engine-ecs/src/util.rs
index 304ba21..f3498fa 100644
--- a/engine-ecs/src/util.rs
+++ b/engine-ecs/src/util.rs
@@ -1,4 +1,3 @@
-use std::fmt::Display;
use std::hash::Hash;
use std::mem::transmute;
use std::ops::{BitAnd, Deref};
@@ -132,64 +131,6 @@ impl<Value> Deref for BorrowedOrOwned<'_, Value>
}
}
-#[derive(Debug, Clone)]
-pub enum Either<A, B>
-{
- A(A),
- B(B),
-}
-
-impl<A, B> Either<A, B>
-{
- #[inline]
- pub fn as_a(&self) -> Option<&A>
- {
- match self {
- Self::A(a) => Some(a),
- Self::B(_) => None,
- }
- }
-
- #[inline]
- pub fn as_b(&self) -> Option<&B>
- {
- match self {
- Self::A(_) => None,
- Self::B(b) => Some(b),
- }
- }
-}
-
-impl<A, B> Iterator for Either<A, B>
-where
- A: Iterator,
- B: Iterator<Item = A::Item>,
-{
- type Item = A::Item;
-
- fn next(&mut self) -> Option<Self::Item>
- {
- match self {
- Self::A(a) => a.next(),
- Self::B(b) => b.next(),
- }
- }
-}
-
-impl<A, B> Display for Either<A, B>
-where
- A: Display,
- B: Display,
-{
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
- {
- match self {
- Self::A(a) => a.fmt(f),
- Self::B(b) => b.fmt(f),
- }
- }
-}
-
pub trait HashMapExt<Key, Value>
{
/// Returns true if the keys are a subset of another [`HashMap`]'s keys, i.e., `other`