From 5e9c5db231dfd0061ebae387d01507019051acc5 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Mon, 26 Aug 2024 16:06:37 -0700 Subject: [PATCH] Ray-caster: switch from draw effect to animation loop This wastes a lot of CPU time, as explained on lines 253--258 of `main.rs`, but it's better than the previous version, which could block graphics updates system-wide for seconds on end. --- app-proto/inversive-display/src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app-proto/inversive-display/src/main.rs b/app-proto/inversive-display/src/main.rs index a5bfedc..ebbf713 100644 --- a/app-proto/inversive-display/src/main.rs +++ b/app-proto/inversive-display/src/main.rs @@ -10,7 +10,7 @@ extern crate js_sys; use core::array; use nalgebra::DVector; -use sycamore::{prelude::*, rt::{JsCast, JsValue}}; +use sycamore::{prelude::*, motion::create_raf, rt::{JsCast, JsValue}}; use web_sys::{console, WebGl2RenderingContext, WebGlProgram, WebGlShader, WebGlUniformLocation}; mod engine; @@ -207,7 +207,7 @@ fn main() { bind_vertex_attrib(&ctx, position_index, 3, &positions); // set up a repainting routine - create_effect(move || { + let (_, start_updating_display, _) = create_raf(move || { // update the construction sphere_vec.clear(); sphere_vec.push(engine::sphere(0.5, 0.5, -5.0 + ctrl_x.get(), radius_x.get())); @@ -249,6 +249,14 @@ fn main() { // draw the scene ctx.draw_arrays(WebGl2RenderingContext::TRIANGLES, 0, VERTEX_CNT as i32); }); + + /* + this wastes CPU time by running an animation loop, which updates the + display even when nothing has changed. there should be a way to make + Sycamore do single-frame updates in response to changes, but i + haven't found it yet + */ + start_updating_display(); }); view! {