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

This commit is contained in:
ecker 2026-08-19 20:18:45 -05:00
parent cb86b34076
commit 5ba9983594
2 changed files with 4 additions and 7 deletions

View File

@ -469,6 +469,7 @@ namespace pod {
uf::stl::vector<pod::PhysicsBody*> bodies;
uf::stl::vector<pod::Constraint*> constraints;
float timeAccumulator = 0.0f;
pod::Vector3f gravity = { 0, -9.81f, 0 };
pod::BVH dynamicBvh;
pod::BVH staticBvh;

View File

@ -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");