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
|
|
@ -13,6 +13,9 @@ export state NpcState {
|
|||
np_n: int = 0 # walkers about
|
||||
np_dice: Rng = rng_new(20260925)
|
||||
np_facts: Queue<NpcFact> = np_facts__new()
|
||||
np_fpool: []NpcFact = new []NpcFact # every fact record made, reused once no drain holds it
|
||||
np_ffree: []NpcFact = new []NpcFact
|
||||
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)
|
||||
np_mirror: bool = false # a guest drawing a host's: no routine runs here
|
||||
|
|
@ -29,8 +32,8 @@ export function npc_facts(npc_st: NpcState) -> Queue<NpcFact> {
|
|||
return npc_st.np_facts
|
||||
}
|
||||
|
||||
function np_fact(npc_st: NpcState, what: int, p: NpcPerson, player: int) -> NpcFact {
|
||||
let f = new NpcFact
|
||||
function np_fact(npc_st: mut NpcState, what: int, p: NpcPerson, player: int) -> NpcFact {
|
||||
let f = np_fact_record(npc_st)
|
||||
f.what = what
|
||||
f.person = p.id
|
||||
f.slot = p.slot
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue