Buffer protocol for DiscreteMap (np.asarray zero-copy) #334
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.
Dependencies
No dependencies set.
Reference
john/McRogueFace#334
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 memory-model review. Additive, tiny, and the template for all later buffer work.
Current state
DiscreteMapis already the right shape: denseuint8_t*with adata()accessor, and it exports the codebase's only zero-copy window today --mask()->PyMemoryView_FromMemory(values, w*h, PyBUF_WRITE)(src/PyDiscreteMap.cpp:1315-1317). But there is notp_as_bufferanywhere in the codebase (only.tp_as_buffer = NULLatsrc/McRFPy_API.cpp:250), sonp.asarray(dmap)fails; users must know thenp.frombuffer(dmap.mask()).reshape(h, w)incantation.Proposal
Implement
tp_as_buffer(getbufferproc/releasebufferproc) onPyDiscreteMapproducing a 2-D C-contiguous uint8 buffer, shape(h, w), writable. Thennp.asarray(entity.perspective_map)is a zero-copy live view. Keepmask()/to_bytes()/from_bytes()for compatibility.DiscreteMap has no dirty flags, so this sidesteps the bulk-edit-convention decision (#328) -- which is exactly why it should go first. Entity perspective (0=unknown/1=discovered/2=visible,
src/UIEntity.h:75-80) becomes directly consumable as an RL observation plane.Related: #55, #154, #156 (agent-simulation motivation); multi-root Dijkstra already consumes
dmap->data->data()internally (src/UIGridPathfinding.cpp:857-878).