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

With win32 video driver, mouse movement is very sluggish #8658

Closed
TrueBrain opened this issue Feb 9, 2021 · 5 comments · Fixed by #8660
Closed

With win32 video driver, mouse movement is very sluggish #8658

TrueBrain opened this issue Feb 9, 2021 · 5 comments · Fixed by #8660
Labels
needs triage This issue needs further investigation before it becomes actionable OS: Windows This issue is related to a MS Windows problem

Comments

@TrueBrain
Copy link
Member

Version of OpenTTD

1.10.3 / 1.11.0-beta1

Expected result

Mouse movement of at least 30fps.

Actual result

Mouse movement of < 30fps.

Steps to reproduce

Start the game on a recent updated Windows.

Technical details

OpenTTD uses Sleep(1) to yield the process back to the OS when the gameloop was called before the next tick. It handles events, updates the mouse etc, and then does a Sleep(1). In the old days, this yielded for a few ms. With recent update of Windows, it yields for 60+ms. This delay is so severe, that the game will miss its deadline for the next tick, but for me even worse: mouse movement feels really sluggish.

It is most likely related to: https://randomascii.wordpress.com/2020/10/04/windows-timer-resolution-the-great-rule-change/

This was found when fiddling with SDL2 on Windows. SDL sets the timer resolution to a much higher value (so lower ms), resulting in a much smoother mouse movement. So possibly we can borrow the solution there in our own codebase.

@TrueBrain TrueBrain added needs triage This issue needs further investigation before it becomes actionable OS: Windows This issue is related to a MS Windows problem labels Feb 9, 2021
@erenes
Copy link

erenes commented Feb 9, 2021

I don't think I really notice this at all (OTTD 1.10.3 + Win 10 20H2 19042.746).
I can tell the mouse cursor is drawn quite slowly if I move the mouse slowly, but it always points where I want it.

@James103
Copy link
Contributor

James103 commented Feb 9, 2021

From the blog post, the bug should not occur on Windows 10 1909, even though you should be able to reproduce the bug on Windows 10 2004.

@glx22
Copy link
Contributor

glx22 commented Feb 9, 2021

Can't test as I'm still on 1909, but I wonder if music playback with dmusic driver is affected, as it also uses Sleep().
BTW it should be quite trivial to fix (I already have some ideas).

@glx22
Copy link
Contributor

glx22 commented Feb 9, 2021

Not opening a pull request as I can't really test if it fixes the problem, but I have a possible solution here

@TrueBrain
Copy link
Member Author

Measurements via TIC/TOC:

With your patch: ~7ms per CSleep(1).
Without your patch: ~46ms per CSleep(1).

SDL (on Windows): ~7ms per CSleep(1).

So yeah, works for me :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue needs further investigation before it becomes actionable OS: Windows This issue is related to a MS Windows problem
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants