replay-viewer
Version:
Rocket League replay viewer React component and tooling
64 lines • 2.34 kB
JavaScript
import { Panel } from "./Panel";
var Stats = /** @class */ (function () {
function Stats() {
this.mode = 0;
var scope = this;
this.dom = document.createElement("div");
scope.dom.style.cssText =
"position:absolute;top:-48px;left:0;cursor:pointer;opacity:0.9;z-index:10000";
scope.dom.addEventListener("click", function (event) {
event.preventDefault();
scope.showPanel(++scope.mode % scope.dom.children.length);
}, false);
this.beginTime = (performance || Date).now();
this.prevTime = this.beginTime;
this.frames = 0;
this.fpsPanel = this.addPanel(new Panel("FPS", "#0ff", "#002"));
this.msPanel = this.addPanel(new Panel("MS", "#0f0", "#020"));
if (self.performance && self.performance.memory) {
this.memPanel = this.addPanel(new Panel("MB", "#f08", "#201"));
}
this.showPanel(0);
}
Stats.prototype.addPanel = function (panel) {
this.dom.appendChild(panel.dom);
return panel;
};
/**
* 0: fps, 1: ms, 2: mb, 3+: custom
* @param id number referenced above
*/
Stats.prototype.showPanel = function (id) {
for (var i = 0; i < this.dom.children.length; i++) {
var child = this.dom.children[i];
if (child.style) {
child.style.display = i === id ? "block" : "none";
}
}
this.mode = id;
};
Stats.prototype.begin = function () {
this.beginTime = (performance || Date).now();
};
Stats.prototype.end = function () {
this.frames++;
var time = (performance || Date).now();
this.msPanel.update(time - this.beginTime, 200);
if (time > this.prevTime + 1000) {
this.fpsPanel.update((this.frames * 1000) / (time - this.prevTime), 100);
this.prevTime = time;
this.frames = 0;
if (this.memPanel) {
var memory = performance.memory;
this.memPanel.update(memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576);
}
}
return time;
};
Stats.prototype.update = function () {
this.beginTime = this.end();
};
return Stats;
}());
export { Stats };
//# sourceMappingURL=Stats.js.map