PixelGuys / Cubyz

Voxel sandbox game with a large render distance, procedurally generated content and some cool graphical effects.
GNU General Public License v3.0
447 stars 56 forks source link

Suggestion: Separate update loops #692

Open ITR13 opened 2 months ago

ITR13 commented 2 months ago

Currently physics are framerate dependent, which can cause inconsistencies down the line. A common solution to this is having physics only run at a fixed rate (I.E. 60 or 120fps) with a potential catch-up mechanic if rendering is slow.

Some benefits from this:

Some drawbacks:

IntegratedQuantum commented 2 months ago

Another disadvantage is that it would increase input lag for players without vsync, because the physics will always be up to one physics tick behind the player input.

I think #599 is happening because the player moves an amount smaller than the margin used by collision. A solution would be to find a way to store more exact collision results without a margin.

533 can be solved by just implementing the catch-up mechanic without fixing all updates to a certain frequency.

ITR13 commented 2 months ago

Another disadvantage is that it would increase input lag for players without vsync, because the physics will always be up to one physics tick behind the player input.

This is the case for almost any game though, even competitive ones. Could also be possible to separate stuff driven more directly by player input like rotation or placing/removing blocks & interacting with UI to not be bound by a rate.

I think https://github.com/PixelGuys/Cubyz/issues/599 is happening because the player moves an amount smaller than the margin used by collision. A solution would be to find a way to store more exact collision results without a margin.

Hmm, collision does in theory set the position to the collision point near the end of the frame though. I tried disabling the spring & friction logic in case it was that, but didn't seem to do anything. I'll try disabling that part and see if it is.

https://github.com/PixelGuys/Cubyz/issues/533 can be solved by just implementing the catch-up mechanic without fixing all updates to a certain frequency.

That might not work since the physics happen so quickly. If the GPU take 16ms to render for example, and the physics only take 0.1ms, then it could end up doing all the catch up physics frames immediately then have to wait for the GPU to finish rendering before it can bind it again. I guess if vsync was made to only affect rendering then that might automatically balance it though (or maybe that's what you meant?)