summaryrefslogtreecommitdiff
path: root/ecs/src/query
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/query')
-rw-r--r--ecs/src/query/flexible.rs83
-rw-r--r--ecs/src/query/term.rs38
2 files changed, 0 insertions, 121 deletions
diff --git a/ecs/src/query/flexible.rs b/ecs/src/query/flexible.rs
deleted file mode 100644
index 652b96f..0000000
--- a/ecs/src/query/flexible.rs
+++ /dev/null
@@ -1,83 +0,0 @@
-//! Low-level querying.
-use std::iter::{repeat_n, FlatMap, RepeatN, Zip};
-
-use crate::component::storage::archetype::{Archetype, EntityIter};
-use crate::component::storage::{
- ArchetypeRefIter,
- ArchetypeSearchTerms,
- Storage as ComponentStorage,
-};
-use crate::entity::Handle as EntityHandle;
-use crate::lock::ReadGuard;
-use crate::query::Terms;
-use crate::World;
-
-/// Low-level entity query structure.
-#[derive(Debug)]
-pub struct Query<'world, 'terms>
-{
- component_storage: ReadGuard<'world, ComponentStorage>,
- terms: Terms<'terms>,
-}
-
-impl<'world, 'terms> Query<'world, 'terms>
-{
- /// Iterates over the entities matching this query.
- #[must_use]
- pub fn iter(&self) -> Iter<'_>
- {
- Iter {
- iter: self
- .component_storage
- .search_archetypes(ArchetypeSearchTerms {
- required_components: &self.terms.required_components,
- excluded_components: &self.terms.excluded_components,
- })
- .flat_map(
- (|archetype| {
- repeat_n(archetype, archetype.entity_cnt())
- .zip(archetype.entities())
- }) as ComponentIterMapFn,
- ),
- }
- }
-
- pub(crate) fn new(world: &'world World, terms: Terms<'terms>) -> Self
- {
- Self {
- component_storage: world
- .data
- .component_storage
- .read_nonblock()
- .expect("Failed to acquire read-only component storage lock"),
- terms,
- }
- }
-}
-
-pub struct Iter<'query>
-{
- iter: QueryEntityIter<'query>,
-}
-
-impl<'query> Iterator for Iter<'query>
-{
- type Item = EntityHandle<'query>;
-
- fn next(&mut self) -> Option<Self::Item>
- {
- let (archetype, entity) = self.iter.next()?;
-
- Some(EntityHandle::new(archetype, entity))
- }
-}
-
-type ComponentIterMapFnOutput<'a> = Zip<RepeatN<&'a Archetype>, EntityIter<'a>>;
-
-type ComponentIterMapFn = for<'a> fn(&'a Archetype) -> ComponentIterMapFnOutput<'a>;
-
-type QueryEntityIter<'query> = FlatMap<
- ArchetypeRefIter<'query, 'query>,
- ComponentIterMapFnOutput<'query>,
- ComponentIterMapFn,
->;
diff --git a/ecs/src/query/term.rs b/ecs/src/query/term.rs
deleted file mode 100644
index 7f24147..0000000
--- a/ecs/src/query/term.rs
+++ /dev/null
@@ -1,38 +0,0 @@
-use std::marker::PhantomData;
-
-use crate::component::Component;
-use crate::query::{TermWithoutField, TermsBuilder, TermsBuilderInterface};
-
-pub struct With<ComponentT>
-where
- ComponentT: Component,
-{
- _pd: PhantomData<ComponentT>,
-}
-
-impl<ComponentT> TermWithoutField for With<ComponentT>
-where
- ComponentT: Component,
-{
- fn apply_to_terms_builder(terms_builder: &mut TermsBuilder<'_>)
- {
- terms_builder.with::<ComponentT>();
- }
-}
-
-pub struct Without<ComponentT>
-where
- ComponentT: Component,
-{
- _pd: PhantomData<ComponentT>,
-}
-
-impl<ComponentT> TermWithoutField for Without<ComponentT>
-where
- ComponentT: Component,
-{
- fn apply_to_terms_builder(terms_builder: &mut TermsBuilder<'_>)
- {
- terms_builder.without::<ComponentT>();
- }
-}