From 65b51c251ed2af4a3945af94276be90bf2a117bb Mon Sep 17 00:00:00 2001 From: Orkuncakilkaya Date: Mon, 28 Sep 2026 11:54:21 +0300 Subject: [PATCH] ludic.things: thing_slot - a placed Thing's reusable slot in the table Co-Authored-By: Claude Opus 5.5 --- packages/ludic.things/spare.ludic | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/ludic.things/spare.ludic b/packages/ludic.things/spare.ludic index a29d866c..e3bf70ad 100644 --- a/packages/ludic.things/spare.ludic +++ b/packages/ludic.things/spare.ludic @@ -55,3 +55,10 @@ function th_clean(t: Thing) -> Thing { export function things_reserve(things_st: mut ThingsState, n: int) -> void { grid_reserve(things_st.th.grid, n) } export function things_spare_count(things_st: ThingsState) -> int { return len(things_st.th_spare) - things_st.th_spare_at } + +# a placed Thing's slot in the table: reused as Things come and go, so a list indexed by it is as +# long as the most Things there have been at once; -1 once it is removed +export function thing_slot(t: Thing) -> int { + if t == null or t.ent < 0 { return -1 } + return t.ent & ECS_SLOT +}