feat(physics): phys_generation - which world this is, so an id kept from an older one is known stale

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 00:47:42 +03:00
parent e909ec122c
commit caa0a15803
2 changed files with 4 additions and 0 deletions

View file

@ -6,12 +6,15 @@ export function phys_open(physics_st: mut PhysicsState, max_bodies: int, threads
phys_close(physics_st)
ph_buffers(physics_st)
physics_st.ph_world = jph_world_new(max_bodies, threads)
physics_st.ph_gen += 1
physics_st.ph_acc = 0.0
physics_st.ph_steps = 0
return physics_st.ph_world != null
}
export function phys_is_open(physics_st: PhysicsState) -> bool { return physics_st.ph_world != null }
# which world this is: a body, shape or walker id kept from an older one means nothing now
export function phys_generation(physics_st: PhysicsState) -> int { return physics_st.ph_gen }
# everything let go: the world, every body in it and every shape (a world swap, a quit)
export function phys_close(physics_st: mut PhysicsState) -> void {

View file

@ -42,6 +42,7 @@ export state PhysicsState {
ph_max_steps: int = 4 # a slow frame catches up this far and no further
ph_acc: float = 0.0
ph_steps: int = 0
ph_gen: int = 0 # how many worlds have been opened: an id from an older one is stale
ph_hard: float = 2.0 # metres a second: a contact under this is not a fact
ph_floats: []int = null # buoyant bodies' ids
ph_float_k: []float = null # and theirs: buoyancy, linear drag, angular drag, wet