From f1e48fffe3c224ee81cdc1f85dbd0179b202d457 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 8 Sep 2017 19:38:59 +0300 Subject: Split SDL_WaitEventTimeout/SDL_PollEvent into lower level SDL function calls. --- src/utils/sdl2helper.cpp | 11 +++++++++++ src/utils/sdl2helper.h | 4 ++++ src/utils/sdlhelper.cpp | 10 ++++++++++ src/utils/sdlhelper.h | 4 ++++ 4 files changed, 29 insertions(+) (limited to 'src/utils') diff --git a/src/utils/sdl2helper.cpp b/src/utils/sdl2helper.cpp index 7648ccc2b..da5b15e41 100644 --- a/src/utils/sdl2helper.cpp +++ b/src/utils/sdl2helper.cpp @@ -30,6 +30,7 @@ PRAGMA48(GCC diagnostic push) PRAGMA48(GCC diagnostic ignored "-Wshadow") +#include #include PRAGMA48(GCC diagnostic pop) @@ -194,4 +195,14 @@ void SDL::WaitThread(SDL_Thread *const thread) SDL_WaitThread(thread, nullptr); } +bool SDL::PollEvent(SDL_Event *event) +{ + SDL_PumpEvents(); + return SDL_PeepEvents(event, + 1, + SDL_GETEVENT, + SDL_FIRSTEVENT, + SDL_LASTEVENT) > 0; +} + #endif // USE_SDL2 diff --git a/src/utils/sdl2helper.h b/src/utils/sdl2helper.h index 089bbbfab..d1b474d50 100644 --- a/src/utils/sdl2helper.h +++ b/src/utils/sdl2helper.h @@ -31,6 +31,8 @@ PRAGMA48(GCC diagnostic ignored "-Wshadow") #include PRAGMA48(GCC diagnostic pop) +union SDL_Event; + struct SDL_Surface; struct SDL_SysWMinfo; struct SDL_Window; @@ -65,6 +67,8 @@ namespace SDL void initLogger(); void WaitThread(SDL_Thread *const thread); + + bool PollEvent(SDL_Event *event); } // namespace SDL #endif // USE_SDL2 diff --git a/src/utils/sdlhelper.cpp b/src/utils/sdlhelper.cpp index 324779898..2e3576578 100644 --- a/src/utils/sdlhelper.cpp +++ b/src/utils/sdlhelper.cpp @@ -33,6 +33,7 @@ PRAGMA48(GCC diagnostic push) PRAGMA48(GCC diagnostic ignored "-Wshadow") +#include #include #include PRAGMA48(GCC diagnostic pop) @@ -192,4 +193,13 @@ void SDL::WaitThread(SDL_Thread *const thread) SDL_WaitThread(thread, nullptr); } +bool SDL::PollEvent(SDL_Event *event) +{ + SDL_PumpEvents(); + return SDL_PeepEvents(event, + 1, + SDL_GETEVENT, + SDL_ALLEVENTS) > 0; +} + #endif // USE_SDL2 diff --git a/src/utils/sdlhelper.h b/src/utils/sdlhelper.h index abb3934cb..67a979da3 100644 --- a/src/utils/sdlhelper.h +++ b/src/utils/sdlhelper.h @@ -35,6 +35,8 @@ PRAGMA48(GCC diagnostic ignored "-Wshadow") #include PRAGMA48(GCC diagnostic pop) +union SDL_Event; + struct SDL_Surface; struct SDL_SysWMinfo; @@ -71,6 +73,8 @@ namespace SDL void initLogger(); void WaitThread(SDL_Thread *const thread); + + bool PollEvent(SDL_Event *event); } // namespace SDL #endif // USE_SDL2 -- cgit v1.2.3-60-g2f50