fix: drain render if backed up

This commit is contained in:
cha0s 2019-05-02 22:18:50 -05:00
parent c986aa4c8c
commit 19ff9e2293

View File

@ -70,6 +70,7 @@ export class App extends decorate(class {}) {
this.debugUiNode = undefined;
this.reactContainer = undefined;
this.lastIntensity = undefined;
this.renderDrainHandle = undefined;
this.renderHandle = undefined;
this.rps = new CycleTracker(1 / 60); // Refresh rate, actually.
this.stage = new Stage(config.visibleSize, config.visibleScale);
@ -494,7 +495,7 @@ export class App extends decorate(class {}) {
startRendering() {
let lastTime = performance.now();
this.renderHandle = setAnimation(() => {
const animate = () => {
const now = performance.now();
const elapsed = (now - lastTime) / 1000;
lastTime = now;
@ -502,7 +503,18 @@ export class App extends decorate(class {}) {
this.stage.renderTick(elapsed);
// Sample.
this.rps.sample(elapsed);
});
};
this.renderHandle = setAnimation(animate);
// Drain animation if a little time has passed. raf may never call if the
// window isn't active, which can cause major backup for any poorly-written
// renderTick implementations that do work.
this.renderDrainHandle = setInterval(() => {
const now = performance.now();
const elapsed = (now - lastTime) / 1000;
if (elapsed >= 0.1) {
animate();
}
}, 100);
}
startSimulation() {
@ -547,6 +559,8 @@ export class App extends decorate(class {}) {
stopRendering() {
clearAnimation(this.renderHandle);
this.renderHandle = undefined;
clearInterval(this.renderDrainHandle);
this.renderDrainHandle = undefined;
}
stopSimulation() {