Refactor: better rounding (#1594)

This commit is contained in:
Alex Christoffer Rasmussen
2025-06-05 06:13:49 +02:00
committed by arc-alex
parent 421183fe55
commit 33ac05ebee
10 changed files with 93 additions and 181 deletions
@@ -717,6 +717,11 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
// combine all big changes
const hasImmediateChanges = hasNewLoaded || justStarted || hasChangedPlayback || offsetModeChanged;
// we would like the wall clock to tick on a regular rate
const normalClockUpdate =
getShouldClockUpdate(RuntimeService.previousClockUpdate, state.clock) ||
getForceUpdate(RuntimeService.previousClockUpdate, state.clock);
/**
* Timer should be updated if
* - big changes
@@ -733,6 +738,7 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
/**
* Runtime should be updated if
* - clock tick
* - big changes
* - the timer is updating so runtime also updates to keep them in sync ???
* - notification rate has been exceeded
@@ -740,7 +746,10 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
* Then check if there is actually a change in the data
*/
const shouldRuntimeUpdate =
(hasImmediateChanges || shouldUpdateTimer || getForceUpdate(RuntimeService.previousRuntimeUpdate, state.clock)) &&
(normalClockUpdate ||
hasImmediateChanges ||
shouldUpdateTimer ||
getForceUpdate(RuntimeService.previousRuntimeUpdate, state.clock)) &&
!deepEqual(RuntimeService.previousState?.runtime, state.runtime);
/**
@@ -751,13 +760,9 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
/**
* Many other values are calculated based on the clock
* so if any of them are updated we also need to send the clock
* in case nothing else is updating the clock will bw updated at the notification rate
* in case nothing else is updating the clock will be updated at the notification rate
*/
const shouldUpdateClock =
shouldUpdateTimer ||
shouldRuntimeUpdate ||
shouldBlockUpdate ||
getForceUpdate(RuntimeService.previousClockUpdate, state.clock);
const shouldUpdateClock = shouldRuntimeUpdate || shouldBlockUpdate || normalClockUpdate;
//Now we set all the updates on the eventstore and update the previous value
if (hasChangedPlayback) {
@@ -828,15 +833,19 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
// Helper function to save the restore state
function saveRestoreState(state: runtimeState.RuntimeState) {
restoreService.save({
playback: state.timer.playback,
selectedEventId: state.eventNow?.id ?? null,
startedAt: state.timer.startedAt,
addedTime: state.timer.addedTime,
pausedAt: state._timer.pausedAt,
firstStart: state.runtime.actualStart,
blockStartAt: state.currentBlock.startedAt,
});
restoreService
.save({
playback: state.timer.playback,
selectedEventId: state.eventNow?.id ?? null,
startedAt: state.timer.startedAt,
addedTime: state.timer.addedTime,
pausedAt: state._timer.pausedAt,
firstStart: state.runtime.actualStart,
blockStartAt: state.currentBlock.startedAt,
})
.catch((_e) => {
//we don't do anything with the error here
});
}
batch.send();