Fixed bug in code that starts/stops renderers when not visible.

This commit is contained in:
Daan Vanden Bosch 2019-08-21 22:29:20 +02:00
parent dbd5dba682
commit 18a8ac1ad6
2 changed files with 10 additions and 11 deletions

View File

@ -10,8 +10,9 @@ const TOOLS: [GuiTool, string][] = [
]; ];
export class NavigationView extends View { export class NavigationView extends View {
element = create_el("div", "application_NavigationView"); readonly element = create_el("div", "application_NavigationView");
height = 30;
readonly height = 30;
private buttons = new Map<GuiTool, ToolButton>( private buttons = new Map<GuiTool, ToolButton>(
TOOLS.map(([value, text]) => [value, this.disposable(new ToolButton(value, text))]), TOOLS.map(([value, text]) => [value, this.disposable(new ToolButton(value, text))]),

View File

@ -41,7 +41,7 @@ export abstract class Renderer implements Disposable {
private renderer = new WebGLRenderer({ antialias: true }); private renderer = new WebGLRenderer({ antialias: true });
private render_scheduled = false; private render_scheduled = false;
private render_stop_scheduled = false; private animation_frame_handle?: number = undefined;
private light = new HemisphereLight(0xffffff, 0x505050, 1.2); private light = new HemisphereLight(0xffffff, 0x505050, 1.2);
private controls_clock = new Clock(); private controls_clock = new Clock();
@ -81,11 +81,14 @@ export abstract class Renderer implements Disposable {
start_rendering(): void { start_rendering(): void {
this.schedule_render(); this.schedule_render();
requestAnimationFrame(this.call_render); this.animation_frame_handle = requestAnimationFrame(this.call_render);
} }
stop_rendering(): void { stop_rendering(): void {
this.render_stop_scheduled = true; if (this.animation_frame_handle != undefined) {
cancelAnimationFrame(this.animation_frame_handle);
this.animation_frame_handle = undefined;
}
} }
schedule_render = () => { schedule_render = () => {
@ -121,15 +124,10 @@ export abstract class Renderer implements Disposable {
this.render_scheduled = false; this.render_scheduled = false;
if (this.render_stop_scheduled) {
this.render_stop_scheduled = false;
return;
}
if (should_render) { if (should_render) {
this.render(); this.render();
} }
requestAnimationFrame(this.call_render); this.animation_frame_handle = requestAnimationFrame(this.call_render);
}; };
} }