Files
yawn/core/renderer/engine.ts
T
Heaust Azure 9d2bf4055d 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
2025-05-06 18:53:21 +05:30

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 };