Package protocols.apps.canvas
Class PixelCanvas
java.lang.Object
protocols.apps.canvas.PixelCanvas
The shared pixel grid: one
PaintOp winner per cell under
last-writer-wins (see PaintOp.isNewerThan(protocols.apps.canvas.PaintOp)). All mutation goes through
apply(protocols.apps.canvas.PaintOp); reads (snapshotArgb(), snapshotOps(),
digest()) are used by the web UI thread and the periodic digest timer,
so every method is synchronized on this instance.
digest() is the convergence oracle: a stable 64-bit hash over the
winning colour of every painted cell in row-major order. Two nodes that have
applied the same set of ops produce the same digest — the experiments harness
asserts all live nodes agree once gossip quiesces.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intColour reported for a cell nobody has painted yet (transparent). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanApply an op under last-writer-wins.longdigest()Stable 64-bit digest of the visible canvas: FNV-1a over (index, argb) for every painted cell in row-major order.intintgetWidth()intmergeSnapshot(List<PaintOp> ops) Merge a peer's snapshot into this canvas under LWW.intNumber of cells that have been painted at least once.int[]The grid as a row-major array of ARGB colours,EMPTYfor unpainted cells.All current winning ops (one per painted cell) — used to seed a joining peer.
-
Field Details
-
EMPTY
public static final int EMPTYColour reported for a cell nobody has painted yet (transparent).- See Also:
-
-
Constructor Details
-
PixelCanvas
public PixelCanvas(int width, int height)
-
-
Method Details
-
getWidth
public int getWidth() -
getHeight
public int getHeight() -
apply
Apply an op under last-writer-wins. Returnstrueif it became (or remained the basis of) the new winner for its cell — i.e. the visible colour may have changed;falseif an out-of-bounds op or an op superseded by what the cell already holds. Idempotent and order-independent: applying the same op twice, or applying ops in any order, yields the same grid. -
paintedCount
public int paintedCount()Number of cells that have been painted at least once. -
snapshotArgb
public int[] snapshotArgb()The grid as a row-major array of ARGB colours,EMPTYfor unpainted cells. A copy — safe to hand to the UI thread. -
snapshotOps
All current winning ops (one per painted cell) — used to seed a joining peer. -
mergeSnapshot
Merge a peer's snapshot into this canvas under LWW. Returns how many cells changed. -
digest
public long digest()Stable 64-bit digest of the visible canvas: FNV-1a over (index, argb) for every painted cell in row-major order. Equal across nodes that have applied the same set of ops; the convergence oracle for the experiments harness.
-