A little more optimization
This commit is contained in:
+25
-10
@@ -5,8 +5,15 @@ import { profiler, type SectionStats } from "$/client/profiler.ts";
|
||||
import { canvas, gpu_timer, render_debug, render_stats } from "$/client/renderer/mod.ts";
|
||||
import { RENDER_LAYERS } from "$/common/everything_registry.ts";
|
||||
|
||||
// how often the totals that go through every chunk are worked out again, so the overlay doesn't slow the frames it's
|
||||
// measuring
|
||||
const CHUNK_STATS_MS = 1000;
|
||||
|
||||
// f3: every entity's fields, editable, and what frames cost
|
||||
export class DebugOverlay {
|
||||
#chunk_stats = { meshed: 0, bytes: 0 };
|
||||
#chunk_stats_time = -Infinity;
|
||||
|
||||
render(client: Client) {
|
||||
this.#render_performance(client);
|
||||
|
||||
@@ -73,17 +80,9 @@ export class DebugOverlay {
|
||||
for (const layer of RENDER_LAYERS) text(` ${layer}: ${quads[layer].toLocaleString()} quads`);
|
||||
const level = client.level;
|
||||
const level_renderer = client.game_renderer.level_renderer;
|
||||
let meshed = 0;
|
||||
let waiting = 0;
|
||||
let bytes = 0;
|
||||
for (const chunk of level.chunks.values()) {
|
||||
const meshes = Object.values(chunk.meshes);
|
||||
if (meshes.length > 0) meshed += 1;
|
||||
if (chunk.dirty) waiting += 1;
|
||||
for (const mesh of meshes) bytes += mesh.vertex_buffer.size + (mesh.index_buffer?.size ?? 0);
|
||||
}
|
||||
const { meshed, bytes } = this.#count_chunks(client);
|
||||
text(`chunks: ${level.chunks.size} loaded, ${meshed} meshed, ${level_renderer.visible_chunks} in view`);
|
||||
text(` ${waiting} waiting to mesh, ${level.meshes_in_flight} meshing`);
|
||||
text(` ${level.dirty_count} waiting to mesh, ${level.meshes_in_flight} meshing`);
|
||||
text(` meshes: ${(bytes / 1024 / 1024).toFixed(1)} MB`);
|
||||
separator();
|
||||
|
||||
@@ -99,6 +98,22 @@ export class DebugOverlay {
|
||||
}
|
||||
}
|
||||
|
||||
// meshed chunks and what their meshes take on the gpu, once a second
|
||||
#count_chunks(client: Client) {
|
||||
const now = performance.now();
|
||||
if (now - this.#chunk_stats_time < CHUNK_STATS_MS) return this.#chunk_stats;
|
||||
this.#chunk_stats_time = now;
|
||||
let meshed = 0;
|
||||
let bytes = 0;
|
||||
for (const chunk of client.level.chunks.values()) {
|
||||
const meshes = Object.values(chunk.meshes);
|
||||
if (meshes.length > 0) meshed += 1;
|
||||
for (const mesh of meshes) bytes += mesh.vertex_buffer.size + (mesh.index_buffer?.size ?? 0);
|
||||
}
|
||||
this.#chunk_stats = { meshed, bytes };
|
||||
return this.#chunk_stats;
|
||||
}
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
#render_fields(object: any) {
|
||||
for (const key in object) {
|
||||
|
||||
Reference in New Issue
Block a user