diff --git a/packages/ludic.inventory/state.ludic b/packages/ludic.inventory/state.ludic index b8f2aad3..05434235 100644 --- a/packages/ludic.inventory/state.ludic +++ b/packages/ludic.inventory/state.ludic @@ -12,15 +12,20 @@ export property ItemChanged { after: int = 0 } +# a change's record comes round again after this many more: far more than a frame makes between drains +const IV_POOL: int = 512 export state InventoryState { iv_keys: []string = null iv_counts: []int = null iv_changes: Queue = iv_changes__new() + iv_pool: []ItemChanged = new []ItemChanged # the facts' records, made once and taken in turn + iv_at: int = 0 } # the kinds, by the name each is saved under; the pack starts empty export function inv_config(inventory_st: mut InventoryState, keys: []string) -> void { inventory_st.iv_keys = keys + if len(inventory_st.iv_pool) == 0 { for i in 0 .. IV_POOL { push(inventory_st.iv_pool, new ItemChanged) } } inv_clear(inventory_st) } diff --git a/packages/ludic.inventory/verbs.ludic b/packages/ludic.inventory/verbs.ludic index c31c7883..392702e9 100644 --- a/packages/ludic.inventory/verbs.ludic +++ b/packages/ludic.inventory/verbs.ludic @@ -3,7 +3,11 @@ function iv_change(inventory_st: mut InventoryState, it: int, after: int) -> voi let before = inventory_st.iv_counts[it] if before == after { return } inventory_st.iv_counts[it] = after - let c = new ItemChanged + var c: ItemChanged = null + if len(inventory_st.iv_pool) > 0 { + c = inventory_st.iv_pool[inventory_st.iv_at] + inventory_st.iv_at = (inventory_st.iv_at + 1) % len(inventory_st.iv_pool) + } else { c = new ItemChanged } c.item = it c.before = before c.after = after