Skip to main content

Module dirty

Module dirty 

Source
Expand description

Tile bitmask of dirty pixel regions for double-buffered CPU surfaces.

Screen-wide weather and campfire embers produce hundreds of cell-sized rectangles per frame, and a double-buffered surface accumulates two frames’ worth of them before swapping. Collapsing past 48 rectangles to one bounding box turns sparse snow or spray into a full-screen copy every frame (~24-33 MB on Retina/4K), while keeping a raw list rewrites pixels where smooth-clock particles overlap from one frame to the next.

DirtyGrid marks 32x16-pixel tiles in a fixed bitset (32 BGRA pixels = 128 bytes, one Apple Silicon cache line) with no per-frame allocation, and emits merged horizontal and vertical runs so every touched pixel is copied at most once.

Structs§

DirtyGrid
Fixed-allocation tile bitset covering a width x height surface.

Constants§

TILE_H
TILE_W
32 4-byte pixels = 128 bytes (one Apple Silicon cache line).