Browse Source

Make zoom animation use delta time

ssao
Aleksey Olokhtonov 6 months ago
parent
commit
e2ba3bb1c2
  1. 8
      README.txt
  2. 2
      client/index.js
  3. 23
      client/webgl_draw.js

8
README.txt

@ -8,7 +8,6 @@ Release:
+ Do not copy memory to wasm, instead use wasm memory to store data in the first place + Do not copy memory to wasm, instead use wasm memory to store data in the first place
+ SIMD for LOD? + SIMD for LOD?
+ Multithreading for LOD + Multithreading for LOD
- Move BVH to WASM side
- Z-prepass fringe bug (also, when do we enable the prepass?) - Z-prepass fringe bug (also, when do we enable the prepass?)
- Textured quads (pictures, code already written in older version) - Textured quads (pictures, code already written in older version)
- Resize and move pictures (draw handles) - Resize and move pictures (draw handles)
@ -38,7 +37,7 @@ Release:
+ Follow player + Follow player
+ Color picker (or at the very least an Open Color color pallete) + Color picker (or at the very least an Open Color color pallete)
+ EYE DROPPER! + EYE DROPPER!
* Dynamic svg cursor to represent the brush + Dynamic svg cursor to represent the brush
- Eraser - Eraser
- Line drawing - Line drawing
- Undo/redo - Undo/redo
@ -66,8 +65,9 @@ Bonus:
- Move whole curve - Move whole curve
- Move single point - Move single point
- Move multiple points - Move multiple points
- Customizable background * Customizable background
- Color, textures, procedural + Dots pattern
* Grid pattern
Bonus-bonus: Bonus-bonus:
- Actually infinite canvas (replace floats with something, some kind of fixed point scheme? chunks? multilevel scheme?) - Actually infinite canvas (replace floats with something, some kind of fixed point scheme? chunks? multilevel scheme?)

2
client/index.js

@ -266,6 +266,8 @@ async function main() {
'gpu_timer_ext': null, 'gpu_timer_ext': null,
'active_image': null, 'active_image': null,
'last_frame_ts': 0,
'last_frame_dt': 0,
}; };
load_player_cursor_template(state); load_player_cursor_template(state);

23
client/webgl_draw.js

@ -1,7 +1,7 @@
function schedule_draw(state, context) { function schedule_draw(state, context, animate = false) {
if (!state.timers.raf) { if (!state.timers.raf) {
window.requestAnimationFrame(async () => { window.requestAnimationFrame(async (ts) => {
await draw(state, context); await draw(state, context, animate, ts);
}); });
state.timers.raf = true; state.timers.raf = true;
} }
@ -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(); const cpu_before = performance.now();
context.last_frame_ts = ts;
const gl = context.gl; const gl = context.gl;
const width = window.innerWidth; const width = window.innerWidth;
const height = window.innerHeight; const height = window.innerHeight;
@ -346,14 +349,18 @@ async function draw(state, context) {
} }
if (state.canvas.target_zoom != state.canvas.zoom) { if (state.canvas.target_zoom != state.canvas.zoom) {
update_canvas_zoom(state, state.canvas.zoom, state.canvas.target_zoom); update_canvas_zoom(state, state.canvas.zoom, state.canvas.target_zoom, animate ? dt : context.last_frame_dt);
schedule_draw(state, context); 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) { 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 { } else {
state.canvas.zoom = target; state.canvas.zoom = target;
} }

Loading…
Cancel
Save