feat(maps): per-cell-origin bitmask branch unlocks 47-blob

compute_cell_bitmask_v3 now branches: cells where
cells_material is set use the classical 47-blob 8-neighbour rule
on effective material; vertex-only cells continue to use the
FIX-A 4-own-corner rule (v0.5.6 dual-grid). The 8-neighbour
branch evaluates each neighbour through cell_has_material so
cell-tile material and vertex-tile material both count as
neighbours.

A vertex-only cell adjacent to a cell-tile cell remains
structurally blind to its neighbour because its 4-corner rule
only reads its own corner vertices. This asymmetric seam at
in-layer mode boundaries is documented behaviour, not a bug.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Axel Meyer
2026-06-01 22:13:26 +02:00
parent c5039e5bf2
commit 5351923dd6

View File

@@ -294,36 +294,46 @@ local function cell_has_material(vertices, cells_material, w, h, x, y)
return false return false
end end
-- Returns the blob-gated 8-bit neighbour bitmask for cell (x, y) given -- Returns the blob-gated 8-bit neighbour bitmask for cell (x, y).
-- the layer's vertex grid + map size. Bit layout (clockwise from N): -- Bit layout (clockwise from N, LSB-first): N, NE, E, SE, S, SW, W, NW.
-- 0=N, 1=NE, 2=E, 3=SE, 4=S, 5=SW, 6=W, 7=NW.
-- --
-- 0.5.6: bits derive from the render-cell's own 4 corner map-tiles -- 0.5.7: per-cell-origin branch. Cells whose material origin is
-- (= the 4 surrounding vertices in dual-grid terms), not from the -- cells_material[x, y] use the classical 47-blob 8-neighbour rule on
-- material status of the 8 neighbour cells. A cardinal bit is set iff -- effective material (vertex-derived OR cell-derived). Vertex-only
-- at least one of the 2 vertices on that edge is painted; a diagonal -- cells continue to use the FIX-A 4-own-corner rule (v0.5.6 dual-grid
-- bit is set iff the corner vertex in that direction is painted. -- semantics, 5 reachable atlas slots).
-- Pre-0.5.6 used cell-neighbour-material, which made two cells with a --
-- shared unpainted edge see each other as material whenever any other -- Pre-condition: cell_has_material(vertices, cells_material, w, h, x, y)
-- corner of either was painted — producing connected blobs across -- returned true for this cell.
-- visually-empty map-tile gaps. See plan
-- 2026-05-29-painting-model-rethink for the discovery.
local function compute_cell_bitmask_v3(vertices, cells_material, w, h, x, y) local function compute_cell_bitmask_v3(vertices, cells_material, w, h, x, y)
local b = 0
if cells_material_at(cells_material, w, h, x, y) ~= 0 then
-- 47-blob branch: 8 neighbour effective-material bits.
if cell_has_material(vertices, cells_material, w, h, x, y - 1) then b = b | 0x01 end
if cell_has_material(vertices, cells_material, w, h, x + 1, y - 1) then b = b | 0x02 end
if cell_has_material(vertices, cells_material, w, h, x + 1, y ) then b = b | 0x04 end
if cell_has_material(vertices, cells_material, w, h, x + 1, y + 1) then b = b | 0x08 end
if cell_has_material(vertices, cells_material, w, h, x, y + 1) then b = b | 0x10 end
if cell_has_material(vertices, cells_material, w, h, x - 1, y + 1) then b = b | 0x20 end
if cell_has_material(vertices, cells_material, w, h, x - 1, y ) then b = b | 0x40 end
if cell_has_material(vertices, cells_material, w, h, x - 1, y - 1) then b = b | 0x80 end
else
-- FIX-A 4-corner-vertex branch (v0.5.6 dual-grid, unchanged).
local vw = w + 1 local vw = w + 1
local vh = h + 1 local vh = h + 1
local TL = vertex_at(vertices, vw, vh, x, y ) ~= 0 local TL = vertex_at(vertices, vw, vh, x, y ) ~= 0
local TR = vertex_at(vertices, vw, vh, x + 1, y ) ~= 0 local TR = vertex_at(vertices, vw, vh, x + 1, y ) ~= 0
local BL = vertex_at(vertices, vw, vh, x, y + 1) ~= 0 local BL = vertex_at(vertices, vw, vh, x, y + 1) ~= 0
local BR = vertex_at(vertices, vw, vh, x + 1, y + 1) ~= 0 local BR = vertex_at(vertices, vw, vh, x + 1, y + 1) ~= 0
local b = 0 if TL or TR then b = b | 0x01 end -- N
if TL or TR then b = b | 0x01 end -- N edge: TL or TR painted if TR then b = b | 0x02 end -- NE
if TR then b = b | 0x02 end -- NE corner: TR painted if TR or BR then b = b | 0x04 end -- E
if TR or BR then b = b | 0x04 end -- E edge: TR or BR painted if BR then b = b | 0x08 end -- SE
if BR then b = b | 0x08 end -- SE corner: BR painted if BL or BR then b = b | 0x10 end -- S
if BL or BR then b = b | 0x10 end -- S edge: BL or BR painted if BL then b = b | 0x20 end -- SW
if BL then b = b | 0x20 end -- SW corner: BL painted if TL or BL then b = b | 0x40 end -- W
if TL or BL then b = b | 0x40 end -- W edge: TL or BL painted if TL then b = b | 0x80 end -- NW
if TL then b = b | 0x80 end -- NW corner: TL painted end
return apply_blob_gating(b) return apply_blob_gating(b)
end end