|
@@ -8,14 +8,15 @@ class render_engine {
|
|
|
#canvas;
|
|
#canvas;
|
|
|
#actors;
|
|
#actors;
|
|
|
#player;
|
|
#player;
|
|
|
|
|
+ #looped;
|
|
|
|
|
|
|
|
constructor(canvas, context, player) {
|
|
constructor(canvas, context, player) {
|
|
|
if (!(canvas instanceof HTMLCanvasElement)) {
|
|
if (!(canvas instanceof HTMLCanvasElement)) {
|
|
|
throw new TypeError("Canvas must be an HTMLCanvasElement.");
|
|
throw new TypeError("Canvas must be an HTMLCanvasElement.");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(context instanceof WebGL2RenderingContext)) {
|
|
|
|
|
- throw new TypeError("Context must be WebGL2 RenderingContext.");
|
|
|
|
|
|
|
+ if (!(context instanceof WebGLRenderingContext)) {
|
|
|
|
|
+ throw new TypeError("Context must be WebGL RenderingContext.");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!(player instanceof actor)) {
|
|
if (!(player instanceof actor)) {
|
|
@@ -59,11 +60,20 @@ class render_engine {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
run() {
|
|
run() {
|
|
|
|
|
+ this.#looped = true;
|
|
|
this.#init();
|
|
this.#init();
|
|
|
this.#loop();
|
|
this.#loop();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ stop() {
|
|
|
|
|
+ this.#looped = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#loop() {
|
|
#loop() {
|
|
|
|
|
+ if (!this.#looped) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const start = performance.now();
|
|
const start = performance.now();
|
|
|
this.#render();
|
|
this.#render();
|
|
|
const stop = performance.now();
|
|
const stop = performance.now();
|