mach/www/template.html
2022-06-10 12:57:31 -07:00

54 lines
1.3 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
canvas {{
border: 1px solid;
}}
</style>
</head>
<body>
<script type="module">
import {{ mach }} from "./mach.js";
let imports = {{
env: mach,
}};
fetch("{s}.wasm")
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.instantiate(buffer, imports))
.then(results => results.instance)
.then(instance => {{
mach.init(instance);
instance.exports.wasmInit();
let frame = true;
let update = function() {{
if (!frame) return;
instance.exports.wasmUpdate();
if (mach.wait_event_timeout > 0) {{
mach.wait_event_timer = setTimeout(() => {{
window.requestAnimationFrame(update);
}},
mach.wait_event_timeout * 1000);
}}
else {{
window.requestAnimationFrame(update);
}}
}};
mach.update = update;
window.requestAnimationFrame(update);
window.addEventListener("mach-close", () => {{
instance.exports.wasmDeinit();
frame = false;
}});
}})
.catch(err => console.error(err));
</script>
</body>
</html>