* added a shitty ecs that I'm confident is way worse than just looping objects lol * mader a rendering system based on ecs
32 lines
696 B
TypeScript
32 lines
696 B
TypeScript
import { Scene } from "./scene";
|
|
|
|
class Engine {
|
|
canvas: HTMLCanvasElement;
|
|
ctx: WebGL2RenderingContext;
|
|
scenes = [] as Scene[];
|
|
|
|
constructor(canvas: string | HTMLCanvasElement) {
|
|
/** get canvas by id */
|
|
if (typeof canvas === "string") {
|
|
canvas = document.getElementById(canvas)! as HTMLCanvasElement;
|
|
}
|
|
|
|
if (!canvas) {
|
|
throw new Error("canvas not found");
|
|
}
|
|
this.canvas = canvas;
|
|
this.ctx = canvas.getContext("webgl2")!;
|
|
if (!this.ctx) {
|
|
throw new Error("can't get webgl2 context");
|
|
}
|
|
}
|
|
|
|
createScene() {
|
|
const scene = new Scene(this.canvas, this.ctx);
|
|
this.scenes.push(scene);
|
|
return scene;
|
|
}
|
|
}
|
|
|
|
export { Engine };
|