mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
Fix a problem where sometimes the emulator would run too fast (#34)
Before, when using `requestAnimationFrame`, the emulator did not save the id returned by the browser. This broke the invariant of `run`, namely that on exit either `runAnimationFrame` or `runTimer` would be set. This meant that sometimes when the emulator restarted, there would be two callbacks to `requetsAnimationFrame` run on every frame. Now the id is saved correctly and the invariant of `run` is maintained.
This commit is contained in:
parent
94d146203a
commit
a200d6de83
@ -67,6 +67,11 @@ export function Apple2(options) {
|
|||||||
window.webkitCancelAnimationFrame ||
|
window.webkitCancelAnimationFrame ||
|
||||||
window.msCancelAnimationFrame;
|
window.msCancelAnimationFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the emulator. If the emulator is already running, this does
|
||||||
|
* nothing. When this function exits either `runTimer` or
|
||||||
|
* `runAnimationFrame` will be non-null.
|
||||||
|
*/
|
||||||
function run() {
|
function run() {
|
||||||
if (runTimer || runAnimationFrame) {
|
if (runTimer || runAnimationFrame) {
|
||||||
return; // already running
|
return; // already running
|
||||||
@ -125,7 +130,7 @@ export function Apple2(options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (_requestAnimationFrame) {
|
if (_requestAnimationFrame) {
|
||||||
_requestAnimationFrame(runFn);
|
runAnimationFrame = _requestAnimationFrame(runFn);
|
||||||
} else {
|
} else {
|
||||||
runTimer = setInterval(runFn, interval);
|
runTimer = setInterval(runFn, interval);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user