hecs could be extended with support for executing queries constructed at runtime rather than specified statically in types. This could be useful for e.g. interactively user-specified queries or for running queries in embedded scripting environments.
An implementation could look something like:
impl World {
fn query_dynamic(&self, q: DynamicQuery) -> DynamicQueryBorrow<'_>;
}
pub enum DynamicQuery {
Get(TypeId),
GetMut(TypeId),
And(Vec<DynamicQuery>),
}
where DynamicQueryBorrow<'_> contains an iterator which yields DynamicQueryItem which has
impl DynamicQueryItem<'_> {
fn get<T: Component>(&self) -> Option<&T>;
fn get_mut<T: Component>(&self) -> Option<&mut T>;
}
or perhaps
impl DynamicQueryItem<'_> {
fn get(&self, ty: TypeId) -> Option<&dyn Any>;
fn get_mut(&self, ty: TypeId) -> Option<&mut dyn Any>;
}
This is complex enough that I'm not likely to work on it unless there's significant demand, so please leave a comment describing your use case if you're interested!
hecs could be extended with support for executing queries constructed at runtime rather than specified statically in types. This could be useful for e.g. interactively user-specified queries or for running queries in embedded scripting environments.
An implementation could look something like:
where
DynamicQueryBorrow<'_>contains an iterator which yieldsDynamicQueryItemwhich hasor perhaps
This is complex enough that I'm not likely to work on it unless there's significant demand, so please leave a comment describing your use case if you're interested!