playcanvas
Version:
PlayCanvas WebGL game engine
33 lines (31 loc) • 1.08 kB
JavaScript
// Stats timer interface for graph
class StatsTimer {
get timings() {
return this.values;
}
constructor(app, statNames, decimalPlaces, unitsName, multiplier){
this.app = app;
this.values = [];
// supporting up to 3 stats
this.statNames = statNames;
if (this.statNames.length > 3) {
this.statNames.length = 3;
}
this.unitsName = unitsName;
this.decimalPlaces = decimalPlaces;
this.multiplier = multiplier || 1;
// recursively look up properties of objects specified in a string
var resolve = (path, obj)=>{
return path.split('.').reduce((prev, curr)=>{
return prev ? prev[curr] : null;
}, obj || this);
};
app.on('frameupdate', (ms)=>{
for(var i = 0; i < this.statNames.length; i++){
// read specified stat from app.stats object
this.values[i] = resolve(this.statNames[i], this.app.stats) * this.multiplier;
}
});
}
}
export { StatsTimer };