Add counters
This commit is contained in:
parent
52799a6bf0
commit
12fa81c3ed
3 changed files with 31 additions and 3 deletions
|
|
@ -36,6 +36,8 @@
|
||||||
<section class="errors-container">
|
<section class="errors-container">
|
||||||
<noscript>JavaScript is required for this website.</noscript>
|
<noscript>JavaScript is required for this website.</noscript>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<div class="counters"><pre></pre></div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<aside>
|
<aside>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
color: var(--very-light-text-color);
|
||||||
|
|
||||||
@media (prefers-reduced-motion) {
|
@media (prefers-reduced-motion) {
|
||||||
transition: none !important;
|
transition: none !important;
|
||||||
|
|
@ -51,7 +52,6 @@ html {
|
||||||
}
|
}
|
||||||
|
|
||||||
> .errors-container {
|
> .errors-container {
|
||||||
color: red;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|
@ -59,12 +59,26 @@ html {
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.counters {
|
||||||
|
@include blurred-background(white);
|
||||||
|
position: absolute;
|
||||||
|
top: var(--normal-margin);
|
||||||
|
right: var(--normal-margin);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
padding: var(--small-margin);
|
||||||
|
|
||||||
|
pre {
|
||||||
|
color: black;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
> aside {
|
> aside {
|
||||||
@include blurred-background;
|
@include blurred-background(#777);
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
|
|
|
||||||
14
src/index.ts
14
src/index.ts
|
|
@ -5,6 +5,7 @@ import { FullScreenHandler } from './page/full-screen-handler';
|
||||||
import { InfoPageHandler } from './page/info-page-handler';
|
import { InfoPageHandler } from './page/info-page-handler';
|
||||||
import { MenuHider } from './page/menu-hider';
|
import { MenuHider } from './page/menu-hider';
|
||||||
import { applyArrayPlugins } from './utils/array';
|
import { applyArrayPlugins } from './utils/array';
|
||||||
|
import { DeltaTimeCalculator } from './utils/delta-time-calculator';
|
||||||
import { ErrorHandler, Severity } from './utils/error-handler';
|
import { ErrorHandler, Severity } from './utils/error-handler';
|
||||||
import { initializeGpu } from './utils/graphics/initialize-gpu';
|
import { initializeGpu } from './utils/graphics/initialize-gpu';
|
||||||
|
|
||||||
|
|
@ -39,6 +40,7 @@ const getElements = () => ({
|
||||||
canvas: document.querySelector('canvas') as HTMLCanvasElement,
|
canvas: document.querySelector('canvas') as HTMLCanvasElement,
|
||||||
canvasContainer: document.querySelector('main.canvas-container') as HTMLCanvasElement,
|
canvasContainer: document.querySelector('main.canvas-container') as HTMLCanvasElement,
|
||||||
errorContainer: document.querySelector('.errors-container') as HTMLDivElement,
|
errorContainer: document.querySelector('.errors-container') as HTMLDivElement,
|
||||||
|
counters: document.querySelector('.counters > pre') as HTMLPreElement,
|
||||||
});
|
});
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
|
|
@ -70,8 +72,18 @@ const main = async () => {
|
||||||
|
|
||||||
elements.restartButton.addEventListener('click', () => game?.destroy());
|
elements.restartButton.addEventListener('click', () => game?.destroy());
|
||||||
|
|
||||||
|
const deltaTimeCalculator = new DeltaTimeCalculator();
|
||||||
|
|
||||||
|
const updateCounters = () => {
|
||||||
|
elements.counters.innerHTML = `FPS: ${deltaTimeCalculator.fps.toFixed(2)}
|
||||||
|
Gen1: ${game?.aliveAgentCounts.currentGenerationCount ?? 0}
|
||||||
|
Gen2: ${game?.aliveAgentCounts.nextGenerationCount ?? 0}`;
|
||||||
|
window.requestAnimationFrame(updateCounters);
|
||||||
|
};
|
||||||
|
updateCounters();
|
||||||
|
|
||||||
while (!shouldStop) {
|
while (!shouldStop) {
|
||||||
game = new GameLoop(elements.canvas, gpu);
|
game = new GameLoop(elements.canvas, gpu, deltaTimeCalculator);
|
||||||
await game.start();
|
await game.start();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue