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>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-29 16:18:42 +03:00
parent 031fcad641
commit b4af12025d
11 changed files with 95 additions and 52 deletions

View file

@ -93,11 +93,11 @@ public:
struct World {
// pairs and contacts are for what MOVES: a valley of sixty thousand still trunks makes none
// between them, so these are Jolt's own sizes, not the body count's; the temporary memory falls
// back to the heap rather than aborting a step
World(int max_bodies, int threads)
: temp(32 * 1024 * 1024), jobs(cMaxPhysicsJobs, cMaxPhysicsBarriers, threads) {
sys.Init(max_bodies, 0, 65536, 20480, bpl, ovb, olp);
// between them, so they are sized for the moving things, not the body count; the temporary memory
// falls back to the heap rather than aborting a step. All four are the package's (phys_open)
World(int max_bodies, int threads, int max_pairs, int max_contacts, int temp_kb)
: temp(size_t(temp_kb) * 1024), jobs(cMaxPhysicsJobs, cMaxPhysicsBarriers, threads) {
sys.Init(max_bodies, 0, max_pairs, max_contacts, bpl, ovb, olp);
sys.SetContactListener(&contacts);
}
TempAllocatorImplWithMallocFallback temp;

View file

@ -1,13 +1,14 @@
// jph_world.inl - a physics world: made, stepped, emptied of its contacts, freed
// a world for up to max_bodies; threads 0 means the machine's cores less one, at most four
JPH_SHIM void *jph_world_new(int max_bodies, int threads) {
// a world for up to max_bodies, max_pairs touching pairs and max_contacts contact constraints, with a
// temp heap of temp_kb; threads 0 means the machine's cores less one, at most four
JPH_SHIM void *jph_world_new(int max_bodies, int threads, int max_pairs, int max_contacts, int temp_kb) {
if (jph_init() != 0) return nullptr;
if (threads <= 0) {
int hw = int(std::thread::hardware_concurrency()) - 1;
threads = hw < 1 ? 1 : (hw > 4 ? 4 : hw);
}
World *w = new World(max_bodies, threads);
World *w = new World(max_bodies, threads, max_pairs, max_contacts, temp_kb);
w->sys.SetGravity(Vec3(0.0f, -9.81f, 0.0f));
return w;
}