add animation frame timeout
This commit is contained in:
parent
7e2acb820e
commit
8eae25d706
|
|
@ -11,6 +11,8 @@ export class AnimationFrameController implements ReactiveController {
|
||||||
#lastTime = 0;
|
#lastTime = 0;
|
||||||
#dtAccumulator = 0;
|
#dtAccumulator = 0;
|
||||||
#fixedTimestep = 1 / 60;
|
#fixedTimestep = 1 / 60;
|
||||||
|
#timeoutMs;
|
||||||
|
#timeoutId = -1;
|
||||||
|
|
||||||
get fixedTimestep() {
|
get fixedTimestep() {
|
||||||
return this.#fixedTimestep;
|
return this.#fixedTimestep;
|
||||||
|
|
@ -21,8 +23,9 @@ export class AnimationFrameController implements ReactiveController {
|
||||||
return this.#isRunning;
|
return this.#isRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(host: AnimationFrameControllerHost) {
|
constructor(host: AnimationFrameControllerHost, timeoutMs = 5000) {
|
||||||
this.#host = host;
|
this.#host = host;
|
||||||
|
this.#timeoutMs = timeoutMs;
|
||||||
host.addController(this);
|
host.addController(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +33,11 @@ export class AnimationFrameController implements ReactiveController {
|
||||||
this.start();
|
this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
hostUpdate() {}
|
hostUpdated() {
|
||||||
|
window.clearTimeout(this.#timeoutId);
|
||||||
|
this.#timeoutId = window.setTimeout(this.stop, this.#timeoutMs);
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
|
||||||
hostDisconnected() {
|
hostDisconnected() {
|
||||||
this.stop();
|
this.stop();
|
||||||
|
|
@ -61,8 +68,9 @@ export class AnimationFrameController implements ReactiveController {
|
||||||
this.#tick();
|
this.#tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop = () => {
|
||||||
cancelAnimationFrame(this.#tick);
|
cancelAnimationFrame(this.#tick);
|
||||||
|
window.clearTimeout(this.#timeoutId);
|
||||||
this.#isRunning = false;
|
this.#isRunning = false;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue