Benchmark

This commit is contained in:
2026-10-28 11:42:58 -03:00
parent e5221ba681
commit 8fc08ab41e
15 changed files with 1356 additions and 41 deletions
+18 -7
View File
@@ -28,6 +28,7 @@ import { PLAYER_MENU } from "$/common/protocol.ts";
import { type BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
import type { EntityJson } from "$/common/mod_data.ts";
import { tick_texture_animations } from "./texture_animations.ts";
import type { RenderBenchmark } from "./benchmark/benchmark.ts";
// holding the use button uses the held item on blocks again this often, like minecraft's 4 ticks
const USE_REPEAT_MS = 200;
@@ -55,6 +56,8 @@ export class Client {
// the entity or other player being looked at, closer than any block. hit_result is undefined then
entity_hit: Entity | undefined;
debugging = false;
// started from the f3 performance window
benchmark: RenderBenchmark | undefined;
// seconds of game time not ticked yet
#pending_time = 0;
@@ -143,21 +146,28 @@ export class Client {
InputManager.set_mouse_grabbed(false);
}
// one frame: input, as many ticks as are due, then drawing between the last tick and the next
// one frame: input, as many ticks as are due, then drawing between the last tick and the next. while the benchmark
// runs, it ticks and draws its own level instead and the world waits, so what's around the player doesn't change
// its numbers
run_frame(delta: number) {
if (this.#stopped) {
return;
}
const screen = this.screen;
this.screen?.on_tick(delta);
// a screen that closed itself just now, like chat on enter, had this frame's keys
this.#handle_keybinds(screen !== undefined && this.screen === undefined);
if (this.benchmark) {
this.benchmark.frame();
} else {
const screen = this.screen;
this.screen?.on_tick(delta);
// a screen that closed itself just now, like chat on enter, had this frame's keys
this.#handle_keybinds(screen !== undefined && this.screen === undefined);
}
this.#pending_time += delta;
let ticks = 0;
const stopped = profiler.section("ticks", () => {
while (this.#pending_time >= TICK_DELTA && ticks < MAX_TICKS_PER_FRAME) {
this.tick();
if (this.benchmark) this.benchmark.tick();
else this.tick();
if (this.#stopped) {
return true;
}
@@ -173,7 +183,8 @@ export class Client {
this.#pending_time = Math.min(this.#pending_time, TICK_DELTA);
}
this.game_renderer.render(this, this.#pending_time / TICK_DELTA);
if (this.benchmark) this.benchmark.render(this.#pending_time / TICK_DELTA);
else this.game_renderer.render(this, this.#pending_time / TICK_DELTA);
}
// one step of the game: what the server sent (chunks included), breaking, then every entity