Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm singleton instance with debug draw #2

Open
marceline-cramer opened this issue Jul 1, 2021 · 0 comments
Open

Wasm singleton instance with debug draw #2

marceline-cramer opened this issue Jul 1, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@marceline-cramer
Copy link
Contributor

marceline-cramer commented Jul 1, 2021

Previously, we've used Wasmtime as the primary WebAssembly runtime. This time around, I believe that we should initially use WAVM. My main reason for saying this is because exploring alternative runtimes is valuable in of itself, and WAVM has several benefits over Wasmtime:

  • better performance: uses LLVM instead of Cranelift, also can do CPU-arch-specific optimizations like Gentoo
  • more conformant to the standardized C API
  • written in C/C++: more hackable by Mondradiko developers as opposed to Rust-based Wasmtime and Wasmer, can be built in-tree
  • native CMake build support: no more hacky vcpkg portfiles that download and configure binaries, we can write a portfile to actually build it as needed, and if we do so, we could push to the upstream vcpkg repo

The first step we can take with Wasm scripting is to create a singleton instance of a WebAssembly module loaded from disk, then call an update(dt) (takes an f32, returns nothing) function exported from it once a frame. Then, debug draw commands can be provided to the script to draw basic colored lines, using a very similar approach to drawTriangle() from Canary or the prototype engine's UI system.

To organize this, a new header/source file pair can be created:

  • include/scripting/debug_script.h
  • src/scripting/debug_script.c

Because debug draw is the only access the script has at the moment, the env parameter of Wasm functions can be set to the debug draw list itself. See world.c for an example of how this is wired up. cli/main.c can then create an instance of debug_script and update it every frame just like how it updates world.c.

@marceline-cramer marceline-cramer added good first issue Good for newcomers help wanted Extra attention is needed enhancement New feature or request labels Jul 1, 2021
This was referenced Jul 2, 2021
@marceline-cramer marceline-cramer changed the title WebAssembly via WAVM Wasm singleton instance with debug draw Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants