summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-09-08 19:38:59 +0300
committerAndrei Karas <akaras@inbox.ru>2017-09-08 19:38:59 +0300
commitf1e48fffe3c224ee81cdc1f85dbd0179b202d457 (patch)
treea180b55377204e85c52a4accf35ecc964f2d2cca
parent29557a45208b1576e293427090360f6d794ea6b3 (diff)
downloadplus-f1e48fffe3c224ee81cdc1f85dbd0179b202d457.tar.gz
plus-f1e48fffe3c224ee81cdc1f85dbd0179b202d457.tar.bz2
plus-f1e48fffe3c224ee81cdc1f85dbd0179b202d457.tar.xz
plus-f1e48fffe3c224ee81cdc1f85dbd0179b202d457.zip
Split SDL_WaitEventTimeout/SDL_PollEvent into lower level SDL function calls.
-rw-r--r--src/eventsmanager.cpp5
-rw-r--r--src/sdlshared.h1
-rw-r--r--src/utils/sdl2helper.cpp11
-rw-r--r--src/utils/sdl2helper.h4
-rw-r--r--src/utils/sdlhelper.cpp10
-rw-r--r--src/utils/sdlhelper.h4
6 files changed, 32 insertions, 3 deletions
diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp
index 2db3e8869..efd300f9c 100644
--- a/src/eventsmanager.cpp
+++ b/src/eventsmanager.cpp
@@ -44,6 +44,7 @@
#endif // USE_SDL2
#include "utils/process.h"
+#include "utils/sdlhelper.h"
#include "debug.h"
@@ -137,7 +138,7 @@ bool EventsManager::handleEvents() const
{
SDL_Event event;
// Handle SDL events
- while (SDL_WaitEventTimeout(&event, 0))
+ while (SDL::PollEvent(&event))
{
if (!handleCommonEvents(event))
{
@@ -187,7 +188,7 @@ void EventsManager::handleGameEvents() const
// Events
SDL_Event event;
- while (SDL_WaitEventTimeout(&event, 0))
+ while (SDL::PollEvent(&event))
{
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
game->updateHistory(event);
diff --git a/src/sdlshared.h b/src/sdlshared.h
index 2dec6aada..71273d82f 100644
--- a/src/sdlshared.h
+++ b/src/sdlshared.h
@@ -59,7 +59,6 @@
#define SDL_Window SDL_Surface
#define SDL_JoystickNameForIndex SDL_JoystickName
#define SurfaceImageHelper SDLImageHelper
-#define SDL_WaitEventTimeout(event, time) SDL_PollEvent(event)
#define SDL_GLContext (void*)
#endif // USE_SDL2
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 <SDL_events.h>
#include <SDL_syswm.h>
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 <SDL_thread.h>
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 <SDL_events.h>
#include <SDL_syswm.h>
#include <SDL_video.h>
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 <SDL_thread.h>
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