feat(ecs): observers and block change stamps on a Table
tb_on_add / tb_on_remove take a fn(int) (its states supplied, like a system's) told each handle as
its row is made and before it goes (ecs_hooks.ludic), so what follows a table - a drawing, a
message - does so without a scan. Every row's tick now also stamps its 64-row block, and
tb_changed_since / tb_added_since skip the blocks nobody wrote since: a delta over a large table
costs the blocks that moved. A row moved into a removal's gap keeps its own tick (it was not
written); a removal is told by the hook. ecs_test holds both. The ludic.wildlife table
(5ac3d48, written while builds were held) now builds and passes its 19 tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4a285903e1
commit
52270ab5d1
6 changed files with 103 additions and 7 deletions
|
|
@ -1,6 +1,8 @@
|
|||
# ludic.base/ecs_table_remove.ludic - removing a row moves the last one into its place, so the
|
||||
# rows stay dense; every index is told, and the slot's generation moves on
|
||||
export function tb_remove<T>(tb: Table<T>, h: int) -> bool {
|
||||
if tb_row(tb, h) < 0 { return false }
|
||||
for k in 0 .. len(tb.on_remove) { tb.on_remove[k].run(h) }
|
||||
let r = tb_row(tb, h)
|
||||
if r < 0 { return false }
|
||||
for g in 0 .. len(tb.grids) { grid_unlink(tb.grids[g], r) }
|
||||
|
|
@ -23,6 +25,8 @@ function tb_move<T>(tb: Table<T>, from: int, to: int) -> void {
|
|||
for c in 0 .. len(tb.f) { tb.f[c][to] = tb.f[c][from] }
|
||||
for c in 0 .. len(tb.i) { tb.i[c][to] = tb.i[c][from] }
|
||||
tb.slot_row[tb.ent[to] & ECS_SLOT] = to
|
||||
let b = to >> 6
|
||||
if tb.blk[b] < tb.changed[to] { tb.blk[b] = tb.changed[to] }
|
||||
for g in 0 .. len(tb.grids) { grid_moved(tb.grids[g], from, to) }
|
||||
for k in 0 .. len(tb.idx) { ix_moved(tb.idx[k], from, to) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue