summaryrefslogtreecommitdiff
path: root/ecs/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-01-10 15:09:33 +0100
committerHampusM <hampus@hampusmat.com>2025-01-10 15:09:33 +0100
commitab2fa8a93de33ccb17ee1efd6f9b8858a8b79253 (patch)
treeae648720e075dd5862805ef7457748d417b18985 /ecs/src/lib.rs
parent49d954830c1872461b779847907328d50e4364e9 (diff)
refactor(ecs): add struct for querying using component metadata
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r--ecs/src/lib.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index d217525..1b9a31b 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -23,6 +23,7 @@ use crate::event::component::Kind as ComponentEventKind;
use crate::extension::{Collector as ExtensionCollector, Extension};
use crate::lock::{Lock, WriteGuard};
use crate::phase::{Phase, START as START_PHASE};
+use crate::query::flexible::Query as FlexibleQuery;
use crate::query::options::{Not, Options as QueryOptions, With};
use crate::relationship::{ChildOf, DependsOn, Relationship};
use crate::sole::Sole;
@@ -30,6 +31,7 @@ use crate::stats::Stats;
use crate::system::{System, SystemComponent};
use crate::type_name::TypeName;
use crate::uid::{Kind as UidKind, Uid};
+use crate::util::Sortable;
pub mod actions;
pub mod component;
@@ -182,6 +184,16 @@ impl World
Query::new(self)
}
+ pub fn flexible_query<CompMetadata>(
+ &self,
+ comp_metadata: CompMetadata,
+ ) -> FlexibleQuery<CompMetadata>
+ where
+ CompMetadata: Sortable<Item = ComponentMetadata> + AsRef<[ComponentMetadata]>,
+ {
+ FlexibleQuery::new(self, comp_metadata)
+ }
+
/// Performs a single tick.
///
/// # Panics
@@ -440,14 +452,18 @@ impl World
fn emit_event_by_id(&self, event_id: Uid)
{
- for (system,) in self
- .query::<(&SystemComponent,), ()>()
- .iter_with_extra_comps([ComponentMetadata {
+ let query = self.flexible_query([
+ ComponentMetadata::of::<SystemComponent>(),
+ ComponentMetadata {
id: event_id,
is_optional: ComponentIsOptional::No,
- }])
+ },
+ ]);
+
+ for (system,) in query
+ .iter::<()>()
+ .into_component_iter::<(&SystemComponent,)>(self)
{
- // SAFETY: The world lives long enough
unsafe {
system.system.run(self);
}