Support running the game at ludicrous speed
This commit is contained in:
parent
0f0c7437a6
commit
fec09c03ba
18
index.html
18
index.html
@ -205,14 +205,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<p>Game speed:
|
<p>Game speed:
|
||||||
<select name="speed">
|
<select name="speed">
|
||||||
<option value="6">6× — 120 tics per second</option>
|
<option value="20">20× faster</option>
|
||||||
<option value="3">3× — 60 tics per second</option>
|
<option value="10">10× faster</option>
|
||||||
<option value="2">2× — 40 tics per second</option>
|
<option value="5">5× faster</option>
|
||||||
<option value="3/2">1½× — 30 tics per second</option>
|
<option value="3">3× faster</option>
|
||||||
<option value="1" selected>1× — 20 tics per second</option>
|
<option value="2">2× faster</option>
|
||||||
<option value="1/2">½× — 10 tics per second</option>
|
<option value="3/2">1½× faster</option>
|
||||||
<option value="1/3">⅓× — 6⅔ tics per second</option>
|
<option value="1" selected>Normal speed</option>
|
||||||
<option value="1/4">¼× — 5 tics per second</option>
|
<option value="1/2">2× slower</option>
|
||||||
|
<option value="1/3">3× slower</option>
|
||||||
|
<option value="1/4">4× slower</option>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|||||||
19
js/main.js
19
js/main.js
@ -1049,13 +1049,27 @@ class Player extends PrimaryView {
|
|||||||
|
|
||||||
this.last_advance = performance.now();
|
this.last_advance = performance.now();
|
||||||
|
|
||||||
|
// If the game is running faster than normal, we cap the timeout between game loops at 10ms
|
||||||
|
// and do multiple loops at a time
|
||||||
|
// (Note that this is a debug feature so precision is not a huge deal and I don't bother
|
||||||
|
// tracking fractional updates, but asking to run at 10× and only getting 2× would suck)
|
||||||
|
let num_advances = 1;
|
||||||
|
let dt = 1000 / (TICS_PER_SECOND * this.play_speed);
|
||||||
|
if (dt < 10) {
|
||||||
|
num_advances = Math.ceil(10 / dt);
|
||||||
|
dt = 10;
|
||||||
|
console.log(this.play_speed, dt, num_advances);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.state === 'playing') {
|
if (this.state === 'playing') {
|
||||||
this.advance_by(1);
|
this.advance_by(num_advances);
|
||||||
}
|
}
|
||||||
else if (this.state === 'rewinding') {
|
else if (this.state === 'rewinding') {
|
||||||
if (this.level.has_undo()) {
|
if (this.level.has_undo()) {
|
||||||
// Rewind by undoing one tic every tic
|
// Rewind by undoing one tic every tic
|
||||||
|
for (let i = 0; i < num_advances; i++) {
|
||||||
this.undo();
|
this.undo();
|
||||||
|
}
|
||||||
this.update_ui();
|
this.update_ui();
|
||||||
}
|
}
|
||||||
// If there are no undo entries left, freeze in place until the player stops rewinding,
|
// If there are no undo entries left, freeze in place until the player stops rewinding,
|
||||||
@ -1064,9 +1078,6 @@ class Player extends PrimaryView {
|
|||||||
// buffer dry) and change to 'waiting' instead?
|
// buffer dry) and change to 'waiting' instead?
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME if play speed is sufficiently high, we need to advance multiple frames at once or
|
|
||||||
// the timeout will get capped
|
|
||||||
let dt = 1000 / (TICS_PER_SECOND * this.play_speed);
|
|
||||||
if (this.state === 'rewinding') {
|
if (this.state === 'rewinding') {
|
||||||
// Rewind faster than normal time
|
// Rewind faster than normal time
|
||||||
dt *= 0.5;
|
dt *= 0.5;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user