ditch setTimeout

This commit is contained in:
David Vanderson 2022-06-10 08:15:32 -04:00 committed by Stephen Gutekanst
parent 4eb872944a
commit ade26b24b1
2 changed files with 6 additions and 28 deletions

View file

@ -25,22 +25,17 @@
instance.exports.wasmInit();
let frame = true;
let last_update_time = performance.now();
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);
if (mach.machHasEvent() ||
(last_update_time + (mach.wait_event_timeout * 1000)) <= performance.now()) {{
instance.exports.wasmUpdate();
last_update_time = performance.now();
}}
window.requestAnimationFrame(update);
}};
mach.update = update;
window.requestAnimationFrame(update);
window.addEventListener("mach-close", () => {{