added a shitty ecs that I'm confident is way worse than just looping … (#4)
* added a shitty ecs that I'm confident is way worse than just looping objects lol * mader a rendering system based on ecs
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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 };
|
||||
Reference in New Issue
Block a user