|
|
|
@ -1,7 +1,7 @@
@@ -1,7 +1,7 @@
|
|
|
|
|
function schedule_draw(state, context) { |
|
|
|
|
function schedule_draw(state, context, animate = false) { |
|
|
|
|
if (!state.timers.raf) { |
|
|
|
|
window.requestAnimationFrame(async () => { |
|
|
|
|
await draw(state, context); |
|
|
|
|
window.requestAnimationFrame(async (ts) => { |
|
|
|
|
await draw(state, context, animate, ts); |
|
|
|
|
}); |
|
|
|
|
state.timers.raf = true; |
|
|
|
|
} |
|
|
|
@ -76,9 +76,12 @@ function draw_html(state) {
@@ -76,9 +76,12 @@ function draw_html(state) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function draw(state, context) { |
|
|
|
|
async function draw(state, context, animate, ts) { |
|
|
|
|
const dt = ts - context.last_frame_ts; |
|
|
|
|
const cpu_before = performance.now(); |
|
|
|
|
|
|
|
|
|
context.last_frame_ts = ts; |
|
|
|
|
|
|
|
|
|
const gl = context.gl; |
|
|
|
|
const width = window.innerWidth; |
|
|
|
|
const height = window.innerHeight; |
|
|
|
@ -346,14 +349,18 @@ async function draw(state, context) {
@@ -346,14 +349,18 @@ async function draw(state, context) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.canvas.target_zoom != state.canvas.zoom) { |
|
|
|
|
update_canvas_zoom(state, state.canvas.zoom, state.canvas.target_zoom); |
|
|
|
|
schedule_draw(state, context); |
|
|
|
|
update_canvas_zoom(state, state.canvas.zoom, state.canvas.target_zoom, animate ? dt : context.last_frame_dt); |
|
|
|
|
schedule_draw(state, context, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
context.last_frame_dt = dt; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function update_canvas_zoom(state, current, target) { |
|
|
|
|
function update_canvas_zoom(state, current, target, dt) { |
|
|
|
|
const rate = Math.min(1.0, dt / 16.66 * 0.2); |
|
|
|
|
|
|
|
|
|
if (Math.abs(1.0 - current / target) > 0.01) { |
|
|
|
|
state.canvas.zoom = current + (target - current) * 0.2; |
|
|
|
|
state.canvas.zoom = current + (target - current) * rate; |
|
|
|
|
} else { |
|
|
|
|
state.canvas.zoom = target; |
|
|
|
|
} |
|
|
|
|