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.
19 lines
441 B
C
19 lines
441 B
C
#ifndef GRID_H
|
|
#define GRID_H
|
|
|
|
typedef struct {
|
|
int cols;
|
|
int rows;
|
|
unsigned char *cells;
|
|
int show_lines;
|
|
} grid_t;
|
|
|
|
void grid_init(grid_t *g, int cols, int rows);
|
|
void grid_free(grid_t *g);
|
|
void grid_resize(grid_t *g, int new_cols, int new_rows);
|
|
void grid_clear(grid_t *g);
|
|
void grid_copy(grid_t *dst, const grid_t *src);
|
|
int grid_get(const grid_t *g, int c, int r);
|
|
void grid_set(grid_t *g, int c, int r, int val);
|
|
|
|
#endif |