playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
32 lines (31 loc) • 772 B
JavaScript
class StatsTimer {
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;
}
});
}
get timings() {
return this.values;
}
}
export {
StatsTimer
};