From 036816eee4972b96196c8becbfc534c8b045150a Mon Sep 17 00:00:00 2001 From: tcsullivan Date: Sun, 25 Aug 2019 15:28:57 -0400 Subject: added logic and render loops --- src/main.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index bd53101..707c912 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,13 +20,21 @@ #include +#include +#include #include #include +#include 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); +} + -- cgit v1.2.3