fixed animation drops

This commit is contained in:
Jade (Rose) Rowland 2024-01-12 00:20:20 -05:00
parent 721f707c94
commit 4d92922263
3 changed files with 8 additions and 3 deletions

View File

@ -62,7 +62,7 @@ let clock = createClock(
lastEnd = end;
const tickdeadline = phase - time; // time left until the phase is a whole number
lastTick = time + tickdeadline;
sendMessage('tick', { begin, end, tickdeadline, cps, time: Date.now(), cycle: getCycle() });
sendMessage('tick', { begin, end, tickdeadline, cps, cycle: getCycle() });
} catch (e) {
log(`[cyclist] error: ${e.message}`, 'error');
}

View File

@ -130,6 +130,7 @@ export class Drawer {
this.lastFrame = phase;
return;
}
// query haps from last frame till now. take last 100ms max
const haps = this.scheduler.pattern.queryArc(Math.max(this.lastFrame, phase - 1 / 10), phase);
this.lastFrame = phase;
@ -154,6 +155,7 @@ export class Drawer {
return;
}
// TODO: scheduler.now() seems to move even when it's stopped, this hints at a bug...
t = t ?? scheduler.now();
this.scheduler = scheduler;
let [_, lookahead] = this.drawTime;

View File

@ -13,6 +13,7 @@ export class NeoCyclist {
this.worker.port.start();
this.cycle = 0;
this.cps = 1;
this.timeAtLastTick = 0;
this.worker.port.addEventListener('message', (message) => {
if (!this.started) {
return;
@ -21,7 +22,8 @@ export class NeoCyclist {
switch (type) {
case 'tick': {
let { begin, end, cps, tickdeadline, time, cycle } = payload;
this.timeAtLastTickMessage = performance.now();
let { begin, end, cps, tickdeadline, cycle } = payload;
this.cps = cps;
this.cycle = cycle + latency * cps;
// const messageLatency = (Date.now() - time) / 1000;
@ -54,7 +56,8 @@ export class NeoCyclist {
now() {
// console.log(this.cycle, 'cycle');
return this.cycle;
const gap = ((performance.now() - this.timeAtLastTickMessage) / 1000) * this.cps;
return this.cycle + gap;
// this.sendMessage('requestcycles', {});
}
setCps(cps = 1) {