From 92354e8a08d020cc1719fa8806048dd8604d2df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 6 Mar 2016 17:20:14 +0100 Subject: [PATCH] Fixed windowsgpu updates --- Makefile | 4 ++-- include/lupi.h | 1 - src/c/event/event.c | 4 ---- src/c/gpu/winapigpu.c | 55 +++++++++++++++++++++++++++---------------- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index aa624da..9cca525 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,8 @@ PREFIX?=x86_64-linux-musl CC = $(PREFIX)-gcc -CFLAGS?=-O2 -std=c99 -fdata-sections -ffunction-sections -LDFLAGS+= -O2 -Wl,--gc-sections -static -Ldependencies/lib-$(PREFIX) +CFLAGS?=-O2 -std=c99 -fdata-sections -ffunction-sections -pthread +LDFLAGS+= -O2 -Wl,--gc-sections -static -Ldependencies/lib-$(PREFIX) -pthread # Project specific stuff BUILD = bin/ diff --git a/include/lupi.h b/include/lupi.h index 06410fb..0c0a83c 100644 --- a/include/lupi.h +++ b/include/lupi.h @@ -32,7 +32,6 @@ int event_pull(int timeout); #ifdef _WIN32 void winapigpu_init(lua_State* L); -int winapigpu_events(); #endif #endif diff --git a/src/c/event/event.c b/src/c/event/event.c index 59849c9..bf313e9 100644 --- a/src/c/event/event.c +++ b/src/c/event/event.c @@ -59,10 +59,6 @@ static void add_events(struct timeval* timeout) { int event_pull(int _timeout) { int n = 0; -#ifdef _WIN32 - n = winapigpu_events(); - if(n > 0) return n; -#endif if(_timeout > 0) { /* wait max this much time for event */ struct timeval timeout = {_timeout / 1000, (_timeout % 1000) * 1000}; diff --git a/src/c/gpu/winapigpu.c b/src/c/gpu/winapigpu.c index f22fe7a..7681f09 100644 --- a/src/c/gpu/winapigpu.c +++ b/src/c/gpu/winapigpu.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #define BYPP 4 #define RES_X 800 @@ -21,6 +23,7 @@ #define uchar unsigned char +HWND hwnd; uchar *screenbb = NULL; HBITMAP screenbmap = NULL; char *colbuf = 0; @@ -72,6 +75,7 @@ static inline int win_draw_32(int x, int y, int bg, int fg, int chr, int cwd) { LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { + logn("win: Msg"); switch(msg) { case WM_PAINT: { logn("win: PAINT"); @@ -107,13 +111,11 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { return 0; } +static int win_draw(int x, int y, int bg, int fg, int chr); - - -static int l_open(lua_State *L) { +void* winapigpu_events(void* ign) { logn("win: INIT"); WNDCLASSEX wc; - HWND hwnd; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; @@ -129,9 +131,7 @@ static int l_open(lua_State *L) { wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) { - lua_pushboolean(L, 0); - lua_pushstring(L, "Window registration failed"); - return 2; + return 0; } hwnd = CreateWindowEx( @@ -143,9 +143,7 @@ static int l_open(lua_State *L) { NULL, NULL, GetModuleHandle(NULL), NULL); if(hwnd == NULL) { - lua_pushboolean(L, 0); - lua_pushstring(L, "Window creation failed"); - return 2; + return 0; } ShowWindow(hwnd, SW_SHOW); @@ -153,6 +151,27 @@ static int l_open(lua_State *L) { InvalidateRect(hwnd, NULL, TRUE); + win_draw(0,0,0,0xFFFFFF,'H'); + + MSG Msg; + while(GetMessage(&Msg, NULL, 0, 0) > 0) { + TranslateMessage(&Msg); + DispatchMessage(&Msg); + } + logn("winapi quit!!"); + return NULL; +} + +static int l_open(lua_State *L) { + pthread_t eventThread; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 0x800000); + pthread_create(&eventThread, &attr, winapigpu_events, NULL); + pthread_attr_destroy(&attr); + + struct timespec st = {.tv_sec = 0, .tv_nsec = 1000000}; + while(!screenbb) nanosleep(&st, NULL); lua_pushboolean(L, 1); return 1; } @@ -217,7 +236,9 @@ static int l_put (lua_State *L) { int bg = lua_tonumber(L, 3); int fg = lua_tonumber(L, 4); int chr = lua_tonumber(L, 5); - return win_draw(x, y, bg, fg, chr); + win_draw(x, y, bg, fg, chr); + InvalidateRect(hwnd, NULL, FALSE); + return 0; } static int l_get_nearest (lua_State *L) { @@ -276,6 +297,7 @@ static int l_copy (lua_State *L) { free(tmpcol); free(tmpchr); + InvalidateRect(hwnd, NULL, FALSE); } static int l_fill (lua_State *L) { @@ -292,6 +314,7 @@ static int l_fill (lua_State *L) { win_draw(j, i, bg, fg, chr); } } + InvalidateRect(hwnd, NULL, FALSE); return 0; } @@ -309,6 +332,7 @@ static int l_winfill (lua_State *L) { win_draw(j, i, bg, fg, chr); } } + InvalidateRect(hwnd, NULL, FALSE); return 0; } @@ -376,13 +400,4 @@ void winapigpu_init(lua_State* L) { luaL_openlib(L, "winapigpu", winlib, 0); } -int winapigpu_events() { - MSG Msg; - while(GetMessage(&Msg, NULL, 0, 0) > 0) { - TranslateMessage(&Msg); - DispatchMessage(&Msg); - } - return 0; -} - #endif