mirror of
https://github.com/sndrec/WebMonkeyBall.git
synced 2026-02-03 02:03:33 +00:00
determinism work
This commit is contained in:
11
src/game.ts
11
src/game.ts
@@ -336,6 +336,8 @@ export class Game {
|
||||
public inputFeed: QuantizedStick[] | null;
|
||||
public inputFeedIndex: number;
|
||||
public inputRecord: QuantizedStick[] | null;
|
||||
public fixedTickMode: boolean;
|
||||
public fixedTicksPerUpdate: number;
|
||||
|
||||
constructor({
|
||||
hud,
|
||||
@@ -429,6 +431,8 @@ export class Game {
|
||||
this.inputFeed = null;
|
||||
this.inputFeedIndex = 0;
|
||||
this.inputRecord = null;
|
||||
this.fixedTickMode = false;
|
||||
this.fixedTicksPerUpdate = 1;
|
||||
}
|
||||
|
||||
setGameSource(source: GameSource) {
|
||||
@@ -442,6 +446,11 @@ export class Game {
|
||||
this.inputFeedIndex = 0;
|
||||
}
|
||||
|
||||
setFixedTickMode(enabled: boolean, ticksPerUpdate = 1) {
|
||||
this.fixedTickMode = enabled;
|
||||
this.fixedTicksPerUpdate = Math.max(1, ticksPerUpdate | 0);
|
||||
}
|
||||
|
||||
startInputRecording() {
|
||||
this.inputRecord = [];
|
||||
}
|
||||
@@ -1774,6 +1783,8 @@ export class Game {
|
||||
|
||||
if (this.paused) {
|
||||
this.accumulator = 0;
|
||||
} else if (this.fixedTickMode) {
|
||||
this.accumulator = this.fixedStep * this.fixedTicksPerUpdate;
|
||||
} else {
|
||||
this.accumulator = Math.min(this.accumulator + dtSeconds, this.fixedStep * MAX_FRAME_DELTA);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user