summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-21 15:26:43 +0100
committerNao Pross <naopross@thearcway.org>2019-01-21 15:27:10 +0100
commit46a28a711fd730828ae5596f68ef3510a20b7b31 (patch)
tree95e1d89c6213fbb140e9b9c767eccdabab2eb369 /test
parentAdd window test (diff)
downloadlibwsdl2-46a28a711fd730828ae5596f68ef3510a20b7b31.tar.gz
libwsdl2-46a28a711fd730828ae5596f68ef3510a20b7b31.zip
Make window_test threaded
Diffstat (limited to 'test')
-rw-r--r--test/makefile2
-rw-r--r--test/window_test.cpp20
2 files changed, 19 insertions, 3 deletions
diff --git a/test/makefile b/test/makefile
index 11df431..ee8569a 100644
--- a/test/makefile
+++ b/test/makefile
@@ -1,7 +1,7 @@
# Compiler
CPP := c++
CFLAGS := -Wall -pedantic -std=c++17 -fPIC -I ../include -DDEBUG
-LFLAGS := ../build/libwrapsdl2.so -lSDL2
+LFLAGS := ../build/libwrapsdl2.so -lSDL2 -lpthread
SRCS := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,build/%.o,$(SRCS))
diff --git a/test/window_test.cpp b/test/window_test.cpp
index 70fcb1a..2136488 100644
--- a/test/window_test.cpp
+++ b/test/window_test.cpp
@@ -2,21 +2,37 @@
#include "video.hpp"
#include <iostream>
+#include <thread>
+#include <mutex>
int main(int argc, char *argv[]) {
wrapsdl2::initialize();
{
- wrapsdl2::window win("Window Test", 800, 600);
+ using namespace wrapsdl2;
+
+ window win("Window Test", 800, 600);
+ std::mutex win_mutex;
std::cout << "press ENTER to show the window" << std::endl;
std::cin.get();
win.show();
- win.update();
+
+ std::thread win_update([&]() {
+ std::lock_guard<std::mutex> lock(win_mutex);
+ while (win.is_open()) {
+ win.update();
+ wrapsdl2::delay(200);
+
+
+ }
+ });
std::cout << "press ENTER to quit" << std::endl;
std::cin.get();
+
+ win_update.join();
}
wrapsdl2::quit();