# ludic.base/ecs_table_set.ludic - the setters: a write stamps the row's tick and refiles it in # every index that reads that column, so an index is never a frame behind what it indexes export function tb_f(tb: Table, c: int, row: int) -> float { return tb.f[c][row] } export function tb_i(tb: Table, c: int, row: int) -> int { return tb.i[c][row] } export function tb_set_f(tb: Table, c: int, row: int, v: float) -> void { tb.f[c][row] = v tb_stamp(tb, row) for g in 0 .. len(tb.grids) { let gr = tb.grids[g] if gr.cx == c or gr.cz == c { tb_grid_refile(tb, gr, row) } } } # two float columns at once, filed once: a move export function tb_set_xz(tb: Table, cx: int, cz: int, row: int, x: float, z: float) -> void { tb.f[cx][row] = x tb.f[cz][row] = z tb_stamp(tb, row) for g in 0 .. len(tb.grids) { let gr = tb.grids[g] if gr.cx == cx or gr.cz == cz or gr.cx == cz or gr.cz == cx { tb_grid_refile(tb, gr, row) } } } export function tb_set_i(tb: Table, c: int, row: int, v: int) -> void { tb.i[c][row] = v tb_stamp(tb, row) for g in 0 .. len(tb.grids) { if tb.grids[g].gate == c { tb_grid_refile(tb, tb.grids[g], row) } } for k in 0 .. len(tb.idx) { let ix = tb.idx[k] if ix.col == c or ix.gate == c { tb_ix_refile(tb, ix, row) } } } # a row written without a setter (tb.f / tb.i directly, for speed) is refiled everywhere by this export function tb_refile(tb: Table, row: int) -> void { tb_stamp(tb, row) for g in 0 .. len(tb.grids) { tb_grid_refile(tb, tb.grids[g], row) } for k in 0 .. len(tb.idx) { tb_ix_refile(tb, tb.idx[k], row) } } export function tb_mark(tb: Table, row: int) -> void { tb_stamp(tb, row) } function tb_gate_on(tb: Table, gate: int, row: int) -> bool { return gate < 0 or tb.i[gate][row] != 0 } function tb_grid_refile(tb: Table, g: Grid, row: int) -> void { grid_refile(g, row, tb.f[g.cx][row], tb.f[g.cz][row], tb_gate_on(tb, g.gate, row)) } function tb_ix_refile(tb: Table, ix: IntIndex, row: int) -> void { if tb_gate_on(tb, ix.gate, row) { ix_file(ix, row, tb.i[ix.col][row]) } else { ix_unfile(ix, row) } } # change detection: the rows a setter wrote after `since`, into `out` (cleared first); no allocation export function tb_changed_since(tb: Table, since: int, out: words) -> int { List.clear(out) for b in 0 .. len(tb.blk) { if tb.blk[b] <= since { continue } var end = b * 64 + 64 if end > tb.n { end = tb.n } for r in b * 64 .. end { if tb.changed[r] > since { kept_push(out, r) } } } return len(out) } export function tb_added_since(tb: Table, since: int, out: words) -> int { List.clear(out) for b in 0 .. len(tb.blk) { if tb.blk[b] <= since { continue } var end = b * 64 + 64 if end > tb.n { end = tb.n } for r in b * 64 .. end { if tb.added[r] > since { push(out, r) } } } return len(out) }