ludic.base, ludic.wildlife, ludic.npc: fact records reused, not made per fact
wl_fact made a new WildFact per fact, about one a frame, and Ludic never gives one back. ludic.base's q_unheld(q, pool, out) lists the records a queue no longer holds: neither waiting nor handed out by its last drain, which is good until the next drain. ludic.wildlife and ludic.npc now keep a pool, hand out a free record, and make a new one only when every record is held. Taking a record writes the state, so wl_fact / np_fact and the few callers holding their state read-only take it mut. Tests: q_unheld's rules (an empty drain holds on, the safe side); 3000 prints drained frame by frame use at most 4 records; 500 arrivals drained turn by turn use at most 4. base 37, wildlife 27, npc 17; all packages 420. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3e3c6088fb
commit
fe2d2bacd7
13 changed files with 129 additions and 10 deletions
|
|
@ -101,4 +101,20 @@ program NpcWayTest {
|
|||
expect_eq(p.act, NPCA_SIT)
|
||||
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) {
|
||||
fk_setup(npc_st, npc_tests_fake_st)
|
||||
npc_tests_fake_st.fk_want = 1
|
||||
let p = npc_spawn(npc_st, NPCK_HIKER)
|
||||
var arrived = 0
|
||||
for k in 0 .. 500 {
|
||||
npc_set_at(p, 0.0, 0.0)
|
||||
npc_go(npc_st, p, 0.5, 0.0, NPCA_SIT, 30.0)
|
||||
npc_tick(npc_st, 0.05)
|
||||
let fs = q_drain(npc_facts(npc_st))
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue