summaryrefslogtreecommitdiff
path: root/ecs/src/query/flexible.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/query/flexible.rs')
-rw-r--r--ecs/src/query/flexible.rs39
1 files changed, 20 insertions, 19 deletions
diff --git a/ecs/src/query/flexible.rs b/ecs/src/query/flexible.rs
index 652b96f..add30b0 100644
--- a/ecs/src/query/flexible.rs
+++ b/ecs/src/query/flexible.rs
@@ -2,25 +2,20 @@
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::component::storage::{ArchetypeRefIter, ArchetypeSearchTerms};
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>
+pub struct Query<'world, const MAX_TERM_CNT: usize>
{
- component_storage: ReadGuard<'world, ComponentStorage>,
- terms: Terms<'terms>,
+ world: &'world World,
+ terms: Terms<MAX_TERM_CNT>,
}
-impl<'world, 'terms> Query<'world, 'terms>
+impl<'world, const MAX_TERM_CNT: usize> Query<'world, MAX_TERM_CNT>
{
/// Iterates over the entities matching this query.
#[must_use]
@@ -28,6 +23,8 @@ impl<'world, 'terms> Query<'world, 'terms>
{
Iter {
iter: self
+ .world
+ .data
.component_storage
.search_archetypes(ArchetypeSearchTerms {
required_components: &self.terms.required_components,
@@ -42,16 +39,20 @@ impl<'world, 'terms> Query<'world, 'terms>
}
}
- pub(crate) fn new(world: &'world World, terms: Terms<'terms>) -> Self
+ pub(crate) fn new(world: &'world World, terms: Terms<MAX_TERM_CNT>) -> Self
{
- Self {
- component_storage: world
- .data
- .component_storage
- .read_nonblock()
- .expect("Failed to acquire read-only component storage lock"),
- terms,
- }
+ Self { world, terms }
+ }
+}
+
+impl<'query, const MAX_TERM_CNT: usize> IntoIterator for &'query Query<'_, MAX_TERM_CNT>
+{
+ type IntoIter = Iter<'query>;
+ type Item = EntityHandle<'query>;
+
+ fn into_iter(self) -> Self::IntoIter
+ {
+ self.iter()
}
}