From 4a0863f343fa6f68639759494e3c0f0ab8ae2a76 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Sun, 7 Dec 2008 12:39:53 -0500 Subject: [PATCH] moved event pumping onto the draw thread, should fix windows event problems --- src/input/inputManager.cpp | 16 +++++++++++----- src/input/inputManager.h | 9 ++++----- src/main.cpp | 2 ++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/input/inputManager.cpp b/src/input/inputManager.cpp index 21934c4..94b645d 100644 --- a/src/input/inputManager.cpp +++ b/src/input/inputManager.cpp @@ -18,6 +18,8 @@ #include "inputManager.h" #include "../debug.h" +#include + #include "../config/keys.h" @@ -48,6 +50,8 @@ void input::clean() /// ***** Public Methods ***** +const Uint32 eventMask = -1; // ALL events + void input::update() { SDL_Event event; @@ -60,7 +64,7 @@ void input::update() keyState[i] = isP; } - while(SDL_PollEvent(&event)) + while(0 < SDL_PeepEvents(&event, 1, SDL_GETEVENT, eventMask)) { switch(event.type) { @@ -73,6 +77,8 @@ void input::update() case SDL_QUIT: keyState[key::end] = wasR; break; + default: + break; } } } @@ -98,20 +104,20 @@ bool input::mouseRight() return state & SDL_BUTTON(3); } -bool input::isPressed(SDLKey key) +bool input::isPressed(const SDLKey& key) { return keyState[key] == isP || keyState[key] == wasP; } -bool input::isReleased(SDLKey key) +bool input::isReleased(const SDLKey& key) { return keyState[key] == isR || keyState[key] == wasR; } -bool input::wasPressed(SDLKey key) +bool input::wasPressed(const SDLKey& key) { return keyState[key] == wasP; } -bool input::wasReleased(SDLKey key) +bool input::wasReleased(const SDLKey& key) { return keyState[key] == wasR; } diff --git a/src/input/inputManager.h b/src/input/inputManager.h index 829dbc3..e0450b2 100644 --- a/src/input/inputManager.h +++ b/src/input/inputManager.h @@ -21,7 +21,6 @@ #include #include "../Vector2.h" - /// ***** Header Methods ***** namespace input @@ -36,11 +35,11 @@ namespace input bool mouseLeft(); bool mouseRight(); - bool isPressed(SDLKey); - bool isReleased(SDLKey); + bool isPressed(const SDLKey&); + bool isReleased(const SDLKey&); - bool wasPressed(SDLKey); - bool wasReleased(SDLKey); + bool wasPressed(const SDLKey&); + bool wasReleased(const SDLKey&); } #endif // INPUT_H diff --git a/src/main.cpp b/src/main.cpp index f94fac6..e932742 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -209,6 +209,8 @@ void draw() { game::draw(); + SDL_PumpEvents(); // has to be on the Draw thread for the Windows API + SDL_GL_SwapBuffers(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -- 2.10.2