Better stats.

This commit is contained in:
Will Scullin 2019-12-30 11:13:35 -08:00
parent f75a2fa962
commit d15979d67e
No known key found for this signature in database
GPG Key ID: 9092A5C0A673416B
4 changed files with 28 additions and 12 deletions

View File

@ -83,7 +83,7 @@
<div style="clear: both"></div>
</div>
<div class="inset">
<div id="khz" onclick="Apple2.toggleShowFPS()">0KHz</div>
<div id="khz" onclick="Apple2.toggleShowFPS()">0 kHz</div>
<button id="pause-run" onclick="Apple2.pauseRun()" title="Pause/Run">
<i class="fas fa-pause"></i>
</button>

View File

@ -86,7 +86,7 @@
</div>
<div style="position: relative">
<div id="controls" class="inset">
<div id="khz" onclick="Apple2.toggleShowFPS()">0KHz</div>
<div id="khz" onclick="Apple2.toggleShowFPS()">0 kHz</div>
<button id="pause-run" onclick="Apple2.pauseRun()">
<i class="fas fa-pause"></i>
</button>

View File

@ -9,6 +9,7 @@ import SYMBOLS from './symbols';
export function Apple2(options) {
var stats = {
frames: 0,
renderedFrames: 0
};
@ -115,6 +116,7 @@ export function Apple2(options) {
stats.renderedFrames++;
}
}
stats.frames++;
io.tick();
options.tick();

View File

@ -17,6 +17,7 @@ var focused = false;
var startTime = Date.now();
var lastCycles = 0;
var lastFrames = 0;
var lastRenderedFrames = 0;
var hashtag;
@ -267,31 +268,44 @@ function openManage() {
}
var prefs = new Prefs();
var showFPS = false;
var showStats = 0;
export function updateKHz() {
var now = Date.now();
var ms = now - startTime;
var cycles = cpu.cycles();
var delta;
var fps;
var khz;
if (showFPS) {
delta = stats.renderedFrames - lastFrames;
var fps = parseInt(delta/(ms/1000), 10);
document.querySelector('#khz').innerText = fps + 'fps';
} else {
switch (showStats) {
case 0: {
delta = cycles - lastCycles;
var khz = parseInt(delta/ms);
document.querySelector('#khz').innerText = khz + 'KHz';
khz = parseInt(delta/ms);
document.querySelector('#khz').innerText = khz + ' kHz';
break;
}
case 1: {
delta = stats.renderedFrames - lastRenderedFrames;
fps = parseInt(delta/(ms/1000), 10);
document.querySelector('#khz').innerText = fps + ' rps';
break;
}
default: {
delta = stats.frames - lastFrames;
fps = parseInt(delta/(ms/1000), 10);
document.querySelector('#khz').innerText = fps + ' fps';
}
}
startTime = now;
lastCycles = cycles;
lastFrames = stats.renderedFrames;
lastRenderedFrames = stats.renderedFrames;
lastFrames = stats.frames;
}
export function toggleShowFPS() {
showFPS = !showFPS;
showStats = ++showStats % 3;
}
export function updateSound() {