ludic/packages/ludic.physics/world.ludic
Orkuncakilkaya b4af12025d physics: Jolt's floor sized for what moves - pairs 4096, contacts 2048 and a 4 MB temp heap by default (phys_open_sized for more), and a body past max_bodies or a step past the pairs or contacts is Mem.over, never a quiet -1; world.ludic split from shapes.ludic
An empty world at the game's size held 51839 KB of Jolt's heap (200000 bodies, 65536 pairs, 20480
contacts, a 32 MB temp heap), the jolt= floor under every walk. Pairs and contacts come from what
moves - drops, boats, a few walkers - and a valley's still things make none. Now 11743 KB at 200000
bodies and 8461 KB at the 98304 the game opens for (jolt_floor_test holds it under 16 MB). The temp heap
still falls back to malloc for a step that wants more.

lib/macos-arm64 rebuilt; lib/windows-x64 needs native/build.sh on the PC (jph_world_new's new sizes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 16:18:42 +03:00

43 lines
2.2 KiB
Text

# world.ludic - the world opened and closed: its sizes, and everything in it let go at once
# a world for up to max_bodies (threads 0: the cores less one, at most four); false if C refused.
# Pairs, contacts and the temp heap are sized for the things that MOVE (PH_PAIRS, ...)
export function phys_open(physics_st: mut PhysicsState, max_bodies: int, threads: int) -> bool { return phys_open_sized(physics_st, max_bodies, threads, PH_PAIRS, PH_CONTACTS, PH_TEMP_KB) }
# the same with Jolt's other three sizes given: touching pairs, contact constraints, the temp heap in KB
export function phys_open_sized(physics_st: mut PhysicsState, max_bodies: int, threads: int, max_pairs: int, max_contacts: int, temp_kb: int) -> bool {
phys_close(physics_st)
ph_buffers()
physics_st.ph_world = jph_world_new(max_bodies, threads, max_pairs, max_contacts, temp_kb)
physics_st.ph_max = max_bodies
ph_own_reset(physics_st, max_bodies)
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); the lists
# that held them are emptied and kept, since nothing is given back
export function phys_close(physics_st: mut PhysicsState) -> void {
if physics_st.ph_walkers != null {
for i in 0 .. len(physics_st.ph_walkers) {
if physics_st.ph_walkers[i] != null { jph_char_free(physics_st.ph_walkers[i]) }
}
}
if physics_st.ph_walkers != null { List.clear(physics_st.ph_walkers) }
if physics_st.ph_world != null { jph_world_free(physics_st.ph_world) }
physics_st.ph_world = null
if physics_st.ph_shapes != null {
for i in 0 .. len(physics_st.ph_shapes) {
if physics_st.ph_shapes[i] != null { jph_shape_free(physics_st.ph_shapes[i]) }
}
}
if physics_st.ph_shapes != null { List.clear(physics_st.ph_shapes) }
List.clear(physics_st.ph_spare)
physics_st.ph_nf = 0
if physics_st.ph_facts != null { q_clear(physics_st.ph_facts) }
}