-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
World.step is buggy when attempting to account for variable framerate #16
Comments
I added support for I updated the demo to highlight issues. The ping pong demo is particularly relevant. Well it's not easy to catch since the gif framerate is also super low. But you can notice that :
You can try it here demo/Pingpong So far I did not encounter wacky simulation explosions as referenced in schteppe#371 There one thing I find odd in the implementation. If maxSubStep is not sufficient to catch up with the actual time, the accumulator build up seconds of delay. So when the framerate gets better, to lower the accumulator the simulation will actually run faster for a few seconds ! here you can see in the log that the maxsubstep is not sufficient, so it fills up the accumulator. One strategy that I rather have would be to prevent the accumulator to build up more than X dt delay. |
I'm seeing the same issue here that I was seeing in my own local attempt at implementing Leave the wasted frames set to 0, and leave Leave the wasted frames set to 0, and turn |
the tab switching makes sense, since request animation frame gets paused, the delta when focusing back is huge. About the cube heap, it pretty interesting, it looks like the simulation takes too long to be renderer at live speed. It takes more than In that case it is indeed a better solution to slow down the simulation, giving up on rendering at live speed. One obvious fix could be to prevent the accumulator to grow out of control, as I don't see any situation where it leads to expected behaviour. We could also detect slow rendering simulation and shortcut them for the sake of keeping a good framerate at the cost of slowing down the simulation. About the cube freezing midair, I am not entirely sure, but I suspect it has something to do with the cube going into a broken sleep mode. this.time is increase by an amount that might be higher than the delta of the simulation |
Is this PR somehow related? I think we should bring in that PR as well, it was closed because it didn't receive any attention. |
yes it seems so, although it also brings questionable features ( "timeSinceLastCalled = -1 instead of 0" ) I am not sure this address the cube freezing midair effect, I am looking into that. |
You're right, if (timeSinceLastCalled === undefined) { and stop. Get rid of the Can you do that in your existing PR? Or should we do a different PR? |
@marcofugaro agreed 8c8aea5 tbh I rather have two methods. How about renaming internalStep step, and allowing it to be called publicly, and renaming the actual step something like |
That's a big api change 😬maybe if this library was a standalone physics library instead of a fork of cannon, we could have done it. The only valid api changes I see are the ones to modernize the library and the ones that make it more compatible with Three.js |
Yes You are right. I was thinking loudly :) |
I agree with Marco regarding API changes, we should strive to make as few API changes as possible, and maintain backwards compatibility where we can. @Platane Great work on this so far, I think supporting variable framerate would be a huge feature. EDIT: I spoke too soon regarding framerate performance |
@Platane I spoke too soon in my last comment, the framerate is still degrading heavily over time on the latest of your fork with I wonder if this commit might give us some insight into how the accumulator was expected to be used, and why If all else fails, we could tweet Schteppe and see if he remembers... |
ok I will check. What environment are you using ? I can't reproduce the frame rate drop on chrome desktop :/ |
I'm using Google Chrome Version 81.0.4044.92 (Official Build) (64-bit), on Windows 10 x64, on an extremely powerful desktop (Intel [email protected], Nvidia 1080TI, 16GB DDR4 4400 RAM). I can test with a Mac on Chrome and Safari later today. I just set the The framerate degradation is mentioned in cannon.js issue 371, along with this quote from Schteppe:
|
@Platane I may have made some mistake in my testing. I set everything up from scratch and stuff is looking much better.
It also looks like the framerate degradation may be completely gone, although I want to leave this running for longer before I say for sure. However, when setting |
Ok good, that seems consistent with what I experienced so far. The simulation might appear sped up when increasing the maxSubStep if one step was not sufficient to render at live speed. I am focusing on the freezing cube issue. I don't see it as often as before, but still more than never (which is the case in the current stable version) |
Would you expect that the simulation stays sped up consistently? It seems like it should catch up at some point, but that doesn't seem to be the case while testing the cube heap demo. |
I think the sped up version is the actual speed. It was previously slower because we restricted to one step (1/60s of simulation ) each animation frame ( > 1/60s of real time ). |
But wouldn't it only be slower if it wasn't achieving 60fps? I thought the whole point of variable framerate stepping is to achieve the same simulation speed between high-performance 60fps code and low-performance variable framerate code? My concern is that the non-variable step that's been the default in Cannon for years has set an expectation for the speed of the simulation when it's achieving 60fps - and I would expect that to be the same speed in the substep method. That seems to be what Schteppe implies with his comments as well. In other words, I would have expected the 1/60 constant step simulation to be at max speed when running 60fps, and wouldn't have expected the variable step simulation to always exceed that speed |
yes that's the goal. Unless something goes wrong in the current version (which is probable), it should do exacty that. |
Released fix in |
When passing a
timeSinceLastCalled
value to theworld.step
method, the simulation performance quickly degrades beyond usability.Example usage: Cannon demo
cannon.js issue 371
Article: Fix your timestep
Spectrum chat: World step does not adapt to framerate
Per Schteppe (schteppe#371):
The text was updated successfully, but these errors were encountered: