moved event pumping onto the draw thread, should fix windows event problems
[physics.git] / src / input / inputManager.cpp
index ebbd72e..94b645d 100644 (file)
 #include "inputManager.h"
 #include "../debug.h"
 
+#include <SDL/SDL.h>
+
+#include "../config/keys.h"
+
 
 /// ***** Private Variables *****
 
@@ -46,6 +50,8 @@ void input::clean()
 
 /// ***** Public Methods *****
 
+const Uint32 eventMask = -1; // ALL events
+
 void input::update()
 {
     SDL_Event event;
@@ -58,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)
         {
@@ -68,6 +74,11 @@ void input::update()
         case SDL_KEYDOWN:
             keyState[event.key.keysym.sym] = wasP;
             break;
+        case SDL_QUIT:
+            keyState[key::end] = wasR;
+            break;
+        default:
+            break;
         }
     }
 }
@@ -93,20 +104,20 @@ bool input::mouseRight()
     return state & SDL_BUTTON(3);
 }
 
-bool input::isPressed(Uint8 key)
+bool input::isPressed(const SDLKey& key)
 {
     return keyState[key] == isP || keyState[key] == wasP;
 }
-bool input::isReleased(Uint8 key)
+bool input::isReleased(const SDLKey& key)
 {
     return keyState[key] == isR || keyState[key] == wasR;
 }
 
-bool input::wasPressed(Uint8 key)
+bool input::wasPressed(const SDLKey& key)
 {
     return keyState[key] == wasP;
 }
-bool input::wasReleased(Uint8 key)
+bool input::wasReleased(const SDLKey& key)
 {
     return keyState[key] == wasR;
 }