81a1b26842
Rendering used to clear the whole canvas and redraw every cell on every frame callback (~60 fps) even though the simulation ticks at 20 tps and starts paused, keeping CPU usage at ~85% while idle. Split simulation timing out of redraw() into the event loop and render only when displayed content can have changed (tick, painting, pattern placement, preview movement, grid-line toggle, resize); idle frames commit only a new frame callback. Repaint incrementally by diffing the grid against a rendered-state snapshot per row and redrawing just the changed cells, with damage limited to the repainted bounding box. Idle CPU drops to ~1% of one core; running frames render at tick rate (~20 fps) at microsecond cost. Adds grid_copy() snapshot helper with tests and archives the optimize-render-on-demand change with the new on-demand-rendering spec.
1.8 KiB
1.8 KiB
Proposal
Why
The render loop repaints the full canvas on every frame callback (~60 fps) even though the simulation ticks at only 20 tps and starts paused, so most frames draw an identical image. This keeps CPU usage at ~85% during idle, dominated by the full-canvas clear and the full grid scan.
What Changes
- Split simulation timing out of
redraw(); ticks are driven by the event loop, not by the render call. - Render a frame only when displayed content can have changed: a simulation tick, cell edit or pattern placement, pattern preview movement (pointer motion, tool selection, rotation), grid-line toggle, or canvas resize.
- When nothing changed, commit an empty frame (frame callback without attaching a new buffer), so the idle loop costs nearly nothing.
- Draw incrementally: keep a snapshot of the grid as last rendered, diff it per row against the current grid, and repaint only changed cells (background, grid-line fragments, cell) instead of clearing the whole canvas.
- Report damage for the changed region instead of the whole surface.
- Full-canvas repaint remains for resize, grid-line toggle, and when the diff covers most of the grid.
Capabilities
New Capabilities
on-demand-rendering: Scheduling of window repaints — when a frame is produced (only on content change) and how changed cells are drawn incrementally.
Modified Capabilities
Impact
wlgol.c: render loop (redraw,wl_callack_done,maindispatch loop), simulation tick timing, buffer commit/damage logic.include/grid.h/grid.c: possible helper for snapshotting the grid (no behavioral change to existing grid functions).- No protocol, dependency, or configuration changes. Rendering output is visually identical to the current renderer; only the frequency and extent of repainting change.