Skip to content
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

Fix: [Win32] now we are drawing on a tick, no longer use WM_PAINT #8702

Merged
merged 2 commits into from Feb 20, 2021

Conversation

TrueBrain
Copy link
Member

Motivation / Problem

With the 60fps patch, mouse movements should be silky smooth on Windows too. It was not. It turns out it is because I assumed WM_PAINT worked slightly different than it does.

Description

In the old days, are drawing was driven by WM_PAINT, when ever Windows decided it was a good time to redraw the screen. This is based on when we send InvalidateRect to the window. This is a good system if you don't care about fps and just want to redraw when ever is best for the OS.

With the 60fps patch, we do care when we redraw. So depending on WM_PAINT gives a "lagging" effect, especially noticeable with mouse movements. When ever you move your mouse, we register it, tell Windows to redraw the window, which happens .. some time later. So you get this feeling you mouse is never where it should be.

So, instead, what is perfectly normal for games to do, is to drive the drawing yourself. As we already have a draw-tick, we can do this perfectly fine.

It does mean we can no longer depend on InvalidateRect, as GetUpdateRect does not return the same value you just set with InvalidateRect without yielding. Shocker, I know. So, instead, the Win32 video driver is now a lot more like all other drivers, and records its own dirty-rect, and redraws that screen.

WM_PAINT is still used if outside influences trigger an GetUpdateRect, to indicate an overlapping window moved etc. We will redraw that surface once it has done.

In a result, we will be redrawing more and too much in more cases (especially when the window is being overlapped by another). This is a consequence of wanting to hit 60fps :)

Result: silky smooth mouse movement on Windows too!

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

WM_PAINT hits when-ever Windows feels like, but always after we
marked the screen as dirty. In result, it was lagging behind,
giving a sub-60fps experience.

With the new draw-tick there is no longer a need to be driven by
WM_PAINT, so it is better anyway to drive the drawing ourself. As
an added bonus this makes the win32 driver more like the others.
…message

Win32 was the only video driver doing this. It is just a bit too
much random.
@TrueBrain TrueBrain merged commit 08821f8 into OpenTTD:master Feb 20, 2021
@TrueBrain TrueBrain deleted the win32-wm-paint branch February 20, 2021 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants