From 7fdd6582be725582c52d3630d097913193fa0c3a Mon Sep 17 00:00:00 2001 From: Orkuncakilkaya Date: Mon, 28 Sep 2026 15:46:11 +0300 Subject: [PATCH] fix(ludic.npc): the facts' records and the queue's lists made at their size at the start (64), so a frame with a new peak of facts makes nothing The fence found np_fact_record making a record in five frames of every scenario: the pool grew to each new peak of facts held at once, and q_unheld's free list and the queue's two lists grew with it. Co-Authored-By: Claude Opus 5.5 --- packages/ludic.npc/index.ludic | 1 + packages/ludic.npc/person.ludic | 6 +++--- packages/ludic.npc/pool.ludic | 26 +++++++++++++++++++++++++ packages/ludic.npc/tests/way_test.ludic | 4 ++-- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 packages/ludic.npc/pool.ludic diff --git a/packages/ludic.npc/index.ludic b/packages/ludic.npc/index.ludic index 4cb6a00c..9d996f04 100644 --- a/packages/ludic.npc/index.ludic +++ b/packages/ludic.npc/index.ludic @@ -4,6 +4,7 @@ module ludic_npc uses ludic_base numbers float import "ludic.base" import "defs.ludic" +import "pool.ludic" import "person.ludic" import "port.ludic" import "ground.ludic" diff --git a/packages/ludic.npc/person.ludic b/packages/ludic.npc/person.ludic index e7c95ff4..f6f90360 100644 --- a/packages/ludic.npc/person.ludic +++ b/packages/ludic.npc/person.ludic @@ -13,8 +13,8 @@ export state NpcState { np_n: int = 0 # walkers about np_dice: Rng = rng_new(20260925) np_facts: Queue = np_facts__new() - np_fpool: []NpcFact = new []NpcFact # every fact record made, reused once no drain holds it - np_ffree: []NpcFact = new []NpcFact + np_fpool: []NpcFact = np_pool_new() # every fact record made, reused once no drain holds it + np_ffree: []NpcFact = np_list_sized() np_fnext: int = 0 np_next_h: float = 0.0 # the hour the census is next looked at np_hold: bool = false # held where they stand (a shot of their poses) @@ -109,4 +109,4 @@ function np_hi(lo: int, hi: int) -> int { if hi < lo { return lo } return hi } -function np_facts__new() -> Queue { return queue_new("npc.facts") } +function np_facts__new() -> Queue { return np_queue_sized(queue_new("npc.facts")) } diff --git a/packages/ludic.npc/pool.ludic b/packages/ludic.npc/pool.ludic new file mode 100644 index 00000000..b33c43db --- /dev/null +++ b/packages/ludic.npc/pool.ludic @@ -0,0 +1,26 @@ +# ludic.npc/pool.ludic - the facts' records and the queue's lists made at their size once, at the +# start: a frame's facts are reused records, and a frame with more than it has seen before still +# makes none until NP_FACTS are held at once +const NP_FACTS: int = 64 + +function np_pool_new() -> []NpcFact { + let l = new []NpcFact + for i in 0 .. NP_FACTS { push(l, new NpcFact) } + return l +} +# an empty list with room for them all: q_unheld fills it without growing it +function np_list_sized() -> []NpcFact { + let l = np_pool_new() + List.clear(l) + return l +} +function np_queue_sized(q: Queue) -> Queue { + let f = new NpcFact + for i in 0 .. NP_FACTS { + push(q.items, f) + push(q.spare, f) + } + List.clear(q.items) + List.clear(q.spare) + return q +} diff --git a/packages/ludic.npc/tests/way_test.ludic b/packages/ludic.npc/tests/way_test.ludic index 624450fe..95cc089d 100644 --- a/packages/ludic.npc/tests/way_test.ludic +++ b/packages/ludic.npc/tests/way_test.ludic @@ -102,7 +102,7 @@ program NpcWayTest { expect(p.phase > 100.0) } - test "an arrival a turn, drained each turn, makes a few fact records and then reuses them" (npc_st: mut NpcState, npc_tests_fake_st: mut NpcTestsFakeState, way_test_st: WayTestState) { + test "an arrival a turn, drained each turn, makes no fact record past the ones made at the start" (npc_st: mut NpcState, npc_tests_fake_st: mut NpcTestsFakeState, way_test_st: WayTestState) { fk_setup(npc_st, npc_tests_fake_st) npc_tests_fake_st.fk_want = 1 let p = npc_spawn(npc_st, NPCK_HIKER) @@ -115,6 +115,6 @@ program NpcWayTest { for i in 0 .. len(fs) { if fs[i].what == NPC_F_ARRIVED { arrived += 1 } } } expect(arrived > 400) - expect(npc_fact_records(npc_st) <= 4) + expect_eq(npc_fact_records(npc_st), 64) } }