Files
shinyobjectz ee42e31469 NB2a: stat channels and pass timings chosen and read from TypeScript
io/trace's stats.rs: a stat channel is a RAEA_ variable's name without RAEA_ (bake_trace, trace, bevy_passes), on
when the composition chose it (native("stats.on", { channels }) at its top level), when RAEA_STATS lists it, or when
its variable is set, the override. The 51 reads of 24 trace and stat variables go through raea_io_trace::stat. Each
of Bevy's render passes (RenderDiagnosticsPlugin, on by bevy_passes) and PassTimer's go into the run's totals, with
the counters engine/draws and engine/updates; native("stats.read", {}) returns them, and a run that chose a channel
prints the table and keeps stats.json in its trace folder (docs/manual/reference/cli/traces.md).

tools/nobuild.sh stats checks it: every channel decided done reads through stat(); the scene choosing bevy_passes and
trace traces, reads 9 passes and 11 draws back on its last frame, prints the table and keeps stats.json; with nothing
chosen nothing prints; RAEA_TRACE=1 and RAEA_STATS give the same trace lines. 12 frames take 12 updates.

raea-render's lines stay as they were (NB4a's plugin choice folded to one line). native-calls.ts gains the two calls,
and bevy.app.*, which raea registers now that the macOS build links the plugin catalog.
2026-11-22 09:15:58 -08:00

43 lines
2.2 KiB
TypeScript

import { AbsoluteFill, Composition, registerRoot, useCurrentFrame } from "raea";
import { native, print } from "@raea/app/native";
import { Camera3d } from "raea/camera";
import { AmbientLight, DirectionalLight } from "raea/light";
import { Cuboid, Mesh3d } from "raea/mesh";
import { StandardMaterial } from "raea/pbr";
import { Quat, Transform } from "raea/transform";
// docs/nobuild.feature NB2a: a scene that turns stat channels on from TypeScript and reads the run's numbers back,
// with no variable set and no build (tools/nobuild.sh stats). At its top level, so they're on before the Engine opens:
// bevy_passes (each of Bevy's render passes timed) and trace (a line per update of each frame, RAEA_TRACE's). On its
// last frame it prints what stats.read says so far: the passes timed, and the Engine's draws and updates.
const FRAMES = 12;
native("stats.on", { channels: ["bevy_passes", "trace"] });
function Box() {
const f = useCurrentFrame();
if (f === FRAMES - 1) {
const s = native("stats.read", {});
const passes = Object.keys(s.passes).filter((k) => k.startsWith("bevy/"));
print(`stats.read: chosen ${s.chosen.join(",")}; ${passes.length} bevy passes timed; draws ${s.counters["engine/draws"] ?? 0}; updates ${s.counters["engine/updates"] ?? 0}`);
}
return (
<AbsoluteFill style={{ background: "#0f1720" }}>
<>
<Camera3d transform={Transform.fromXyz(0, 1.5, 5).lookingAt([0, 0.5, 0])} projection={{ Perspective: { fov: 0.785398163397448 } }} />
<AmbientLight brightness={200} />
<DirectionalLight transform={Transform.fromXyz(3, 6, 4).lookingAt([0, 0, 0])} illuminance={10400} shadow_maps_enabled />
<Mesh3d name="floor">
<Cuboid half_size={[3, 0.1, 2]} />
<StandardMaterial base_color="#334155" perceptual_roughness={0.8} />
</Mesh3d>
<Mesh3d transform={Transform.fromXyz(0, 0.6, 0).withRotation(Quat.fromEuler("XYZ", 0, f * 0.1, 0))} name="box">
<Cuboid half_size={[0.5, 0.5, 0.5]} />
<StandardMaterial base_color="#e11d48" perceptual_roughness={0.4} />
</Mesh3d>
</>
</AbsoluteFill>
);
}
registerRoot(() => <Composition id="stats" component={Box} width={320} height={180} fps={30} durationInFrames={FRAMES} />);