Repository navigation
Show renderer stats with I, link home from the pause screen, new favicon #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
29e1133
feat: show renderer.info draws, triangles and memory with I
valuecodes 97f4ac6
fix: address review findings
valuecodes 6aaf6be
feat: link home from the pause screen and use a backrooms favicon
valuecodes 776a706
fix: address PR review feedback
valuecodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * A value handed from the render loop to the overlays without rendering the | ||
| * app (which would re-render the whole scene): the loop publishes, an open | ||
| * overlay subscribes through `useSyncExternalStore`. | ||
| */ | ||
| type Feed<T> = { | ||
| readonly publish: (value: T) => void; | ||
| readonly subscribe: (listener: () => void) => () => void; | ||
| /** The latest value, the same object until the next publish. */ | ||
| readonly get: () => T | null; | ||
| /** Forgets the latest value, so a stale one is never shown. */ | ||
| readonly clear: () => void; | ||
| }; | ||
|
|
||
| const createFeed = <T>(): Feed<T> => { | ||
| let latest: T | null = null; | ||
| const listeners = new Set<() => void>(); | ||
| const set = (value: T | null) => { | ||
| latest = value; | ||
| for (const listener of listeners) { | ||
| listener(); | ||
| } | ||
| }; | ||
| return { | ||
| publish: set, | ||
| clear: () => set(null), | ||
| subscribe: (listener) => { | ||
| listeners.add(listener); | ||
| return () => { | ||
| listeners.delete(listener); | ||
| }; | ||
| }, | ||
| get: () => latest, | ||
| }; | ||
| }; | ||
|
|
||
| export { createFeed }; | ||
| export type { Feed }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,12 @@ | ||
| import type { Placement } from "@repo/types"; | ||
|
|
||
| /** | ||
| * Where the player is, handed from the render loop to the overview map | ||
| * without rendering the app (which would re-render the whole scene): the | ||
| * Player publishes, the open map subscribes through `useSyncExternalStore`. | ||
| */ | ||
| type PoseFeed = { | ||
| readonly publish: (pose: Placement) => void; | ||
| readonly subscribe: (listener: () => void) => () => void; | ||
| /** The latest pose, the same object until the next publish. */ | ||
| readonly get: () => Placement | null; | ||
| }; | ||
| import { createFeed } from "~/feed"; | ||
| import type { Feed } from "~/feed"; | ||
|
|
||
| const createPoseFeed = (): PoseFeed => { | ||
| let latest: Placement | null = null; | ||
| const listeners = new Set<() => void>(); | ||
| return { | ||
| publish: (pose) => { | ||
| latest = pose; | ||
| for (const listener of listeners) { | ||
| listener(); | ||
| } | ||
| }, | ||
| subscribe: (listener) => { | ||
| listeners.add(listener); | ||
| return () => { | ||
| listeners.delete(listener); | ||
| }; | ||
| }, | ||
| get: () => latest, | ||
| }; | ||
| }; | ||
| /** Where the player is: the Player publishes, the open maps subscribe. */ | ||
| type PoseFeed = Feed<Placement>; | ||
|
|
||
| const createPoseFeed = (): PoseFeed => createFeed<Placement>(); | ||
|
|
||
| export { createPoseFeed }; | ||
| export type { PoseFeed }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ const WORLD_KEYS: readonly string[] = [ | |
| "code", | ||
| "eager", | ||
| "view", | ||
| "stats", | ||
| ]; | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { RenderSample } from "@repo/renderer/stats"; | ||
| import { useSyncExternalStore } from "react"; | ||
|
|
||
| import type { Feed } from "~/feed"; | ||
| import { statsText } from "~/stats-text"; | ||
|
|
||
| type StatsLineProps = { | ||
| /** Filled from the render loop about twice a second. */ | ||
| readonly feed: Feed<RenderSample>; | ||
| /** Areas generated so far. */ | ||
| readonly areas: number; | ||
| }; | ||
|
|
||
| /** The renderer's numbers, bottom right; only this line re-renders per sample. */ | ||
| const StatsLine = ({ feed, areas }: StatsLineProps) => { | ||
| const sample = useSyncExternalStore(feed.subscribe, feed.get); | ||
| return ( | ||
| <p className="pointer-events-none absolute right-4 bottom-3 font-mono text-xs text-amber-100/50"> | ||
| {statsText(sample, areas)} | ||
| </p> | ||
| ); | ||
| }; | ||
|
|
||
| export { StatsLine }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { statsText } from "./stats-text"; | ||
|
|
||
| const sample = { | ||
| calls: 312, | ||
| triangles: 184_321, | ||
| geometries: 420, | ||
| textures: 36, | ||
| frameMs: 16.666, | ||
| }; | ||
|
|
||
| describe("statsText", () => { | ||
| it("names the areas alone before the first sample", () => { | ||
| expect(statsText(null, 1)).toBe("1 area"); | ||
| expect(statsText(null, 3)).toBe("3 areas"); | ||
| }); | ||
|
|
||
| it("shortens large counts and rounds the frame time", () => { | ||
| expect(statsText(sample, 9)).toBe( | ||
| "312 draws · 184k tris · 420 geo · 36 tex · 9 areas · 16.7 ms/frame" | ||
| ); | ||
| }); | ||
|
|
||
| it("writes millions with one decimal", () => { | ||
| expect(statsText({ ...sample, triangles: 1_234_567 }, 1)).toContain( | ||
| "1.2M tris · 420 geo · 36 tex · 1 area" | ||
| ); | ||
| expect(statsText({ ...sample, triangles: 999_500 }, 1)).toContain( | ||
| "1.0M tris" | ||
| ); | ||
| expect(statsText({ ...sample, triangles: 999_499 }, 1)).toContain( | ||
| "999k tris" | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { RenderSample } from "@repo/renderer/stats"; | ||
|
|
||
| /** `420`, `184k`, `1.2M`: short enough to read while walking. */ | ||
| const shortCount = (count: number): string => { | ||
| if (count < 1000) { | ||
| return String(count); | ||
| } | ||
| // 999 500 rounds to 1000k: it reads as 1.0M instead. | ||
| const thousands = Math.round(count / 1000); | ||
| return thousands < 1000 | ||
| ? `${thousands}k` | ||
| : `${(count / 1_000_000).toFixed(1)}M`; | ||
| }; | ||
|
|
||
| /** | ||
| * `312 draws · 184k tris · 420 geo · 36 tex · 9 areas · 16.7 ms/frame`, or | ||
| * the areas alone before the first sample. | ||
| */ | ||
| const statsText = (sample: RenderSample | null, areas: number): string => { | ||
| const built = areas === 1 ? "1 area" : `${areas} areas`; | ||
| if (sample === null) { | ||
| return built; | ||
| } | ||
| return [ | ||
| `${shortCount(sample.calls)} draws`, | ||
| `${shortCount(sample.triangles)} tris`, | ||
| `${shortCount(sample.geometries)} geo`, | ||
| `${shortCount(sample.textures)} tex`, | ||
| built, | ||
| `${sample.frameMs.toFixed(1)} ms/frame`, | ||
| ].join(" · "); | ||
| }; | ||
|
|
||
| export { statsText }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.