]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
added logic and render loops
authortcsullivan <tullivan99@gmail.com>
Sun, 25 Aug 2019 19:28:57 +0000 (15:28 -0400)
committertcsullivan <tullivan99@gmail.com>
Sun, 25 Aug 2019 19:28:57 +0000 (15:28 -0400)
Makefile
src/main.cpp

index 9d2f336b7beb40a6fd5ac1a872a9684605f7236b..46e61b73592a51a5aa9e6a9e228ab3aad9eaa940 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@
 CC  = gcc
 CXX = g++
 
-LIBS = -lSDL2
+LIBS = -lSDL2 -lpthread
 
 CXXFLAGS = -ggdb -std=c++17 \
        -Wall -Wextra -Werror -pedantic \
index bd531014c7f1f115dc76cd11e7fa73ded1aa753a..707c912b66eddeca02624050748b5286c1283f92 100644 (file)
 
 #include <SDL2/SDL.h>
 
+#include <atomic>
+#include <chrono>
 #include <iostream>
 #include <memory>
+#include <thread>
 
 constexpr const char *title = "gamedev2";
 constexpr int width = 640;
 constexpr int height = 480;
 
+std::atomic_bool shouldRun;
+
+static void renderLoop(void);
+static void logicLoop(void);
+
 int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[])
 {
        // Initialize SDL
@@ -49,9 +57,28 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[])
                return -1;
        }
 
-       // TODO game
-       SDL_Delay(1000);
+       // Start game
+       shouldRun.store(true);
+       std::thread logic (logicLoop);
+       renderLoop();
+       logic.join();
 
        return 0;
 }
 
+void renderLoop(void)
+{
+       using namespace std::chrono_literals;
+
+       // TODO render
+       while (shouldRun.load())
+               std::this_thread::sleep_for(100ms);
+}
+
+void logicLoop(void)
+{
+       // TODO handle logic
+       SDL_Delay(1000);
+       shouldRun.store(false);
+}
+