optimize Behavior automounting
This commit is contained in:
parent
433d9505ff
commit
eb19d95eee
7 changed files with 18 additions and 17 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
5
html/chunk-818093f0cbbefec3.js
Normal file
5
html/chunk-818093f0cbbefec3.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
class L{d;constructor(d){this.app=d;this.onStart&&d.onStart(this.onStart.bind(this)),this.onUpdate&&d.onUpdate(this.onUpdate.bind(this)),this.onAfterUpdate&&d.onAfterUpdate(this.onAfterUpdate.bind(this)),this.onBeforeUpdate&&d.onBeforeUpdate(this.onBeforeUpdate.bind(this))}}class h extends L{d;el;frameTimes=[];maxFrameTimes=100;lastFrameTime=0;constructor(d,n="#telemetry"){super(d);this.app=d;if(this.el=document.querySelector(n),this.el&&location.search.includes("telemetry"))this.el.style.display="block"}insertTime(d){if(this.frameTimes.push(d),this.frameTimes.length>this.maxFrameTimes)this.frameTimes.shift()}onStart(){this.lastFrameTime=0,this.frameTimes=[],setInterval(()=>{const d=this.frameTimes.reduce((U,c)=>U+c,0)/this.frameTimes.length,n=1000/d;this.el.innerHTML=`
|
||||
${n.toFixed(1)} FPS (${d.toFixed(3)} ms)<br />
|
||||
bU: ${this.app.registry.onBeforeUpdate.length} | U: ${this.app.registry.onUpdate.length} | aU: ${this.app.registry.onAfterUpdate.length}
|
||||
`},1000)}onAfterUpdate(d){const n=d-this.lastFrameTime;this.insertTime(n),this.lastFrameTime=d}}
|
||||
export{L as a,h as b};
|
|
@ -1,5 +0,0 @@
|
|||
class n{U;constructor(U){this.app=U;this.onBeforeUpdate&&U.onBeforeUpdate(this.onBeforeUpdate.bind(this)),this.onUpdate&&U.onUpdate(this.onUpdate.bind(this)),this.onAfterUpdate&&U.onAfterUpdate(this.onAfterUpdate.bind(this)),this.onStart&&U.onStart(this.onStart.bind(this))}onStart(U){}onBeforeUpdate(U){}onUpdate(U){}onAfterUpdate(U){}}class k extends n{U;el;frameTimes=[];maxFrameTimes=100;lastFrameTime=0;constructor(U,h="#telemetry"){super(U);this.app=U;if(this.el=document.querySelector(h),this.el&&location.search.includes("telemetry"))this.el.style.display="block"}insertTime(U){if(this.frameTimes.push(U),this.frameTimes.length>this.maxFrameTimes)this.frameTimes.shift()}onStart(){this.lastFrameTime=0,this.frameTimes=[],setInterval(()=>{const U=this.frameTimes.reduce((L,j)=>L+j,0)/this.frameTimes.length,h=1000/U;this.el.innerHTML=`
|
||||
${h.toFixed(1)} FPS (${U.toFixed(3)} ms)<br />
|
||||
bU: ${this.app.registry.onBeforeUpdate.length} | U: ${this.app.registry.onUpdate.length} | aU: ${this.app.registry.onAfterUpdate.length}
|
||||
`},1000)}onAfterUpdate(U){const h=U-this.lastFrameTime;this.insertTime(h),this.lastFrameTime=U}}
|
||||
export{n as a,k as b};
|
|
@ -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) {}
|
||||
}
|
||||
|
|
|
@ -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) {}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue