fix(ludic.physics): a removed walker's place is taken again, and phys_close keeps the lists it empties - nothing grows per horse called or per world swap

tests/reuse_test: 200 walkers made and removed hold one place and 0 bytes of heap (Os.heap_bytes);
twenty closes and opens keep the same shape and walker lists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 13:05:28 +03:00
parent e6729b3123
commit 6e132d25c8
3 changed files with 55 additions and 4 deletions

View file

@ -27,7 +27,15 @@ function ph_walker(physics_st: PhysicsState, id: int) -> pointer {
export function phys_walker_add(physics_st: mut PhysicsState, r: float, h: float, x: float, y: float, z: float, max_slope: float, mass: float) -> int {
if physics_st.ph_world == null { return -1 }
ph_buffers()
push(physics_st.ph_walkers, jph_char_new(physics_st.ph_world, r, h, x, y, z, max_slope, mass))
let k = jph_char_new(physics_st.ph_world, r, h, x, y, z, max_slope, mass)
# a removed walker's place is taken again, so a horse called and sent away grows nothing
for i in 0 .. len(physics_st.ph_walkers) {
if physics_st.ph_walkers[i] == null {
physics_st.ph_walkers[i] = k
return i
}
}
push(physics_st.ph_walkers, k)
return len(physics_st.ph_walkers) - 1
}