-
Notifications
You must be signed in to change notification settings - Fork 264
fix gui not responding when the game is paused #151
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
Conversation
|
Looks good to me, merged. Slow polling while paused was a feature from the original game. |
|
I've checked what was causing this "laggy" behavior and the history of the related code. This seems to be related to the number of events generated by the system. In that function (before this PR): int winmain::ProcessWindowMessages()
{
static auto idleWait = 0;
SDL_Event event;
if (has_focus && !single_step)
{
idleWait = static_cast<int>(TargetFrameTime.count());
while (SDL_PollEvent(&event))
{
if (!event_handler(&event))
return 0;
}
return 1;
}
// Progressively wait longer when transitioning to idle
idleWait = std::min(idleWait + static_cast<int>(TargetFrameTime.count()), 500);
if (SDL_WaitEventTimeout(&event, idleWait))
{
idleWait = static_cast<int>(TargetFrameTime.count());
return event_handler(&event);
}
return 1;
}When paused (with F3), the SDL_PollEvent is never called. Events get processed only by SDL_WaitEventTimeout.
I use a high DPI mouse which might be the cause of the high number of generated mouse move event. I've also checked and found that the old behavior (before this PR) is from the older code that was using GetMessage/PeekMessage,
while(1)
{
while (PeekMessageA(&Msg, nullptr, 0, 0, 1u))
{ ... }
debugStuff?()
displayFrame()
sleep(time before next frame)
}
while(1)
{
GetMessageA(&Msg, hwnd_frame, 0, 0);
debugStuff?()
}Which means that when the game was paused, the only thing it was doing is looping on GetMessage without any Sleep() which explain why it was not "lagging" (at least not in wine on linux).
int winmain::ProcessWindowMessages()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (!event_handler(&event))
return 0;
}
return 1;
}
While I'm here I've a question about the variable |
|
I have found that the sleep() is only called when the window has focus. So when So the ProcessWindowMessages function is good at it is now and my proposition to simplify it must not be implemented. |
|
About event stuff:
The way I see it: About original code: About sleep and events: About single_step: To sum it up: |
|
I got curious, so I tried it with this PR rolled back on my Linux VMs. So, not all Linux setups have this problem. |
When the game is paused (with F3), the GUI become less and less responsive to mouse and keyboard:
simplescreenrecorder-2022-08-08_22.25.24.mp4
The patch keep the polling of input event active even when the game is paused, by not checking single_step.
The resulting behavior is a fluid GUI even when the game is paused:
simplescreenrecorder-2022-08-08_22.27.09.mp4