optimize Behavior automounting

This commit is contained in:
41666 2023-10-08 00:32:46 -04:00
parent 433d9505ff
commit eb19d95eee
7 changed files with 18 additions and 17 deletions

View file

@ -1,15 +1,14 @@
import { WebGPUApp } from "./webgpu";
export abstract class Behavior {
onStart?(...args: any[]): void;
onBeforeUpdate?(...args: any[]): void;
onUpdate?(...args: any[]): void;
onAfterUpdate?(...args: any[]): void;
constructor(public app: WebGPUApp) {
this.onBeforeUpdate && app.onBeforeUpdate(this.onBeforeUpdate.bind(this));
this.onStart && app.onStart(this.onStart.bind(this));
this.onUpdate && app.onUpdate(this.onUpdate.bind(this));
this.onAfterUpdate && app.onAfterUpdate(this.onAfterUpdate.bind(this));
this.onStart && app.onStart(this.onStart.bind(this));
this.onBeforeUpdate && app.onBeforeUpdate(this.onBeforeUpdate.bind(this));
}
onStart(time: number) {}
onBeforeUpdate(time: number) {}
onUpdate(time: number) {}
onAfterUpdate(time: number) {}
}

View file

@ -16,9 +16,11 @@ export class MeshRenderer extends Behavior {
) {
super(app);
}
onStart() {
override onStart() {
console.log("hello from meshrenderer!");
console.log(`i've got a ${this.mesh.constructor.name}`);
}
onUpdate(time: number) {}
override onUpdate(time: number) {}
}

View file

@ -121,7 +121,7 @@ export class WebGPUApp {
}
doStart(time: number = 0) {
this.registry.onStart.forEach((handle) => handle(this, time));
this.registry.onStart.forEach((handle) => handle(time, this));
}
async oneShot(time: number = 0) {