From f872a5f0944c6d4f7b6ce49d4e922f6f75edb4f6 Mon Sep 17 00:00:00 2001 From: bjorn Date: Thu, 30 Aug 2018 22:09:54 -0700 Subject: [PATCH] Re-enable threads for emscripten; They don't appear to work very well but this simplifies code a lot. --- CMakeLists.txt | 18 ++++++++---------- src/api/event.c | 2 -- src/api/lovr.c | 4 ---- src/event/event.h | 6 ------ src/lovr.c | 2 -- src/luax.c | 5 ----- src/luax.h | 1 - src/util.h | 4 ---- 8 files changed, 8 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4dcce16..a916f390 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,7 +225,7 @@ if(NOT EMSCRIPTEN) endif() # pthreads -if(NOT WIN32 AND NOT EMSCRIPTEN) +if(NOT WIN32) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) set(LOVR_PTHREADS Threads::Threads) @@ -242,11 +242,13 @@ set(LOVR_SRC src/api/lovr.c src/api/math.c src/api/physics.c + src/api/thread.c src/api/timer.c src/api/types/animator.c src/api/types/audioStream.c src/api/types/blob.c src/api/types/canvas.c + src/api/types/channel.c src/api/types/collider.c src/api/types/controller.c src/api/types/font.c @@ -265,6 +267,7 @@ set(LOVR_SRC src/api/types/source.c src/api/types/texture.c src/api/types/textureData.c + src/api/types/thread.c src/api/types/transform.c src/api/types/vertexData.c src/api/types/world.c @@ -297,6 +300,7 @@ set(LOVR_SRC src/lib/stb/stb_image_write.c src/lib/stb/stb_truetype.c src/lib/stb/stb_vorbis.c + src/lib/tinycthread/tinycthread.c src/lib/vec/vec.c src/lovr.c src/luax.c @@ -309,6 +313,8 @@ set(LOVR_SRC src/math/vec3.c src/physics/physics.c src/resources/shaders.c + src/thread/channel.c + src/thread/thread.c src/timer/timer.c src/util.c ${LOVR_AUDIO_SRC} @@ -318,15 +324,7 @@ set(LOVR_SRC if(EMSCRIPTEN) set(LOVR_SRC ${LOVR_SRC} src/headset/webvr.c) else() - set(LOVR_SRC ${LOVR_SRC} - src/headset/openvr.c - src/api/thread.c - src/api/types/channel.c - src/api/types/thread.c - src/lib/tinycthread/tinycthread.c - src/thread/channel.c - src/thread/thread.c - ) + set(LOVR_SRC ${LOVR_SRC} src/headset/openvr.c) endif() # LÖVR diff --git a/src/api/event.c b/src/api/event.c index 1136f9cb..ddffba8e 100644 --- a/src/api/event.c +++ b/src/api/event.c @@ -88,13 +88,11 @@ static int nextEvent(lua_State* L) { lua_pushboolean(L, event.data.boolean.value); return 2; -#ifndef EMSCRIPTEN case EVENT_THREAD_ERROR: luax_pushobject(L, event.data.thread.thread); lua_pushstring(L, event.data.thread.error); free((void*) event.data.thread.error); return 3; -#endif case EVENT_CONTROLLER_ADDED: case EVENT_CONTROLLER_REMOVED: diff --git a/src/api/lovr.c b/src/api/lovr.c index d1b9f5bb..cdd4b9c8 100644 --- a/src/api/lovr.c +++ b/src/api/lovr.c @@ -19,11 +19,7 @@ int l_lovrInit(lua_State* L) { luax_preloadmodule(L, "lovr.headset", l_lovrHeadsetInit); luax_preloadmodule(L, "lovr.math", l_lovrMathInit); luax_preloadmodule(L, "lovr.physics", l_lovrPhysicsInit); -#ifdef EMSCRIPTEN - luax_preloadmodule(L, "lovr.thread", luax_emptymodule); -#else luax_preloadmodule(L, "lovr.thread", l_lovrThreadInit); -#endif luax_preloadmodule(L, "lovr.timer", l_lovrTimerInit); luax_preloadmodule(L, "json", luaopen_cjson); luax_preloadmodule(L, "enet", luaopen_enet); diff --git a/src/event/event.h b/src/event/event.h index efa695b6..a79e41d9 100644 --- a/src/event/event.h +++ b/src/event/event.h @@ -1,7 +1,5 @@ #include "headset/headset.h" -#ifndef EMSCRIPTEN #include "thread/thread.h" -#endif #include "lib/vec/vec.h" #include @@ -52,12 +50,10 @@ typedef struct { bool value; } BoolEvent; -#ifndef EMSCRIPTEN typedef struct { Thread* thread; const char* error; } ThreadEvent; -#endif typedef struct { Controller* controller; @@ -73,9 +69,7 @@ typedef struct { typedef union { QuitEvent quit; BoolEvent boolean; -#ifndef EMSCRIPTEN ThreadEvent thread; -#endif ControllerEvent controller; CustomEvent custom; } EventData; diff --git a/src/lovr.c b/src/lovr.c index 573b5f8c..327fdebe 100644 --- a/src/lovr.c +++ b/src/lovr.c @@ -6,9 +6,7 @@ #include "headset/headset.h" #include "math/math.h" #include "physics/physics.h" -#ifndef EMSCRIPTEN #include "thread/thread.h" -#endif #include "timer/timer.h" #include "resources/boot.lua.h" #include "lib/glfw.h" diff --git a/src/luax.c b/src/luax.c index c3134b4e..dda6aa4f 100644 --- a/src/luax.c +++ b/src/luax.c @@ -21,11 +21,6 @@ int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f) { return 0; } -int luax_emptymodule(lua_State* L) { - lua_pushnil(L); - return 1; -} - void luax_registerloader(lua_State* L, lua_CFunction loader, int index) { lua_getglobal(L, "table"); lua_getfield(L, -1, "insert"); diff --git a/src/luax.h b/src/luax.h index 789d3420..e5356394 100644 --- a/src/luax.h +++ b/src/luax.h @@ -10,7 +10,6 @@ #define luax_checktype(L, i, T) ((T*) _luax_checktype(L, i, #T)) int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f); -int luax_emptymodule(lua_State* L); void luax_registerloader(lua_State* L, lua_CFunction loader, int index); void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions); void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions); diff --git a/src/util.h b/src/util.h index a1cfe9f3..7f8219c0 100644 --- a/src/util.h +++ b/src/util.h @@ -1,9 +1,5 @@ #include "lib/vec/vec.h" -#ifdef EMSCRIPTEN -#define _Thread_local -#else #include "lib/tinycthread/tinycthread.h" -#endif #include #include