@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.31 kB
JavaScript
class t{constructor(t,e,s,i,h){this.app=e,this.name=t,this.device=e.graphicsDevice,this.timer=h,this.watermark=s,this.enabled=!1,this.textRefreshRate=i,this.avgTotal=0,this.avgTimer=0,this.avgCount=0,this.timingText="",this.texture=null,this.yOffset=0,this.cursor=0,this.sample=new Uint8ClampedArray(4),this.sample.set([0,0,0,255]),this.counter=0,this.app.on("frameupdate",this.update,this)}destroy(){this.app.off("frameupdate",this.update,this)}loseContext(){this.timer&&"function"==typeof this.timer.loseContext&&this.timer.loseContext()}update(t){const e=this.timer.timings,s=e.reduce(((t,e)=>t+e),0);if(this.avgTotal+=s,this.avgTimer+=t,this.avgCount++,this.avgTimer>this.textRefreshRate&&(this.timingText=(this.avgTotal/this.avgCount).toFixed(this.timer.decimalPlaces),this.avgTimer=0,this.avgTotal=0,this.avgCount=0),this.enabled){let t=0;const s=1.5*this.watermark;for(let i=0;i<e.length;++i)t+=Math.floor(e[i]/s*255),this.sample[i]=t;this.sample[3]=this.watermark/s*255;this.texture.lock().set(this.sample,4*(this.cursor+this.yOffset*this.texture.width)),this.texture.unlock(),this.cursor++,this.cursor===this.texture.width&&(this.cursor=0)}}render(t,e,s,i,h){t.quad(e+i,s,-i,h,this.enabled?this.cursor:0,this.enabled?.5+this.yOffset:this.texture.height-1,-i,0,this.texture,0)}}export{t as Graph};