mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
Optimize SDL_WaitEventTimeout() for the SDL_PollEvent() case
There's no sense in doing all the setup for waiting if we're just polling.
This commit is contained in:
parent
85b51e6c92
commit
b992b915e5
@ -866,28 +866,25 @@ int
|
|||||||
SDL_WaitEventTimeout(SDL_Event * event, int timeout)
|
SDL_WaitEventTimeout(SDL_Event * event, int timeout)
|
||||||
{
|
{
|
||||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||||
SDL_bool need_polling = SDL_events_need_polling();
|
SDL_Window *wakeup_window;
|
||||||
SDL_Window *wakeup_window = NULL;
|
|
||||||
Uint32 expiration = 0;
|
Uint32 expiration = 0;
|
||||||
|
|
||||||
if (timeout > 0)
|
if (timeout > 0)
|
||||||
expiration = SDL_GetTicks() + timeout;
|
expiration = SDL_GetTicks() + timeout;
|
||||||
|
|
||||||
if (!need_polling && _this) {
|
if (timeout != 0 && _this && _this->WaitEventTimeout && _this->SendWakeupEvent && !SDL_events_need_polling()) {
|
||||||
/* Look if a shown window is available to send the wakeup event. */
|
/* Look if a shown window is available to send the wakeup event. */
|
||||||
wakeup_window = SDL_find_active_window(_this);
|
wakeup_window = SDL_find_active_window(_this);
|
||||||
need_polling = (wakeup_window == NULL);
|
if (wakeup_window) {
|
||||||
}
|
|
||||||
|
|
||||||
if (!need_polling && _this && _this->WaitEventTimeout && _this->SendWakeupEvent) {
|
|
||||||
int status = SDL_WaitEventTimeout_Device(_this, wakeup_window, event, timeout);
|
int status = SDL_WaitEventTimeout_Device(_this, wakeup_window, event, timeout);
|
||||||
|
|
||||||
/* There may be implementation-defined conditions where the backend cannot
|
/* There may be implementation-defined conditions where the backend cannot
|
||||||
reliably wait for the next event. If that happens, fall back to polling */
|
reliably wait for the next event. If that happens, fall back to polling. */
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
|
Loading…
Reference in New Issue
Block a user