@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
28 lines (27 loc) • 796 B
JavaScript
"use strict";
import { DESIRED_FPS } from "../../scene/utils/TimeController";
function _round(perf) {
return Math.round(perf * 10);
}
export class ViewerPerformanceMonitor {
constructor(viewer) {
this.viewer = viewer;
this._accumulatedDelta = 0;
this._framesCount = 0;
this._lastRoundedPerf = _round(1);
}
measurePerformance(delta) {
this._accumulatedDelta += delta;
if (this._accumulatedDelta >= 1) {
const perf = this._framesCount / DESIRED_FPS;
const roundedPerf = _round(perf);
if (roundedPerf != this._lastRoundedPerf) {
this._lastRoundedPerf = roundedPerf;
this.viewer.scene().perfMonitor.onPerformanceChange(perf);
}
this._framesCount = 0;
this._accumulatedDelta = 0;
}
this._framesCount++;
}
}