summaryrefslogtreecommitdiffstats
path: root/site/main.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-12-22 15:48:50 -0500
committerBrian Cully <bjc@spork.org>2025-12-22 15:48:50 -0500
commit0dd46263395c1cc7a879b4305766776f00c21bb5 (patch)
tree1e6592e327a162f6e17d9a96a1466470655ccd9a /site/main.mjs
parente083a6720227e8cf2b03b94110607f9d5a50e1b6 (diff)
downloadautomathon-0dd46263395c1cc7a879b4305766776f00c21bb5.tar.gz
automathon-0dd46263395c1cc7a879b4305766776f00c21bb5.zip
html: add fps counter
Diffstat (limited to 'site/main.mjs')
-rw-r--r--site/main.mjs8
1 files changed, 6 insertions, 2 deletions
diff --git a/site/main.mjs b/site/main.mjs
index 859b8d0..626a6b4 100644
--- a/site/main.mjs
+++ b/site/main.mjs
@@ -8,6 +8,7 @@ const TICK_BUTTON_SELECTOR = '#tick';
const TICK_RATE_SELECTOR = '#tick-rate-select';
const BENCH_BUTTON_SELECTOR = '#bench';
const BLINKEN_BUTTON_SELECTOR = '#blinken';
+const FPS_SELECTOR = '#fps';
// one per bot
const SRC_SELECT_SELECTOR = '#src-select';
@@ -101,7 +102,7 @@ function clamp(radius, x, y, width, height) {
function renderRobo(ctx, x, y) {
ctx.fillStyle = 'rgb(200 0 0)';
ctx.beginPath();
- ctx.arc(x, y, 25, 0, 2 * Math.PI);
+ ctx.arc(Math.floor(x), Math.floor(y), 25, 0, 2 * Math.PI);
ctx.fill();
}
@@ -271,10 +272,13 @@ async function loaded() {
// we often get called with the same time stamp many times
// in a row due to fingerprint-reduction tech.
- if (t > lastTime) {
+ const ms = t - lastTime;
+ if (ms > 0) {
lastTime = t;
const delta = robo.lastTick ? t - robo.lastTick : 0;
renderArena([robo], delta);
+ const fps = document.querySelector(FPS_SELECTOR);
+ fps.textContent = ms > 0 ? Math.floor(1_000 / ms) : '0';
}
}