mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
fixed animation drops
This commit is contained in:
parent
721f707c94
commit
4d92922263
@ -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');
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user