Frame rate measurer deleted
This commit is contained in:
parent
8780d57df2
commit
3d4235766d
|
@ -1,84 +0,0 @@
|
|||
import FrameRateMeasuredEvent from "./events/FrameRateMeasuredEvent.js";
|
||||
|
||||
export default class FrameRateMeasurer
|
||||
{
|
||||
constructor(rounds = 30)
|
||||
{
|
||||
this.rounds = rounds;
|
||||
this.round = 0;
|
||||
this.lastTimestamp = undefined;
|
||||
this.frameDurations = [];
|
||||
|
||||
window.requestAnimationFrame(
|
||||
(timestamp) => {
|
||||
this.measureFrameRate(timestamp);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
measureFrameRate(timestamp)
|
||||
{
|
||||
if (this.lastTimestamp !== undefined) {
|
||||
this.round++;
|
||||
this.frameDurations.push(timestamp - this.lastTimestamp);
|
||||
|
||||
this.lastTimestamp = timestamp;
|
||||
|
||||
if (this.round < this.rounds) {
|
||||
window.requestAnimationFrame(
|
||||
(timestamp) => {
|
||||
this.measureFrameRate(timestamp);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
window.dispatchEvent(new FrameRateMeasuredEvent(this.getAverageFrameRate()));
|
||||
}
|
||||
} else {
|
||||
this.round = 0;
|
||||
this.lastTimestamp = timestamp;
|
||||
window.requestAnimationFrame(
|
||||
(timestamp) => {
|
||||
this.measureFrameRate(timestamp);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
this.lastTimestamp = timestamp
|
||||
}
|
||||
|
||||
getAverageFrameRate()
|
||||
{
|
||||
let frameDurationSum = 0;
|
||||
|
||||
this.frameDurations.forEach(
|
||||
(duration) => {
|
||||
frameDurationSum += duration;
|
||||
}
|
||||
);
|
||||
|
||||
let durationAverage = frameDurationSum / this.frameDurations.length;
|
||||
|
||||
return 1000 / durationAverage;
|
||||
}
|
||||
|
||||
getFrameRate()
|
||||
{
|
||||
const DEFAULT_FRAME_RATES = [30, 60, 120];
|
||||
|
||||
let averageFrameRate = this.getAverageFrameRate();
|
||||
let closestDistance = {frameRate: 0, distance: 99999};
|
||||
|
||||
DEFAULT_FRAME_RATES.forEach(
|
||||
(frameRate) => {
|
||||
let distance = Math.abs(frameRate - averageFrameRate);
|
||||
|
||||
if (closestDistance.distance > distance) {
|
||||
closestDistance.frameRate = frameRate;
|
||||
closestDistance.distance = distance;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return closestDistance.frameRate;
|
||||
}
|
||||
}
|
16
js/Game.js
16
js/Game.js
|
@ -8,8 +8,6 @@ import UserInterface from "./ui/UserInterface.js";
|
|||
import Key from "./Key.js";
|
||||
import Setting from "./Setting.js";
|
||||
import {EventBus} from "./events/EventBus.js";
|
||||
import InterfaceEvent from "./events/InterfaceEvent.js";
|
||||
import FrameRateMeasurer from "./FrameRateMeasurer.js";
|
||||
|
||||
|
||||
export class Game
|
||||
|
@ -18,8 +16,8 @@ export class Game
|
|||
|
||||
constructor(level) {
|
||||
this.level = level;
|
||||
this.fps = 0;
|
||||
this.frameDuration = 0;
|
||||
this.fps = 60;
|
||||
this.frameDuration = 1000.0 / this.fps;
|
||||
this.lastRendered = undefined;
|
||||
this.lastTimestamp = undefined;
|
||||
this.canvas = document.getElementById('canvas');
|
||||
|
@ -216,17 +214,9 @@ export class Game
|
|||
this.architecture.setMovableToStartPosition(this.mrCroc);
|
||||
this.architecture.setMovableToTargetPosition(this.gisela);
|
||||
|
||||
EventBus.addEventListener(
|
||||
InterfaceEvent.FRAME_RATE_MEASURED,
|
||||
(event) => {
|
||||
this.isPaused = false;
|
||||
this.fps = event.frameRate;
|
||||
this.frameDuration = 1000.0 / this.fps;
|
||||
window.requestAnimationFrame(loopFunction);
|
||||
}
|
||||
);
|
||||
|
||||
new FrameRateMeasurer();
|
||||
window.requestAnimationFrame(loopFunction);
|
||||
}
|
||||
|
||||
isChromeBrowser()
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
import InterfaceEvent from "./InterfaceEvent.js";
|
||||
|
||||
export default class FrameRateMeasuredEvent extends Event
|
||||
{
|
||||
constructor(frameRate) {
|
||||
super(InterfaceEvent.FRAME_RATE_MEASURED);
|
||||
this.frameRate = frameRate;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue