Should "step" function be more pure / time independent?

Currently, when calling “step” function on the mechanical_world it not only relies on fixed update period but also talks to the system to get the current Instant (though I am not sure if and how Counters are related to the simulation).
Imagine now the following situation where I’ve got a game where my simulation step is 1/60s but my frame rate varies between 30fps and 60fps (e.g. on slower PC). That would cause that the time in my game will diverge form the real one causing lags and other unpredictable results.
In order to simplify the interface I would suggest that the “step” function should accept two more arguments:

  • currentTimestamp (ms/µs) - absolute timestamp for logging and debugging
  • deltaTimestamp (ms/µs) - time passed since last step call.
    It should be users’ responsibility to compute the delta and make it as small as possible. Therefore no references to absolute time from within the engine would be needed.
    BTW I know I can modify “dt” param before each step call, yet it is not what I expect.

I would be happy to provide a PR if that sounds reasonable.

Hi!

The step function, only relies on the user-defined timestep (modifiable with mechanical_world.set_timestep or mechanical_world.integration_parameters.set_dt). The Counters , and thus the reliance on the system clock, are unrelated to the simulation, they only exist for debugging and profiling purpose (and are disabled by default).

So the simulation you get is completely independent from the performance of your computer.

To be clear, specifying a timestep equal to, say, 16ms, means that the time in the physical world will advance by 16ms. It does not mean that the execution of the step function is constrained to be equal to 16ms. It can happen that the step function takes less or more than 16ms to execute, depending on the physical world complexity and your computer efficiency.

In typical uses of physics engine (say, for games) the physics is stepped with a constant timestep. Then it is the responsibility of another component of the game engine/animation framework/whatever to use extrapolation or interpolation to adjust for the fact the step took less or more than the specified dt.

BTW I know I can modify “dt” param before each step call, yet it is not what I expect.

What did you try exactly and what result did you expect?