mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-12 22:28:36 +00:00
prettier
This commit is contained in:
parent
796f741a92
commit
b60beaf508
@ -366,7 +366,13 @@ export function objectMap(obj, fn) {
|
||||
|
||||
// utility for averaging two clocks together to account for drift
|
||||
export class ClockCollator {
|
||||
constructor({ getTargetClockTime = () => Date.now() / 1000, weight = 16, offsetDelta = 0.005, checkAfterTime = 2, resetAfterTime = 8 }) {
|
||||
constructor({
|
||||
getTargetClockTime = () => Date.now() / 1000,
|
||||
weight = 16,
|
||||
offsetDelta = 0.005,
|
||||
checkAfterTime = 2,
|
||||
resetAfterTime = 8,
|
||||
}) {
|
||||
this.offsetTime;
|
||||
this.timeAtPrevOffsetSample;
|
||||
this.prevOffsetTimes = [];
|
||||
@ -374,7 +380,7 @@ export class ClockCollator {
|
||||
this.weight = weight;
|
||||
this.offsetDelta = offsetDelta;
|
||||
this.checkAfterTime = checkAfterTime;
|
||||
this.resetAfterTime = resetAfterTime
|
||||
this.resetAfterTime = resetAfterTime;
|
||||
}
|
||||
|
||||
calculateTimestamp(currentTime, targetTime) {
|
||||
@ -383,9 +389,9 @@ export class ClockCollator {
|
||||
const newOffsetTime = targetClockTime - currentTime;
|
||||
// recalcuate the diff from scratch if the clock has been paused for some time.
|
||||
if (diffBetweenTimeSamples > this.resetAfterTime) {
|
||||
this.prevOffsetTimes = []
|
||||
this.prevOffsetTimes = [];
|
||||
}
|
||||
|
||||
|
||||
if (this.offsetTime == null) {
|
||||
this.offsetTime = newOffsetTime;
|
||||
}
|
||||
@ -393,12 +399,10 @@ export class ClockCollator {
|
||||
if (this.prevOffsetTimes.length > this.weight) {
|
||||
this.prevOffsetTimes.shift();
|
||||
}
|
||||
|
||||
|
||||
// after X time has passed, the average of the previous weight offset times is calculated and used as a stable reference
|
||||
// for calculating the timestamp
|
||||
if (this.timeAtPrevOffsetSample == null || diffBetweenTimeSamples > this.checkAfterTime) {
|
||||
|
||||
|
||||
this.timeAtPrevOffsetSample = targetClockTime;
|
||||
const rollingOffsetTime = averageArray(this.prevOffsetTimes);
|
||||
//when the clock offsets surpass the delta, set the new reference time
|
||||
@ -412,9 +416,8 @@ export class ClockCollator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function getPerformanceTimeSeconds() {
|
||||
return performance.now() / 1000
|
||||
return performance.now() / 1000;
|
||||
}
|
||||
|
||||
// Floating point versions, see Fraction for rational versions
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user