Adds support for wasm/wat assets in Bevy, and enables easier scripting

Overview

bevy_wasm_scripting

Adds support for wasm/wat assets in Bevy, and enables easy scripting. This is enabled through the wasmer crate.

  • Prepare for public use. This is very experimental! Please share any feedback in the Bevy Discord!
  • Scripts managed through bevy asset management
  • Scripts attached to components
  • Scripts attached to resources
  • Hot-reloading of component- and resource-based scripts
  • Basic examples
  • Harmonize resource- and component-based scripts, as they could both be simpler to define.
  • Put this through its paces with a game project, to find pain points
  • Confirm safety of WorldPointer imports strategy.
  • Investigate compilation performance and multi-threading options.
  • Investigate memory usage.
  • Investigate cooperation with web builds.
  • Configuration for Wasmer Tunables.
  • Configuration for Wasmer compiler. (The Cranelift compiler is currently hardcoded.)
  • Example game (probably a breakout clone with powerups)
  • Rust -> wasm script example
  • Lua -> wasm script example
  • Other language examples?

Examples

For component-based scripts:

fn main() {
    App::new()
    ...
        .add_plugin(WasmPlugin)
        .add_wasm_script_component::<AdderScript>()
        .add_startup_system(spawn_script_entity)
        .add_system(call_script_on_entity)
    ...
}

impl WasmScriptComponent for AdderScript {
    type ImportQueriedComponents = ();
    type ImportResources = ();
    fn get_wasm_script_handle(&self) -> &Handle<WasmScript> {
        &self.handle
    }
}

fn spawn_script_entity(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(AdderScript {
        handle: asset_server.load("add_one.wat"),
        accumulator: 0,
    });
}

// 
fn call_script_on_entity(
    mut scripted_entities: Query<&mut AdderScript>,
    mut script_env: WasmScriptComponentEnv<AdderScript>,
) {
    for mut scripted_entity in scripted_entities.iter_mut() {
        if let Ok(new_val) = script_env.call_if_instantiated(
            &scripted_entity.handle,
            "main",
            scripted_entity.accumulator,
        ) {
            scripted_entity.accumulator = new_val;
        }
        println!("Accumulated value: {}", scripted_entity.accumulator);
    }
}

More examples, for hot reloading, resource-based scripts, and script imports, are available in the examples directory.

Web Build Example

You can run the breakout example, very similar to the bevy examples:

cargo build --release --example breakout --target wasm32-unknown-unknown --features js --no-default-features
wasm-bindgen --out-name wasm_example   --out-dir examples/wasm/target   --target web target/wasm32-unknown-unknown/release/examples/breakout.wasm
basic-http-server examples/wasm
You might also like...
RPG Dialog support for Bevy, written in pure Rust!

🌷 🌷 Bevy x RPG Dialog 🌸 🌸 RPG Dialog support for Bevy, written in pure Rust! bevy-rpg is a plugin crate that adds dialog functionalities to Bevy,

Minecraft-esque voxel engine prototype made with the bevy game engine. Pending bevy 0.6 release to undergo a full rewrite.
Minecraft-esque voxel engine prototype made with the bevy game engine. Pending bevy 0.6 release to undergo a full rewrite.

vx_bevy A voxel engine prototype made using the Bevy game engine. Goals and features Very basic worldgen Animated chunk loading (ala cube world) Optim

bevy-hikari is an implementation of voxel cone tracing global illumination with anisotropic mip-mapping in Bevy
bevy-hikari is an implementation of voxel cone tracing global illumination with anisotropic mip-mapping in Bevy

Bevy Voxel Cone Tracing bevy-hikari is an implementation of voxel cone tracing global illumination with anisotropic mip-mapping in Bevy. Bevy Version

Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Wasm game of life - A Rust and WebAssembly tutorial implementing the Game of Life

wasm_game_of_life Conway's Game of Life in Rust and WebAssembly Contributing | Chat Built with 🦀 🕸 by The Rust and WebAssembly Working Group About T

A single-threaded polling-based Rust async executor suitable for use in games, embedded systems or WASM.

simple async local executor An Enlightware® software. Overview A single-threaded polling-based executor suitable for use in games, embedded systems or

A cross platform (wasm included) networking library!

bootleg_networking A cross platform (wasm included) networking library! A networking plugin for the Bevy game engine that wraps around bevy_networking

Cross-platform (including wasm) persistent key value store plugin for rust games/apps

bevy_pkv bevy_pkv is a cross-platform persistent key value store for rust apps. Use it for storing things like settings, save games etc. Currently, it

Reimplementation of Matthias Müller's "Ten Minute Physics" demos in Rust with WASM + WebGL

ten-minute-physics-rs reimplements Matthias Müller's "Ten Minute Physics" demos in Rust with WASM + WebGL. Compared with the source pure Javascript im

Owner
null
A simple extension for `bevy-editor-pls` to support tilemap editing right inside the bevy app.

What is this This is a simple tilemap editor plugin, that hooks right into bevy_editor_pls to work with bevy_ecs_tilemap. It works completely within i

null 3 May 8, 2023
A frontend to Assets purchased on Epic Games Store

Epic-Asset-Manager A frontend to Assets purchased on Epic Games Store Current Screenshot Install Arch Linux Use the AUR package Build flatpak meson _b

Acheta Games 202 Jan 3, 2023
A data compatibility project for Minecraft's assets

Data Compat MC Data tool for the Falcon MC project. Description DataCompatMC is a cli tool designed to help deal with the many different versions of M

GrizzlT 5 Dec 11, 2022
A data compatibility project for Minecraft's assets

Data Compat MC Data tool for the Falcon MC project. Description DataCompatMC is a cli tool designed to help deal with the many different versions of M

FalconMC 2 Jul 6, 2022
Decryption tool for assets.pie from Teenage Mutant Ninja Turtles: The Cowabunga Collection. This tool was made in its entirety by SowwyItsAnAlt.

Cowabunga Decryption tool for assets.pie from Teenage Mutant Ninja Turtles: The Cowabunga Collection. This tool was made in its entirety by SowwyItsAn

Masquerade 8 Dec 22, 2022
A lightweight standard for non-fungible assets.

Nifty Asset A lightweight standard for non-fungible assets. Contents Features Overview Packages Building Testing Programs Clients CLI License Warning

null 14 Mar 6, 2024
An opinionated, monolithic template for Bevy with cross-platform CI/CD, native + WASM launchers, and managed cross-platform deployment.

??️ Bevy Shell - Template An opinionated, monolithic template for Bevy with cross-platform CI/CD, native + WASM launchers, and managed cross-platform

Kurbos 218 Dec 30, 2022
Minecraft using Bevy and Bevy-Meshem

minecraft_bevy Minecraft_bevy was built to showcase bevy_meshem. After a week of developing it has: Chunk loading / unloading each chunk's mesh is bei

Adam 7 Oct 4, 2023
Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions

Introduction Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions. (hand interaction with boxes missing

Mika 52 Nov 14, 2022
Discord RIch Presence in Rust, with native Bevy support

Discord Presence The root project for both Bevy Discord Presence and regular Discord Presence, both contained in the crates directory. TODO Allow invi

Juliette Cordor 22 Nov 29, 2022