aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--src/main.cpp31
2 files changed, 30 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 9d2f336..46e61b7 100644
--- 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 \
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);
+}
+