aboutsummaryrefslogtreecommitdiffstats
path: root/src/render_loop.rs
diff options
context:
space:
mode:
authorbrian cully <bjc@spork.org>2025-12-29 11:20:12 -0500
committerbrian cully <bjc@spork.org>2025-12-29 11:20:12 -0500
commit5378626d85b69b53b79d2539dea9c8746af88616 (patch)
tree435214a5407a151dcc644af3a47d5f0ad2ece32e /src/render_loop.rs
parentf3bc843bcaa5c40ce93a6f1777d48e2ad7d097f5 (diff)
downloadpolyring-5378626d85b69b53b79d2539dea9c8746af88616.tar.gz
polyring-5378626d85b69b53b79d2539dea9c8746af88616.zip
wasm: separate update/render for later benching
Diffstat (limited to 'src/render_loop.rs')
-rw-r--r--src/render_loop.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/render_loop.rs b/src/render_loop.rs
index 628e687..7056493 100644
--- a/src/render_loop.rs
+++ b/src/render_loop.rs
@@ -4,6 +4,8 @@ use std::rc::Rc;
use log::error;
use wasm_bindgen::prelude::*;
+use crate::JSResult;
+
/// use `window.requestAnimationFrame()` to schedule calling a
/// function as long as the function returns true.
pub struct RenderLoop {
@@ -21,7 +23,7 @@ impl RenderLoop {
/// `fun` takes a timestamp in the same space as the document
/// timeline and returns a flag specifying whether we should
/// schedule another frame..
- pub fn new<T: FnMut(f64) -> bool + 'static>(mut fun: T) -> Self {
+ pub fn new<T: FnMut(f64) -> JSResult<bool> + 'static>(mut fun: T) -> Self {
// init with stub closure because rust wants that, then change
// it later once we have our rc clone.
let inner = Rc::new(UnsafeCell::new(Closure::new(|_| {})));
@@ -29,11 +31,15 @@ impl RenderLoop {
let rloop = inner.clone();
let f = unsafe { &mut *inner.get() };
*f = Closure::new(move |t| {
- if fun(t) {
- let cl = unsafe { &*rloop.get() };
- if let Err(e) = Self::request_animation_frame(cl) {
- error!("couldn't request animation frame: {:?}", e);
+ match fun(t) {
+ Err(e) => error!("render callback error: {:?}", e),
+ Ok(true) => {
+ let cl = unsafe { &*rloop.get() };
+ if let Err(e) = Self::request_animation_frame(cl) {
+ error!("couldn't request animation frame: {:?}", e);
+ }
}
+ Ok(false) => {},
}
});