]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
added SDL key events
authortcsullivan <tullivan99@gmail.com>
Sun, 25 Aug 2019 19:49:06 +0000 (15:49 -0400)
committertcsullivan <tullivan99@gmail.com>
Sun, 25 Aug 2019 19:49:06 +0000 (15:49 -0400)
src/main.cpp

index 707c912b66eddeca02624050748b5286c1283f92..778ae732f8ded96c431a71a40a25f4e5251b2209 100644 (file)
@@ -77,8 +77,24 @@ void renderLoop(void)
 
 void logicLoop(void)
 {
-       // TODO handle logic
-       SDL_Delay(1000);
-       shouldRun.store(false);
+       using namespace std::chrono_literals;
+
+       std::cout << "Press escape to exit." << std::endl;
+
+       while (shouldRun.load()) {
+               for (SDL_Event event; SDL_PollEvent(&event);) {
+                       switch (event.type) {
+                       case SDL_KEYUP:
+                               // Exit game on escape
+                               if (event.key.keysym.sym == SDLK_ESCAPE)
+                                       shouldRun.store(false);
+                               break;
+                       default:
+                               break;
+                       }
+               }
+
+               std::this_thread::sleep_for(100ms);
+       }
 }