ludic.physics, ludic.character, ludic.vehicles: fact records reused, and phys_sink allocates nothing

The per-frame sweep over physics, character, vehicles and nav found three fact makers that made a record per fact: contacts and splashes, the character's and the vehicles'. Each keeps a pool now, as wildlife's and npc's do (q_unheld). phys_sink, asked on every removal, built two new lists each time; it filters into a kept spare pair and swaps. ludic.nav's paths and crowds already allocate nothing, and none of the four builds a string per call. What remains at load, reset or a world swap is not per frame. vehicle_feed takes its state mut. vehicles_test: 1000 fed facts, drained turn by turn, use at most 4 records. All packages 421.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 02:03:09 +03:00
parent fe2d2bacd7
commit fffedf71d0
10 changed files with 92 additions and 11 deletions

View file

@ -104,6 +104,9 @@ export state CharacterState {
chr_safe_x: float = 0.0
chr_safe_z: float = 0.0
chr_fact_q: Queue<CharacterFact> = chr_fact_q__new()
chr_fpool: []CharacterFact = new []CharacterFact # every fact record made, reused once no drain holds it
chr_ffree: []CharacterFact = new []CharacterFact
chr_fnext: int = 0
}
function chr__top_plain(x: float, z: float, r: float, from_y: float, step: float, base: float) -> float { return base }
function chr__bed_plain(x: float, z: float) -> float { return CharacterGround.height(x, z) }

View file

@ -13,8 +13,24 @@ export function char_facts(character_st: CharacterState) -> Queue<CharacterFact>
return character_st.chr_fact_q
}
function chr_say(character_st: CharacterState, what: int, v: float) -> void {
# a fact record no drain holds any more, made fresh (and kept) only when every one is held: a
# fact can come every frame, and a record a frame is never given back
function chr_fact_record(character_st: mut CharacterState) -> CharacterFact {
if character_st.chr_fnext >= len(character_st.chr_ffree) {
q_unheld(char_facts(character_st), character_st.chr_fpool, character_st.chr_ffree)
character_st.chr_fnext = 0
}
if character_st.chr_fnext < len(character_st.chr_ffree) {
let f = character_st.chr_ffree[character_st.chr_fnext]
character_st.chr_fnext += 1
return f
}
let f = new CharacterFact
push(character_st.chr_fpool, f)
return f
}
function chr_say(character_st: mut CharacterState, what: int, v: float) -> void {
let f = chr_fact_record(character_st)
f.what = what
f.x = character_st.chr_x
f.y = character_st.chr_y