ditch setTimeout
This commit is contained in:
parent
4eb872944a
commit
ade26b24b1
2 changed files with 6 additions and 28 deletions
|
|
@ -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", () => {{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue