[1.0 Decision] Bulk-edit convention for future array/buffer APIs (edit() context manager vs explicit sync) #328
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
#335 Buffer protocol / numpy views for ColorLayer and TileLayer
john/McRogueFace
Reference
john/McRogueFace#328
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From the 2026-07-02 pre-1.0 memory-model review. The buffer-protocol APIs themselves are additive (post-1.0-safe), but the idiom should be chosen once, before
apply_threshold/fill_rect/future numpy views accumulate three inconsistent conventions.Problem
Zero-copy views (memoryview / numpy) let Python write cell data while bypassing the setters that maintain invariants:
markDirty(x,y)-> chunk render-texture invalidation (src/GridLayers.h:42-79)transparency_generationbump +fov_dirty(src/GridData.cpp:133-140,src/UIGridPoint.cpp:90)The one existing zero-copy export,
DiscreteMap.mask()(src/PyDiscreteMap.cpp:1315-1317), dodges this only because DiscreteMap has no dirty flags.Options
with layer.edit() as view:-- yields a writable view, marks affected state dirty (conservatively: whole layer / full TCOD resync) on__exit__. Scoped, explicit, hard to misuse.layer.view/grid.walkable_view); after writing, the user must calllayer.mark_dirty()/grid.sync(). More flexible, easier to forget.Per the project's fail-early principle, no automatic change detection -- pick an explicit contract.
Blocks
grid.walkablearray view (depends on GridData SoA refactor, #332).DECIDED 2026-07-02: Option 1 —
edit()context manager is THE bulk-edit convention.with layer.edit() as view:yields the writable view;__exit__conservatively invalidates (whole-layer markDirty / full TCOD resync + generation bump as applicable). Forgetting to sync is impossible by construction, which is the fail-early principle applied to the API surface. Read-only zero-copy views (likeDiscreteMap.mask()) may still be exposed without ceremony.No always-writable raw view +
mark_dirty()primitives will be shipped; if a real need for persistent writable views emerges post-1.0, primitives can be added additively without breaking theedit()idiom.This unblocks #335 (ColorLayer/TileLayer buffers) and sets the convention #334 and any future
grid.walkableview (#332) must follow. Convention will be recorded in the compatibility/docs pass (#327/#330/#326), which closes this issue.