UNPKG

@lightningjs/renderer

Version:
66 lines 2.22 kB
/* * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * * Copyright 2023 Comcast Cable Communications Management, LLC. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ let fpsBoundaries = [20, 40, 60, 80, 100]; let fpsInterval = 1000; // 1 second const frameCounter = { start: 0, end: 0, total: 0, boundaries: [], count: {}, increment(frameDelta) { this.total++; const boundaries = this.boundaries; for (let i = 0; i < boundaries.length; i++) { const bucket = boundaries[i]; if (frameDelta <= bucket) { this.count[bucket]++; return; } } this.count['overflow']++; }, get averageFps() { //calculate fps based on frame count and elapsed time return (this.total / (this.end - this.start)) * 1000; }, }; export function setFpsBoundaries(newBoundaries) { // sort buckets in ascending order just in case fpsBoundaries = newBoundaries.slice().sort((a, b) => a - b); } export function setFpsInterval(newInterval) { fpsInterval = newInterval; } export function createFrameCounter(frameTime) { const counter = Object.create(frameCounter); counter.boundaries = fpsBoundaries; counter.start = frameTime; counter.end = frameTime + fpsInterval; counter.total = 0; counter.count = Object.create(null); //fill frames with 0 for each bucket for (let i = 0; i < fpsBoundaries.length; i++) { const bucket = fpsBoundaries[i]; counter.count[bucket] = 0; } counter.count['overflow'] = 0; return counter; } //# sourceMappingURL=fps.js.map