diff options
author | tcsullivan <tullivan99@gmail.com> | 2019-08-25 15:28:57 -0400 |
---|---|---|
committer | tcsullivan <tullivan99@gmail.com> | 2019-08-25 15:28:57 -0400 |
commit | 036816eee4972b96196c8becbfc534c8b045150a (patch) | |
tree | 4beb3316d17cc3b653454c8fcc4abd6ab91add52 /src/main.cpp | |
parent | a3009ec0079769837dcbd690b0fb1ba54d379a85 (diff) |
added logic and render loops
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
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 <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); +} + |