feat: Doing more polishing (M8b)
This commit is contained in:
@@ -5,11 +5,11 @@ export function createClock() {
|
||||
}
|
||||
|
||||
// Feed it the real elapsed ms; it returns how many in-game days are due.
|
||||
// dt is capped so a background tab doesn't fast-forward the game on return, and
|
||||
// floored at 0: the first animation frame can carry a timestamp slightly before
|
||||
// the one the caller recorded, and a negative step would pre-load a whole day.
|
||||
export function consumeClock(clock, dtMs, msPerDay, speed) {
|
||||
clock.acc += Math.max(0, Math.min(dtMs, 1000)) * speed;
|
||||
// dt is capped (capMs) so a frozen tab doesn't fast-forward the game without limit when it wakes
|
||||
// up, and floored at 0: the first animation frame can carry a timestamp slightly before the one the
|
||||
// caller recorded, and a negative step would pre-load a whole day.
|
||||
export function consumeClock(clock, dtMs, msPerDay, speed, capMs = 1000) {
|
||||
clock.acc += Math.max(0, Math.min(dtMs, capMs)) * speed;
|
||||
const days = Math.floor(clock.acc / msPerDay);
|
||||
clock.acc -= days * msPerDay;
|
||||
return days;
|
||||
|
||||
Reference in New Issue
Block a user