Struct bevy_defer::access::AsyncWorld
source · pub struct AsyncWorld;
Expand description
Async version of World
or Commands
.
This type only works inside a bevy_defer
future,
calling any function outside of a bevy_defer
future
or inside a world access function (a closure with World
as a parameter)
will likely panic.
If you need the functionalities defined here in sync code, see non-send resources
AsyncExecutor
and QueryQueue
.
Implementations§
source§impl AsyncWorld
impl AsyncWorld
sourcepub fn asset<A: Asset>(&self, handle: Handle<A>) -> AsyncAsset<A>
pub fn asset<A: Asset>(&self, handle: Handle<A>) -> AsyncAsset<A>
Obtain an AsyncAsset
from a Handle
.
§Example
let square = AsyncWorld.load_asset::<Image>("square.png");
AsyncWorld.asset(square.into_handle());
sourcepub fn load_asset<A: Asset>(
&self,
path: impl Into<AssetPath<'static>> + Send + 'static
) -> AsyncAsset<A>
pub fn load_asset<A: Asset>( &self, path: impl Into<AssetPath<'static>> + Send + 'static ) -> AsyncAsset<A>
sourcepub fn load_asset_with_settings<A: Asset, S: Settings>(
&self,
path: impl Into<AssetPath<'static>> + Send + 'static,
f: impl Fn(&mut S) + Send + Sync + 'static
) -> AsyncAsset<A>
pub fn load_asset_with_settings<A: Asset, S: Settings>( &self, path: impl Into<AssetPath<'static>> + Send + 'static, f: impl Fn(&mut S) + Send + Sync + 'static ) -> AsyncAsset<A>
Begins loading an Asset of type A
stored at path.
The given settings function will override the asset’s AssetLoader settings.
sourcepub fn add_asset<A: Asset + 'static>(&self, item: A) -> AccessResult<Handle<A>>
pub fn add_asset<A: Asset + 'static>(&self, item: A) -> AccessResult<Handle<A>>
Add an asset and obtain its handle.
source§impl AsyncWorld
impl AsyncWorld
sourcepub fn send_event<E: Event>(&self, event: E) -> AccessResult<EventId<E>>
pub fn send_event<E: Event>(&self, event: E) -> AccessResult<EventId<E>>
Send an Event
.
sourcepub fn event_stream<E: Event + Clone>(&self) -> EventStream<E>
pub fn event_stream<E: Event + Clone>(&self) -> EventStream<E>
Create a stream to an Event
, requires the corresponding react_to_event
system.
This requires Clone
and duplicates all events sent in bevy.
source§impl AsyncWorld
impl AsyncWorld
sourcepub fn new() -> Self
pub fn new() -> Self
Acquire an AsyncWorld
, checks if in a bevy_defer
future.
§Panics
When used outside a bevy_defer
future.
§Note
You can construct AsyncWorld
directly without this error.
sourcepub fn entity(&self, entity: Entity) -> AsyncEntityMut
pub fn entity(&self, entity: Entity) -> AsyncEntityMut
sourcepub fn resource<R: Resource>(&self) -> AsyncResource<R>
pub fn resource<R: Resource>(&self) -> AsyncResource<R>
sourcepub fn non_send_resource<R: 'static>(&self) -> AsyncNonSend<R>
pub fn non_send_resource<R: 'static>(&self) -> AsyncNonSend<R>
sourcepub fn query<Q: QueryData>(&self) -> AsyncQuery<Q>
pub fn query<Q: QueryData>(&self) -> AsyncQuery<Q>
Obtain an AsyncQuery
.
sourcepub fn query_filtered<Q: QueryData, F: QueryFilter>(&self) -> AsyncQuery<Q, F>
pub fn query_filtered<Q: QueryData, F: QueryFilter>(&self) -> AsyncQuery<Q, F>
Obtain an AsyncQuery
.
sourcepub fn frame_count(&self) -> u32
pub fn frame_count(&self) -> u32
Obtain frame count since init
, according to the executor.
source§impl AsyncWorld
impl AsyncWorld
sourcepub fn apply_command(&self, command: impl Command)
pub fn apply_command(&self, command: impl Command)
Apply a command.
Use AsyncWorld::run
to obtain a result instead.
§Example
AsyncWorld.apply_command(|w: &mut World| println!("{:?}", w))
sourcepub fn apply_command_queue(&self, commands: CommandQueue)
pub fn apply_command_queue(&self, commands: CommandQueue)
Apply a CommandQueue
.
§Example
let queue = CommandQueue::default();
AsyncWorld.apply_command_queue(queue);
sourcepub fn watch<T: 'static>(
&self,
f: impl FnMut(&mut World) -> Option<T> + 'static
) -> ChannelOut<T> ⓘ
pub fn watch<T: 'static>( &self, f: impl FnMut(&mut World) -> Option<T> + 'static ) -> ChannelOut<T> ⓘ
sourcepub fn run_schedule(&self, schedule: impl ScheduleLabel) -> AccessResult
pub fn run_schedule(&self, schedule: impl ScheduleLabel) -> AccessResult
sourcepub fn register_system<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>(
&self,
system: S
) -> SystemId<I, O>
pub fn register_system<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>( &self, system: S ) -> SystemId<I, O>
sourcepub fn run_system<O: 'static>(&self, system: SystemId<(), O>) -> AccessResult<O>
pub fn run_system<O: 'static>(&self, system: SystemId<(), O>) -> AccessResult<O>
sourcepub fn run_system_with_input<I: 'static, O: 'static>(
&self,
system: SystemId<I, O>,
input: I
) -> AccessResult<O>
pub fn run_system_with_input<I: 'static, O: 'static>( &self, system: SystemId<I, O>, input: I ) -> AccessResult<O>
sourcepub fn run_cached_system<O: 'static, M, S: IntoSystem<(), O, M> + 'static>(
&self,
system: S
) -> AccessResult<O>
pub fn run_cached_system<O: 'static, M, S: IntoSystem<(), O, M> + 'static>( &self, system: S ) -> AccessResult<O>
sourcepub fn run_cached_system_with_input<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>(
&self,
system: S,
input: I
) -> AccessResult<O>
pub fn run_cached_system_with_input<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>( &self, system: S, input: I ) -> AccessResult<O>
Run a system with input that will be stored and reused upon repeated usage.
§Note
The system is disambiguated by the type ID of the closure.
Be careful not to pass in a fn
.
§Example
AsyncWorld.run_cached_system_with_input(|input: In<f32>, time: Res<Time>| time.delta_seconds() + *input, 4.0).unwrap();
sourcepub fn spawn_empty(&self) -> AsyncEntityMut
pub fn spawn_empty(&self) -> AsyncEntityMut
sourcepub fn spawn_bundle(&self, bundle: impl Bundle) -> AsyncEntityMut
pub fn spawn_bundle(&self, bundle: impl Bundle) -> AsyncEntityMut
sourcepub fn set_state<S: States>(&self, state: S) -> AccessResult<()>
pub fn set_state<S: States>(&self, state: S) -> AccessResult<()>
sourcepub fn get_state<S: States>(&self) -> AccessResult<S>
pub fn get_state<S: States>(&self) -> AccessResult<S>
sourcepub fn in_state<S: States>(&self, state: S) -> ChannelOut<()> ⓘ
👎Deprecated: Use state_stream
instead.
pub fn in_state<S: States>(&self, state: S) -> ChannelOut<()> ⓘ
state_stream
instead.sourcepub fn state_stream<S: States + Clone + Default>(&self) -> SignalStream<S>
pub fn state_stream<S: States + Clone + Default>(&self) -> SignalStream<S>
Obtain a SignalStream
that reacts to changes of a States
.
Requires system react_to_state
.
sourcepub fn sleep(&self, duration: impl AsSeconds) -> MaybeChannelOut<()>
pub fn sleep(&self, duration: impl AsSeconds) -> MaybeChannelOut<()>
Pause the future for the duration, according to the Time
resource.
§Example
AsyncWorld.sleep(5.4).await
sourcepub fn sleep_frames(&self, frames: u32) -> MaybeChannelOut<()>
pub fn sleep_frames(&self, frames: u32) -> MaybeChannelOut<()>
Pause the future for some frames, according to the FrameCount
resource.
§Example
AsyncWorld.sleep_frames(12).await
sourcepub fn yield_now(&self) -> impl Future<Output = ()> + 'static
pub fn yield_now(&self) -> impl Future<Output = ()> + 'static
Yield control back to the bevy_defer
executor.
Unlike yield_now
from futures_lite
,
the future will be resumed on the next execution point.
sourcepub fn typed_signal<T: SignalId>(&self) -> Signal<T::Data>
pub fn typed_signal<T: SignalId>(&self) -> Signal<T::Data>
sourcepub fn spawn_scoped<T: 'static>(
&self,
fut: impl Future<Output = T> + 'static
) -> impl Future<Output = T>
pub fn spawn_scoped<T: 'static>( &self, fut: impl Future<Output = T> + 'static ) -> impl Future<Output = T>
source§impl AsyncWorld
impl AsyncWorld
sourcepub async fn spawn_scene(&self, bun: impl Bundle) -> AsyncEntityMut
pub async fn spawn_scene(&self, bun: impl Bundle) -> AsyncEntityMut
Spawn a scene and wait for spawning to complete.
Requires react_to_scene_load
to function.
source§impl AsyncWorld
impl AsyncWorld
sourcepub fn timed_routine<T: 'static>(
&self,
f: impl FnMut(&mut World, Duration) -> Option<T> + 'static,
cancellation: impl Into<TaskCancellation>
) -> ChannelOutOrCancel<T> ⓘ
pub fn timed_routine<T: 'static>( &self, f: impl FnMut(&mut World, Duration) -> Option<T> + 'static, cancellation: impl Into<TaskCancellation> ) -> ChannelOutOrCancel<T> ⓘ
Run a repeatable routine on Update
, with access to delta time.
Trait Implementations§
source§impl AsyncWorldParam for AsyncWorld
impl AsyncWorldParam for AsyncWorld
source§fn from_async_context(_: &Reactors) -> Option<Self>
fn from_async_context(_: &Reactors) -> Option<Self>
Self
from the async context.source§fn build_in_async() -> Option<Self>
fn build_in_async() -> Option<Self>
bevy_defer
future.source§impl Clone for AsyncWorld
impl Clone for AsyncWorld
source§fn clone(&self) -> AsyncWorld
fn clone(&self) -> AsyncWorld
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AsyncWorld
impl Debug for AsyncWorld
impl Copy for AsyncWorld
Auto Trait Implementations§
impl Freeze for AsyncWorld
impl RefUnwindSafe for AsyncWorld
impl Send for AsyncWorld
impl Sync for AsyncWorld
impl Unpin for AsyncWorld
impl UnwindSafe for AsyncWorld
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.source§impl<T> AsyncEntityParam for Twhere
T: AsyncWorldParam,
impl<T> AsyncEntityParam for Twhere
T: AsyncWorldParam,
source§fn fetch_signal(_: &Signals) -> Option<<T as AsyncEntityParam>::Signal>
fn fetch_signal(_: &Signals) -> Option<<T as AsyncEntityParam>::Signal>
source§fn from_async_context(
_: Entity,
reactors: &Reactors,
_: <T as AsyncEntityParam>::Signal,
_: &[Entity]
) -> Option<T>
fn from_async_context( _: Entity, reactors: &Reactors, _: <T as AsyncEntityParam>::Signal, _: &[Entity] ) -> Option<T>
Self
from the async context.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.