playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
31 lines (29 loc) • 830 B
JavaScript
class StatsTimer {
get timings() {
return this.values;
}
constructor(app, statNames, decimalPlaces, unitsName, multiplier){
this.app = app;
this.values = [];
this.statNames = statNames;
this.unitsName = unitsName;
this.decimalPlaces = decimalPlaces;
this.multiplier = multiplier || 1;
const resolve = (path, obj)=>{
return path.split('.').reduce((prev, curr)=>{
if (!prev) return null;
if (prev instanceof Map) {
return prev.get(curr);
}
return prev[curr];
}, obj || this);
};
app.on('frameupdate', (ms)=>{
for(let i = 0; i < this.statNames.length; i++){
const value = resolve(this.statNames[i], this.app.stats);
this.values[i] = (value ?? 0) * this.multiplier;
}
});
}
}
export { StatsTimer };