Mod your Bevy games with WebAssembly!
| | | |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- |
| bevy_wasm
|
| For games |
|
bevy_wasm_sys
|
| For mods |
|
bevy_wasm_shared
|
| For protocols |
See examples/cubes for a comprehensive example of how to use this.
Our protocol crate defines the two message types for communicating between the game and mods.
toml
[dependencies]
bevy_wasm_shared = "0.9"
serde = { version = "1.0", features = ["derive"] }
```rust use bevywasmshared::prelude::*; use serde::{Deserialize, Serialize};
/// The version of the protocol. Automatically set from the CARGO_PKG_XXX
environment variables.
pub const PROTOCOL_VERSION: Version = version!();
/// A message to be sent Mod -> Game.
pub enum ModMessage { Hello, }
/// A message to be sent Game -> Mod.
pub enum GameMessage { HiThere, } ```
Our game will import WasmPlugin
from bevy_wasm
, and use it to automatically send and receive messages with the mods.
toml
[dependencies]
bevy = "0.9"
bevy_wasm = "0.9"
my_game_protocol = { git = "https://github.com/username/my_game_protocol" }
```rust use bevy::prelude::; use bevy_wasm::prelude::; use mygameprotocol::{GameMessage, ModMessage, PROTOCOL_VERSION};
fn main() {
App::new()
.addplugins(DefaultPlugins)
.addplugin(WasmPlugin::
fn addmods(mut commands: Commands, wasmengine: Res
fn listenformod_messages(mut events: EventReader
fn sendmessagesto_mods(mut events: EventWriter
Our mod will import FFIPlugin
from bevy_wasm_sys
, and use it to automatically send and receive messages with the game.
toml
[dependencies]
bevy_wasm_sys = "0.9"
my_game_protocol = { git = "https://github.com/username/my_game_protocol" }
```rust use bevywasmsys::prelude::*; use mygameprotocol::{GameMessage, ModMessage, PROTOCOL_VERSION};
pub unsafe extern "C" fn buildapp() {
App::new()
.addplugin(FFIPlugin::
fn listenforgame_messages(mut events: EventReader
fn sendmessagesto_game(mut events: EventWriter
Protocol:
```rust
pub struct MyResource { pub value: i32, } ```
Game:
```rust
App::new()
...
.addresource(MyResource { value: 0 })
.addplugin(
WasmPlugin::
fn changeresourcevalue(mut resource: ResMut
Mod:
```rust
App::new()
...
.addplugin(FFIPlugin::
fn setup(mut externresource: ResMut
fn printresourcevalue(resource: ExternRes
See examples/shared_resources for a full example.
| | | | --- | ------------------------------------------------ | | ✅ | wasmtime runtime in games | | ✅ | Send messages from mods to game | | ✅ | Send messages from game to mods | | ✅ | Multi-mod support | | ✅ | Time keeping | | ✅ | Protocol version checking | | ✅ | Extern Resource | | ✅ | Startup system mod loading | | ✅ | Direct update control | | ✅ | Mod unloading | | ✅ | Mod discrimination (events aren't broadcast all) | | ⬜ | Mutable Extern Resource | | ⬜ | Extern Query | | ⬜ | Custom FFI | | ⬜ | Synced time | | ⬜ | Mod hotloading | | ⬜ | Automatic component syncing | | ⬜ | Browser support |