mondradiko / mdo-core

1 stars 1 forks source link

Wasm singleton instance with debug draw #2

Open marceline-cramer opened 3 years ago

marceline-cramer commented 3 years ago

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:

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:

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.