OpenTTD / OpenTTD

OpenTTD is an open source simulation game based upon Transport Tycoon Deluxe
https://www.openttd.org/
Other
6.36k stars 893 forks source link

[Bug]: Vsync kills the game smoothness, turning it off restores smoothness but gives tear screen lines #9839

Closed goofyseeker311 closed 2 years ago

goofyseeker311 commented 2 years ago

Version of OpenTTD

12.1 Windows 11

Expected result

turning vsync on (4K rtx 3060 60Hz) should be smooth 60Hz

Actual result

turning vsync on lags the snot out of the game, without vsync the game will scroll smoothly but obviously has random lines. frame rate drops to 30-40fps, from 60fps, using the internal game fps viewer.

Steps to reproduce

  1. acceleration on, full screen 4K
  2. turn on vsync
  3. observe huge lag
  4. turn off vsync
  5. observe smooth scroll but with the screen tear lines
Shituation commented 2 years ago

That's how Vsync works for all games, its not a bug. I also use 4K and at far zoom levels the lag is noticeable. Zooming in makes it normal again.

goofyseeker311 commented 2 years ago

My RK is 60Hz not 40Hz, what are you talking about, even 3D games run at full 60Hz with the RTX card, so it's your programming issue, best ~me

On Sat, Apr 2, 2022, 23:56 Shituation @.***> wrote:

That's how Vsync works for all games, its not a bug. I also use 4K and at far zoom levels the lag is noticeable. Zooming in makes it normal again.

— Reply to this email directly, view it on GitHub https://github.com/OpenTTD/OpenTTD/issues/9839#issuecomment-1086721958, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEX7K7UT5VQPT6JJ2W5LIEDVDCYA3ANCNFSM5RN26RLA . You are receiving this because you authored the thread.Message ID: @.***>

glx22 commented 2 years ago

OpenTTD internal speed is 30Hz (a tick is at most 33ms) and drawing used to happen during the tick but is now in a separated thread with some synchronisation, allowing higher refresh rates (and smoothness issues in some occasions)

goofyseeker311 commented 2 years ago

Fix the vsync issue, because I play in the no-vsync to get non-staggered gameplay, vsync should be strictly working at the vsync Hz, no matter the game logic

On Sun, Apr 3, 2022, 00:54 Loïc Guilloux @.***> wrote:

OpenTTD internal speed is 30Hz (a tick is at most 33ms) and drawing used to happen during the tick but is now in a separated thread with some synchronisation, allowing higher refresh rates (and smoothness issues in some occasions)

— Reply to this email directly, view it on GitHub https://github.com/OpenTTD/OpenTTD/issues/9839#issuecomment-1086730624, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEX7K7Q3KZNLCMXKROWXP4TVDC6XRANCNFSM5RN26RLA . You are receiving this because you authored the thread.Message ID: @.***>

goofyseeker311 commented 2 years ago

You could initiate the game logic from the vsync if selected, soft coupling

On Sun, Apr 3, 2022, 01:03 Tapio Palomäki @.***> wrote:

Fix the vsync issue, because I play in the no-vsync to get non-staggered gameplay, vsync should be strictly working at the vsync Hz, no matter the game logic

On Sun, Apr 3, 2022, 00:54 Loïc Guilloux @.***> wrote:

OpenTTD internal speed is 30Hz (a tick is at most 33ms) and drawing used to happen during the tick but is now in a separated thread with some synchronisation, allowing higher refresh rates (and smoothness issues in some occasions)

— Reply to this email directly, view it on GitHub https://github.com/OpenTTD/OpenTTD/issues/9839#issuecomment-1086730624, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEX7K7Q3KZNLCMXKROWXP4TVDC6XRANCNFSM5RN26RLA . You are receiving this because you authored the thread.Message ID: @.***>

TrueBrain commented 2 years ago

Sadly, there is very little we can do about this.

OpenTTD is an old game, intended for 640x480. We managed to do some pretty impressive optimizations over the years to render higher resolutions pretty well, but at a point it just breaks.

4k is a huge amount of pixels to render, even on normal zoom. The game simply wasn't designed for that, and it is not unlikely that even drawing a single frame takes more than 16ms. Sadly, as math will tell us, if a single frame takes more than 16ms to draw, it is impossible to reach 60fps. So you might claim "should be strictly working at the vsync Hz", but that is simply not how any game (and math) works. And with any game, especially if vsync is on, you will see that if the frame-to-render gets complex, fps suffers. Those two are strongly correlated, and that is just how things work.

Adding on top of that, we also need some time between frames to do some actual game-logic. And the more complex your game-logic becomes (so many trains, complex pathfinding, etc), the more the fps suffers. We already do some parts of that game-logic while the frame is being rendered, but there is only so much we can do before we have to wait for the vsync to return to us.

To release some pressure on the drawing, often people use 2x zoom to play on 4k monitors. This means 4(!) times less pixels have to be drawn, which makes OpenTTD very happy.

That all said and done, we keep on trying other ways to optimize the game. All the easy things are done, and now the hard things are beginning. For 1.11 we allowed the drawing to happen much more in parallel from the game-logic, which means on many machines you can now reach fast-forward speeds of over 9999x. And currently we are trying to separate the logic of sorting the sprites to draw from the game-logic. Sadly, as this game was created in 1994, there are some heavy dependencies between those two, making that far from a trivial job. But who knows, one day, we manage to do that. And that for sure will improve fps for everyone.

Till that time, sadly, this is what you get, and little we can do about it. But, if you are interested in helping out to solve this puzzle, you are more than welcome to give it a spin! That is the beauty about Open Source games :)

And to hook back to your observation and an earlier comment:

Vsync is doing exactly what it is suppose to do.

And that exactly is always the balance in games. If your frame takes too long to draw, what suffers? (as something has to suffer) The vsync setting (in these cases) gives you the option to pick what is least annoying to you: tearing (which is bad) or low fps (which is bad).

So sadly, I am going to close this ticket, with a very annoying "works as intended" message. Sorry about that, but I hope my explanations help you understand why. And hopefully some day soon in another release we have even more optimizations to make 4k more a reality .. till then .. you have to pick either of the two :(

goofyseeker311 commented 2 years ago

you never tried gpu acceleration

goofyseeker311 commented 2 years ago

none has to suffer your incompetence