05-26-2023, 04:32 AM
Nice! @lupyuen btw when you are missing functions in Zig/WASM it is often easier to make a call into the javascript world, unless you are on a performance critical path. For my wasm stuff I also keep the render loop on the JS side using requestAnimationFrame but with a custom callback into Zig (once per frame) passing over a frame number, timestamp and canvas2d context.
roughly:
roughly:
Code:
WebAssembly.instantiateStreaming(fetch('app.wasm'),{env}).then(wa=>{
zex=wa.instance.exports;
zmb=zex.memory.buffer;
zex.run();
let fn=0; //frame number
function frame(ts) {
zex.drawFrame(ctx,fn,timestamp);
fn++;
globalThis.requestAnimationFrame(frame);
}
globalThis.requestAnimationFrame(frame);
})