Make benchmark work on native

This commit is contained in:
2026-11-23 20:01:25 -03:00
parent 90dd86b336
commit ced27d3400
5 changed files with 21 additions and 17 deletions
+9 -10
View File
@@ -13,6 +13,7 @@ import type { GameRenderer } from "@/client/rendering/game_renderer.ts";
import { block_visuals } from "@/client/rendering/visuals.ts";
import { draw_item } from "@/client/rendering/render_utils.ts";
import { InputManager } from "@/client/input_manager.ts";
import { platform } from "@/client/platform.ts";
import { type FrameSample, profiler } from "@/client/profiler.ts";
import { RemotePlayer } from "@/client/entity/remote_player.ts";
import { RemoteEntity } from "@/client/entity/remote_entity.ts";
@@ -129,8 +130,9 @@ export class RenderBenchmark {
// a line of names for each row of the gui scene's slots
#gui_lines: string[];
#system: SystemInfo;
// the page was hidden, which stops frames
// the game was hidden, which held frames back
#hidden = false;
#stop_watching_shown: () => void;
#saved_debug = { ...render_debug };
#saved_draw: Record<string, boolean>;
@@ -157,7 +159,7 @@ export class RenderBenchmark {
for (const key of Object.keys(draw) as (keyof typeof draw)[]) draw[key] = true;
Object.assign(render_debug, { msaa: false, split_passes: false, uncapped: false });
set_canvas_size(RESOLUTION);
document.addEventListener("visibilitychange", this.#on_visibility);
this.#stop_watching_shown = platform.on_shown(() => this.#hidden = true);
this.#flow = this.#run();
}
@@ -167,7 +169,7 @@ export class RenderBenchmark {
if (InputManager.is_key_pressed("Escape")) {
this.#end("The benchmark was stopped");
} else if (this.#hidden) {
this.#end("The benchmark stopped since the page was hidden, which holds frames back");
this.#end("The benchmark stopped since the game was hidden, which holds frames back");
} else {
this.#flow.next();
}
@@ -216,14 +218,10 @@ export class RenderBenchmark {
set_canvas_size(undefined);
profiler.samples = undefined;
if (gpu_timer) gpu_timer.samples = undefined;
document.removeEventListener("visibilitychange", this.#on_visibility);
this.#stop_watching_shown();
this.#on_end(result);
}
#on_visibility = () => {
if (document.hidden) this.#hidden = true;
};
// the whole benchmark, a frame at each yield
*#run(): Generator<void, void> {
yield* this.#build();
@@ -559,8 +557,9 @@ function system_info(workers: number): SystemInfo {
gpu_features: [...device.features].sort(),
timestamps: gpu_timer?.supported ?? false,
canvas_format: navigator.gpu.getPreferredCanvasFormat(),
device_pixel_ratio: devicePixelRatio,
screen: `${screen.width}x${screen.height}`,
// the desktop app's window is drawn a pixel to a pixel
device_pixel_ratio: globalThis.devicePixelRatio ?? 1,
screen: globalThis.screen && `${screen.width}x${screen.height}`,
workers,
};
const hints = (navigator as { userAgentData?: UserAgentData }).userAgentData;
+2 -1
View File
@@ -62,7 +62,8 @@ export interface SystemInfo {
// the median fps where nothing is drawn, which is the display's refresh when the browser holds frames to it
refresh_hz?: number;
device_pixel_ratio: number;
screen: string;
// the browser's, the desktop app doesn't know it
screen?: string;
// meshing workers, see ChunkWorkerPool
workers: number;
}