Crates.io | bevy-async-ecs |
lib.rs | bevy-async-ecs |
version | |
source | src |
created_at | 2023-12-01 06:40:20.472348 |
updated_at | 2024-12-03 02:50:36.43122 |
description | Asynchronous interface for Bevy ECS |
homepage | |
repository | https://github.com/dlom/bevy-async-ecs |
max_upload_size | |
id | 1054829 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Bevy Async ECS is an asynchronous interface to the standard Bevy World
.
It aims to be simple and intuitive to use for those familiar with Bevy's ECS.
AsyncWorld
AsyncWorld
is the entrypoint for all further asynchronous manipulation of the world.
It can only be created using the FromWorld
trait implementation.
It should be driven by an executor running parallel with the main Bevy app
(this can either be one of the TaskPool
s or a blocking executor running on another thread).
Internally, the AsyncWorld
simply wraps an MPSC channel sender.
As such, it can be cheaply cloned and further sent to separate threads or tasks.
This means that all operations on the AsyncWorld
are processed in FIFO order.
However, there are no ordering guarantees between AsyncWorld
s or any derivatives sharing the same internal channel
sender, or any AsyncWorld
s constructed separately.
It is important to note that Bevy is still running and mutating the world while the async tasks run! Assume that the world could have been mutated between any asynchronous call. However, there are several ways to ensure that multiple commands are applied together, without mutation of the world in between:
CommandQueue
, and send it to the Bevy World
with CommandQueueSender::send_queue()
AsyncWorld
via AsyncWorld::start_queue()
use bevy::prelude::*;
use bevy::tasks::AsyncComputeTaskPool;
use bevy_async_ecs::*;
// vanilla Bevy system
fn print_names(query: Query<(Entity, &Name)>) {
for (id, name) in query.iter() {
info!("entity {:?} has name '{}'", id, name);
}
}
fn main() {
App::new()
.add_plugins((DefaultPlugins, AsyncEcsPlugin))
.add_systems(Startup, |world: &mut World| {
let async_world = AsyncWorld::from_world(world);
let fut = async move {
let print_names = async_world.register_system(print_names).await;
let entity = async_world.spawn_named("Frank").await;
print_names.run().await;
entity.despawn().await;
};
AsyncComputeTaskPool::get().spawn(fut).detach();
})
.run();
}
bevy-async-ecs
fully supports running in a web environment. Run the examples in your browser:
# One-time setup
rustup target install wasm32-unknown-unknown
cargo install wasm-server-runner
# Run examples
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-server-runner cargo run --target wasm32-unknown-unknown --example end_to_end
bevy-async-ecs
does not explicitly require the multi-threaded
feature (though all the tests and non-browser examples do).
However, due to its asynchronous nature, this library inherently requires a multithreaded environment. In a web environment,
the browser provides this for us. On native platforms, the multi-threaded
feature will likely have to be enabled to prevent the
app from deadlocking.
bevy | bevy-async-ecs |
---|---|
0.15 | 0.7.0 |
0.14 | 0.6.1 |
0.13 | 0.5.1 |
0.12 | 0.4.1 |
0.11 | N/A |