ludic/packages/ludic.base/ecs_hooks.ludic
Orkuncakilkaya 52270ab5d1 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>
2026-09-27 21:47:06 +03:00

18 lines
699 B
Text

# ludic.base/ecs_hooks.ludic - observers on a table: told each handle as its row is made, and before
# it is removed, so what depends on a table (a drawing, a message) follows it without a scan
# an observer: a function handed an entity's handle (its states are supplied, like a system's)
export property TbHook {
run: fn(int) -> void = null
}
# f is told every handle added from here on, and every handle about to be removed
export function tb_on_add<T>(tb: Table<T>, f: fn(int) -> void) -> void {
let hk = new TbHook
hk.run = f
push(tb.on_add, hk)
}
export function tb_on_remove<T>(tb: Table<T>, f: fn(int) -> void) -> void {
let hk = new TbHook
hk.run = f
push(tb.on_remove, hk)
}