Skip to content

Commit

Permalink
fix(physics): do fixed updates correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomanita authored and joaomanita committed Nov 26, 2024
1 parent 49e590f commit fba21ee
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fixed delta time not used in some physics systems and simulations exploding after being frozen for too long (**@joaomanita**).
- Crash in ecs when removing or destroying components with observers (#1348, **@SrGesus**).
- Crash when opening the Play Pause menu (**SrGesus**).
- Duplicated destructor call in AnyVector which caused double free crashes on multiple samples (**@RiscadoA**).
Expand Down
1 change: 0 additions & 1 deletion engine/samples/collisions/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ int main(int argc, char** argv)

cubos.system("move colliders")
.tagged(physicsApplyForcesTag)
.before(transformUpdateTag)
.call(
[](State& state, const Options& options, const Input& input, Query<Position&, Rotation&, Velocity&> query) {
auto [aPos, aRot, aVel] = *query.at(state.a);
Expand Down
2 changes: 1 addition & 1 deletion engine/samples/voxel-shape-collisions/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main()
});

cubos.system("move colliders")
.before(transformUpdateTag)
.tagged(physicsApplyForcesTag)
.call([](State& state, Query<Position&, Rotation&, Velocity&> query) {
auto [aPos, aRot, aVel] = *query.at(state.a);
auto [bPos, bRot, bVel] = *query.at(state.b);
Expand Down
8 changes: 5 additions & 3 deletions engine/src/fixed_step/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ void cubos::engine::fixedStepPlugin(Cubos& cubos)
return false;
});

cubos.system("accumulate time resource").before(fixedStepTag).call([](AccumulatedTime& timer, const DeltaTime& dt) {
timer.value += dt.value();
});
cubos.system("accumulate time resource")
.before(fixedStepTag)
.call([](AccumulatedTime& timer, const DeltaTime& dt, const FixedDeltaTime& step) {
timer.value += std::min(dt.value(), 2 * step.value);
});
}
2 changes: 1 addition & 1 deletion engine/src/physics/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,5 @@ void cubos::engine::physicsPlugin(Cubos& cubos)
}
});

cubos.tag(physicsApplyForcesTag);
cubos.tag(physicsApplyForcesTag).tagged(fixedStepTag);
}

0 comments on commit fba21ee

Please sign in to comment.