[−][src]Struct yaks::SystemContext
Thin wrapper over hecs::World
, can prepare queries using a
QueryMarker
.
Instantiating one directly is only useful when calling systems as plain functions,
and can be done either by SystemContext::new()
or converting a &hecs::World
or &mut hecs::World
:
fn some_system(_context: SystemContext, _resources: (), _queries: ()) {} let mut world = hecs::World::new(); some_system(SystemContext::new(&world), (), ()); some_system((&world).into(), (), ()); some_system((&mut world).into(), (), ());
Implementations
impl<'scope> SystemContext<'scope>
[src]
pub fn new(world: &'scope World) -> Self
[src]
Wraps a &hecs::World
. See documentation for SystemContext
itself.
pub fn id(&self) -> Option<SystemId>
[src]
Returns a debug-printable SystemId
if the system is ran in an
Executor
, with printed number reflecting
the order of insertion into the ExecutorBuilder
.
pub fn query<Q>(&self, _: QueryMarker<Q>) -> QueryBorrow<Q> where
Q: Query + Send + Sync,
[src]
Q: Query + Send + Sync,
Prepares a query using the given QueryMarker
;
see hecs::World::query()
.
Example
fn some_system( context: SystemContext, _resources: (), query: QueryMarker<(&mut Pos, &Vel)> ) { for (_entity, (pos, vel)) in context.query(query).iter() { *pos += *vel; } };
pub fn query_one<Q>(
&self,
_: QueryMarker<Q>,
entity: Entity
) -> Result<QueryOne<Q>, NoSuchEntity> where
Q: Query + Send + Sync,
[src]
&self,
_: QueryMarker<Q>,
entity: Entity
) -> Result<QueryOne<Q>, NoSuchEntity> where
Q: Query + Send + Sync,
Prepares a query against a single entity using the given
QueryMarker
;
see hecs::World::query_one()
.
Example
fn some_system( context: SystemContext, _resources: (), query: QueryMarker<(&mut Pos, &Vel)> ) { let mut max_velocity = Vel::default(); let mut max_velocity_entity = None; for (entity, (pos, vel)) in context.query(query).iter() { *pos += *vel; if *vel > max_velocity { max_velocity = *vel; max_velocity_entity = Some(entity); } } if let Some(entity) = max_velocity_entity { let mut query_one = context .query_one(query, entity) .expect("no such entity"); let (pos, _vel) = query_one .get() .expect("some components are missing"); *pos = Pos::default(); } };
Trait Implementations
impl<'scope> From<&'scope World> for SystemContext<'scope>
[src]
impl<'scope> From<&'scope mut World> for SystemContext<'scope>
[src]
Auto Trait Implementations
impl<'scope> !RefUnwindSafe for SystemContext<'scope>
impl<'scope> Send for SystemContext<'scope>
impl<'scope> Sync for SystemContext<'scope>
impl<'scope> Unpin for SystemContext<'scope>
impl<'scope> !UnwindSafe for SystemContext<'scope>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Component for T where
T: 'static + Send + Sync,
[src]
T: 'static + Send + Sync,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,