summaryrefslogtreecommitdiff
path: root/ecs/src/query
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/query')
-rw-r--r--ecs/src/query/flexible.rs46
1 files changed, 7 insertions, 39 deletions
diff --git a/ecs/src/query/flexible.rs b/ecs/src/query/flexible.rs
index c42ec25..a3e8701 100644
--- a/ecs/src/query/flexible.rs
+++ b/ecs/src/query/flexible.rs
@@ -3,30 +3,21 @@ use std::iter::{repeat_n, Filter, FlatMap, RepeatN, Zip};
use crate::component::storage::archetype::{Archetype, ArchetypeEntity, EntityIter};
use crate::component::storage::{ArchetypeRefIter, Storage as ComponentStorage};
-use crate::component::{
- Metadata as ComponentMetadata,
- RefSequence as ComponentRefSequence,
-};
use crate::lock::ReadGuard;
use crate::query::options::Options;
-use crate::query::ComponentIter;
+use crate::query::Terms;
use crate::uid::Uid;
-use crate::util::Sortable;
use crate::{EntityComponent, World};
/// Low-level entity query structure.
#[derive(Debug)]
-pub struct Query<'world, CompMetadata>
-where
- CompMetadata: Sortable<Item = ComponentMetadata> + AsRef<[ComponentMetadata]>,
+pub struct Query<'world, 'terms>
{
component_storage: ReadGuard<'world, ComponentStorage>,
- comp_metadata: CompMetadata,
+ terms: Terms<'terms>,
}
-impl<'world, CompMetadata> Query<'world, CompMetadata>
-where
- CompMetadata: Sortable<Item = ComponentMetadata> + AsRef<[ComponentMetadata]>,
+impl<'world, 'terms> Query<'world, 'terms>
{
/// Iterates over the entities matching this query.
#[must_use]
@@ -35,7 +26,7 @@ where
Iter {
iter: self
.component_storage
- .search_archetypes(self.comp_metadata.as_ref())
+ .search_archetypes(self.terms.required_components.as_ref())
.flat_map(
(|archetype| {
repeat_n(archetype, archetype.entity_cnt())
@@ -46,17 +37,15 @@ where
}
}
- pub(crate) fn new(world: &'world World, mut comp_metadata: CompMetadata) -> Self
+ pub(crate) fn new(world: &'world World, terms: Terms<'terms>) -> Self
{
- comp_metadata.sort_by_key_b(|metadata| metadata.id);
-
Self {
component_storage: world
.data
.component_storage
.read_nonblock()
.expect("Failed to acquire read-only component storage lock"),
- comp_metadata,
+ terms,
}
}
}
@@ -66,27 +55,6 @@ pub struct Iter<'query>
iter: QueryEntityIter<'query>,
}
-impl<'query> Iter<'query>
-{
- /// Converts this iterator into a [`ComponentIter`].
- ///
- /// Note: The matching entities of this iterator should have all of the non-[`Option`]
- /// components in `Comps`, otherwise iterating the [`ComponentIter`] will cause a
- /// panic.
- #[must_use]
- #[inline]
- pub fn into_component_iter<'world, Comps>(
- self,
- world: &'world World,
- ) -> ComponentIter<'query, 'world, Comps, Self>
- where
- Comps: ComponentRefSequence + 'world,
- 'world: 'query,
- {
- ComponentIter::new(world, self)
- }
-}
-
impl<'query> Iterator for Iter<'query>
{
type Item = EntityHandle<'query>;