From 5ba99835949c0681ce514262a45109092b7958f2 Mon Sep 17 00:00:00 2001 From: ecker Date: Wed, 19 Aug 2026 20:18:45 -0500 Subject: [PATCH] also migrate frame accumulator to world state instead of it being a static variable in some weird timeline i have multiple physics sims running at once --- engine/inc/uf/utils/math/physics/structs.h | 1 + engine/src/utils/math/physics/impl.cpp | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/engine/inc/uf/utils/math/physics/structs.h b/engine/inc/uf/utils/math/physics/structs.h index 21dd8688..ef26a35a 100644 --- a/engine/inc/uf/utils/math/physics/structs.h +++ b/engine/inc/uf/utils/math/physics/structs.h @@ -469,6 +469,7 @@ namespace pod { uf::stl::vector bodies; uf::stl::vector constraints; + float timeAccumulator = 0.0f; pod::Vector3f gravity = { 0, -9.81f, 0 }; pod::BVH dynamicBvh; pod::BVH staticBvh; diff --git a/engine/src/utils/math/physics/impl.cpp b/engine/src/utils/math/physics/impl.cpp index b55635f1..6fcfc9dd 100644 --- a/engine/src/utils/math/physics/impl.cpp +++ b/engine/src/utils/math/physics/impl.cpp @@ -68,17 +68,13 @@ void uf::physics::tick( pod::World& world, float dt ) { return; } - UF_PHYSICS_TIMER_MULTITRACE_START("Tick Step Begin"); - static float accumulator = 0; - accumulator += dt; - float timestep = uf::physics::settings.timestep; - - while ( accumulator >= timestep ) { + world.timeAccumulator += dt; + while ( world.timeAccumulator >= timestep ) { if ( uf::physics::settings.substeps > 0 ) uf::physics::substep( world, timestep, uf::physics::settings.substeps ); else uf::physics::step( world, timestep ); - accumulator -= timestep; + world.timeAccumulator -= timestep; UF_PHYSICS_TIMER_MULTITRACE("Tick Accumulation Step"); } UF_PHYSICS_TIMER_MULTITRACE_END("Tick Step Complete");