Skip to main content

Module app

Module app 

Expand description

The canvas side of the demo: frame pacing and egui painting.

Session pairs the crate::controller::Controller with the presentation state a frame needs (pace, view options, cached textures and observation, the model map being computed) and the custom function with its brush (D94). Its Session::show paints into any egui::Ui and takes pointer input there, so the full paint, hover and drawing paths run headless in tests; the browser shell only forwards frames to it.

The canvas holds up to three panels (D95): the function’s heatmap with the trials, the model map of crate::belief, and a chart. The model map is fitted, sampled and read by a dedicated browser worker when available. Native sessions, tests and the browser fallback fit synchronously and sample a few rows per frame within a time slice.

For CartPole (D113) the heatmap is itself expensive, one training run per cell, so it is sampled a few cells per frame the same way and kept for the rest of the process; its contour lines follow a lightly smoothed copy of the cells, its colors the cells themselves. A fourth panel, a strip across the canvas’s bottom, replays the best completed trial’s policy: the cart and pole drawn from crate::cartpole::replay at a fixed 50 steps per second of real time, looping after a one-second hold on the last step, switching to a new best trial’s policy as soon as there is one, and frozen on the last step under reduced motion.

Structs§

Brush
The custom function’s drawing tool.
Painted
Where the last frame painted each panel’s plot, in canvas points.
Panels
The canvas’s panels.
Session
The controller plus everything a frame needs to present it.
View
What the canvas shows besides the function and its trials.

Enums§

Pace
How quickly a running study advances.

Constants§

LANDSCAPE_SLICE
The time a frame may spend sampling a learner’s heatmap, in seconds.
LEARNER_SMOOTHING
How many binomial blur passes a learner’s contour lines are traced on (heatmap::Field::smoothed); the heatmap’s colors stay the raw cells.
MODEL_SLICE
The time a frame may spend computing the model map, in seconds.
POLICY_HEIGHT
The policy panel’s height: a strip across the canvas’s bottom.
POLICY_HOLD
How long the policy panel holds the last step before looping, in seconds.
POLICY_RATE
How many simulation steps the policy panel replays per second of real time: the environment’s own rate, one step per 0.02 s.

Functions§

apply_kit
Copies the demo kit v1 tokens into egui’s style for one scheme.
compact
A value to three significant digits (every integer digit from 100 up), in scientific notation when very large or small.
layout
Lays the panels out: the maps and the chart in one row when the canvas is wide enough for full-height maps (or nearly), else the maps above the chart, side by side when two fit at a readable size.