UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

61 lines 2.19 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.FpsTracker = void 0; /** @packageDocumentation * @module Widgets */ const core_frontend_1 = require("@itwin/core-frontend"); const CheckBox_1 = require("../ui/CheckBox"); /** Displays average frames-per-second. * NOTE: Enabling fps tracking causes a new frame to render on every tick of the render loop, which may negatively impact battery life. * @beta */ class FpsTracker { _label; _metrics; _curIntervalId; _vp; constructor(parent, viewport) { this._vp = viewport; this._label = (0, CheckBox_1.createCheckBox)({ parent, name: "Track FPS", id: "fpsTracker_toggle", handler: (cb) => this.toggle(cb.checked), }).label; } [Symbol.dispose]() { this.toggle(false); } clearInterval() { if (undefined !== this._curIntervalId) { window.clearInterval(this._curIntervalId); this._curIntervalId = undefined; } } toggle(enabled) { this._vp.continuousRendering = enabled; if (enabled) { this._metrics = new core_frontend_1.PerformanceMetrics(false, true); this._curIntervalId = window.setInterval(() => this.updateFPS(), 500); this._label.innerText = "Tracking FPS..."; } else { this._metrics = undefined; this.clearInterval(); this._label.innerText = "Track FPS"; } this._vp.target.performanceMetrics = this._metrics; } updateFPS() { const metrics = this._metrics; const fps = (metrics.spfTimes.length / metrics.spfSum).toFixed(2); this._label.innerText = `FPS: ${fps}`; } } exports.FpsTracker = FpsTracker; //# sourceMappingURL=FpsTracker.js.map