feat(ecs): things_now / things_changed - a consumer keeps the tick it read up to and asks only for the Things written since (untouched 64-row blocks skipped)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 22:13:45 +03:00
parent 61a6ab2e7b
commit 649a65d854
2 changed files with 35 additions and 0 deletions

View file

@ -15,3 +15,20 @@ export function things_drop_chunk(things_st: mut ThingsState, chunk: int) -> int
}
return n
}
# change detection: the tick now, the table moving on to the next - a consumer keeps what this
# returned and asks things_changed(since: it) for what was written after
export function things_now(things_st: mut ThingsState) -> int {
let t = tb_tick(things_st.th.tab)
tb_advance(things_st.th.tab)
return t
}
# every Thing a verb wrote after `since`, into the caller's list (untouched 64-row blocks skipped)
export function things_changed(things_st: ThingsState, since: int, rows: words, out: []Thing) -> int {
List.clear(out)
let tb = things_st.th.tab
let n = tb_changed_since(tb, since, rows)
for k in 0 .. n { push(out, tb.rec[rows[k]]) }
return n
}

View file

@ -197,4 +197,22 @@ program ThingsTest {
expect_eq(len(facts(things_st)), 3)
expect_eq(things_verify(things_st), 0)
}
test "change detection names what a verb wrote since the tick a consumer kept" (things_st: mut ThingsState) {
things_clear(things_st)
let a = put(things_st, TH_BRANCH, 1.0, 0.0)
let b = put(things_st, TH_BRANCH, 2.0, 0.0)
let seen = things_now(things_st)
let rows = words(0)
let out = new []Thing
expect_eq(things_changed(things_st, seen, rows, out), 0)
thing_hide(b)
expect_eq(things_changed(things_st, seen, rows, out), 1)
expect(out[0] == b)
let later = things_now(things_st)
thing_move(a, 9.0, 9.0, 0.0)
expect_eq(things_changed(things_st, later, rows, out), 1)
expect(out[0] == a)
expect_eq(things_changed(things_st, seen, rows, out), 2)
}
}