From 46a28a711fd730828ae5596f68ef3510a20b7b31 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 21 Jan 2019 15:26:43 +0100 Subject: Make window_test threaded --- test/makefile | 2 +- test/window_test.cpp | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'test') 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 +#include +#include 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 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(); -- cgit v1.2.1