mirror of https://github.com/bjornbytes/lovr.git
Re-enable threads for emscripten;
They don't appear to work very well but this simplifies code a lot.
This commit is contained in:
parent
017066d45e
commit
f872a5f094
|
@ -225,7 +225,7 @@ if(NOT EMSCRIPTEN)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# pthreads
|
# pthreads
|
||||||
if(NOT WIN32 AND NOT EMSCRIPTEN)
|
if(NOT WIN32)
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(LOVR_PTHREADS Threads::Threads)
|
set(LOVR_PTHREADS Threads::Threads)
|
||||||
|
@ -242,11 +242,13 @@ set(LOVR_SRC
|
||||||
src/api/lovr.c
|
src/api/lovr.c
|
||||||
src/api/math.c
|
src/api/math.c
|
||||||
src/api/physics.c
|
src/api/physics.c
|
||||||
|
src/api/thread.c
|
||||||
src/api/timer.c
|
src/api/timer.c
|
||||||
src/api/types/animator.c
|
src/api/types/animator.c
|
||||||
src/api/types/audioStream.c
|
src/api/types/audioStream.c
|
||||||
src/api/types/blob.c
|
src/api/types/blob.c
|
||||||
src/api/types/canvas.c
|
src/api/types/canvas.c
|
||||||
|
src/api/types/channel.c
|
||||||
src/api/types/collider.c
|
src/api/types/collider.c
|
||||||
src/api/types/controller.c
|
src/api/types/controller.c
|
||||||
src/api/types/font.c
|
src/api/types/font.c
|
||||||
|
@ -265,6 +267,7 @@ set(LOVR_SRC
|
||||||
src/api/types/source.c
|
src/api/types/source.c
|
||||||
src/api/types/texture.c
|
src/api/types/texture.c
|
||||||
src/api/types/textureData.c
|
src/api/types/textureData.c
|
||||||
|
src/api/types/thread.c
|
||||||
src/api/types/transform.c
|
src/api/types/transform.c
|
||||||
src/api/types/vertexData.c
|
src/api/types/vertexData.c
|
||||||
src/api/types/world.c
|
src/api/types/world.c
|
||||||
|
@ -297,6 +300,7 @@ set(LOVR_SRC
|
||||||
src/lib/stb/stb_image_write.c
|
src/lib/stb/stb_image_write.c
|
||||||
src/lib/stb/stb_truetype.c
|
src/lib/stb/stb_truetype.c
|
||||||
src/lib/stb/stb_vorbis.c
|
src/lib/stb/stb_vorbis.c
|
||||||
|
src/lib/tinycthread/tinycthread.c
|
||||||
src/lib/vec/vec.c
|
src/lib/vec/vec.c
|
||||||
src/lovr.c
|
src/lovr.c
|
||||||
src/luax.c
|
src/luax.c
|
||||||
|
@ -309,6 +313,8 @@ set(LOVR_SRC
|
||||||
src/math/vec3.c
|
src/math/vec3.c
|
||||||
src/physics/physics.c
|
src/physics/physics.c
|
||||||
src/resources/shaders.c
|
src/resources/shaders.c
|
||||||
|
src/thread/channel.c
|
||||||
|
src/thread/thread.c
|
||||||
src/timer/timer.c
|
src/timer/timer.c
|
||||||
src/util.c
|
src/util.c
|
||||||
${LOVR_AUDIO_SRC}
|
${LOVR_AUDIO_SRC}
|
||||||
|
@ -318,15 +324,7 @@ set(LOVR_SRC
|
||||||
if(EMSCRIPTEN)
|
if(EMSCRIPTEN)
|
||||||
set(LOVR_SRC ${LOVR_SRC} src/headset/webvr.c)
|
set(LOVR_SRC ${LOVR_SRC} src/headset/webvr.c)
|
||||||
else()
|
else()
|
||||||
set(LOVR_SRC ${LOVR_SRC}
|
set(LOVR_SRC ${LOVR_SRC} src/headset/openvr.c)
|
||||||
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
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# LÖVR
|
# LÖVR
|
||||||
|
|
|
@ -88,13 +88,11 @@ static int nextEvent(lua_State* L) {
|
||||||
lua_pushboolean(L, event.data.boolean.value);
|
lua_pushboolean(L, event.data.boolean.value);
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
#ifndef EMSCRIPTEN
|
|
||||||
case EVENT_THREAD_ERROR:
|
case EVENT_THREAD_ERROR:
|
||||||
luax_pushobject(L, event.data.thread.thread);
|
luax_pushobject(L, event.data.thread.thread);
|
||||||
lua_pushstring(L, event.data.thread.error);
|
lua_pushstring(L, event.data.thread.error);
|
||||||
free((void*) event.data.thread.error);
|
free((void*) event.data.thread.error);
|
||||||
return 3;
|
return 3;
|
||||||
#endif
|
|
||||||
|
|
||||||
case EVENT_CONTROLLER_ADDED:
|
case EVENT_CONTROLLER_ADDED:
|
||||||
case EVENT_CONTROLLER_REMOVED:
|
case EVENT_CONTROLLER_REMOVED:
|
||||||
|
|
|
@ -19,11 +19,7 @@ int l_lovrInit(lua_State* L) {
|
||||||
luax_preloadmodule(L, "lovr.headset", l_lovrHeadsetInit);
|
luax_preloadmodule(L, "lovr.headset", l_lovrHeadsetInit);
|
||||||
luax_preloadmodule(L, "lovr.math", l_lovrMathInit);
|
luax_preloadmodule(L, "lovr.math", l_lovrMathInit);
|
||||||
luax_preloadmodule(L, "lovr.physics", l_lovrPhysicsInit);
|
luax_preloadmodule(L, "lovr.physics", l_lovrPhysicsInit);
|
||||||
#ifdef EMSCRIPTEN
|
|
||||||
luax_preloadmodule(L, "lovr.thread", luax_emptymodule);
|
|
||||||
#else
|
|
||||||
luax_preloadmodule(L, "lovr.thread", l_lovrThreadInit);
|
luax_preloadmodule(L, "lovr.thread", l_lovrThreadInit);
|
||||||
#endif
|
|
||||||
luax_preloadmodule(L, "lovr.timer", l_lovrTimerInit);
|
luax_preloadmodule(L, "lovr.timer", l_lovrTimerInit);
|
||||||
luax_preloadmodule(L, "json", luaopen_cjson);
|
luax_preloadmodule(L, "json", luaopen_cjson);
|
||||||
luax_preloadmodule(L, "enet", luaopen_enet);
|
luax_preloadmodule(L, "enet", luaopen_enet);
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "headset/headset.h"
|
#include "headset/headset.h"
|
||||||
#ifndef EMSCRIPTEN
|
|
||||||
#include "thread/thread.h"
|
#include "thread/thread.h"
|
||||||
#endif
|
|
||||||
#include "lib/vec/vec.h"
|
#include "lib/vec/vec.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
@ -52,12 +50,10 @@ typedef struct {
|
||||||
bool value;
|
bool value;
|
||||||
} BoolEvent;
|
} BoolEvent;
|
||||||
|
|
||||||
#ifndef EMSCRIPTEN
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Thread* thread;
|
Thread* thread;
|
||||||
const char* error;
|
const char* error;
|
||||||
} ThreadEvent;
|
} ThreadEvent;
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Controller* controller;
|
Controller* controller;
|
||||||
|
@ -73,9 +69,7 @@ typedef struct {
|
||||||
typedef union {
|
typedef union {
|
||||||
QuitEvent quit;
|
QuitEvent quit;
|
||||||
BoolEvent boolean;
|
BoolEvent boolean;
|
||||||
#ifndef EMSCRIPTEN
|
|
||||||
ThreadEvent thread;
|
ThreadEvent thread;
|
||||||
#endif
|
|
||||||
ControllerEvent controller;
|
ControllerEvent controller;
|
||||||
CustomEvent custom;
|
CustomEvent custom;
|
||||||
} EventData;
|
} EventData;
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
#include "headset/headset.h"
|
#include "headset/headset.h"
|
||||||
#include "math/math.h"
|
#include "math/math.h"
|
||||||
#include "physics/physics.h"
|
#include "physics/physics.h"
|
||||||
#ifndef EMSCRIPTEN
|
|
||||||
#include "thread/thread.h"
|
#include "thread/thread.h"
|
||||||
#endif
|
|
||||||
#include "timer/timer.h"
|
#include "timer/timer.h"
|
||||||
#include "resources/boot.lua.h"
|
#include "resources/boot.lua.h"
|
||||||
#include "lib/glfw.h"
|
#include "lib/glfw.h"
|
||||||
|
|
|
@ -21,11 +21,6 @@ int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int luax_emptymodule(lua_State* L) {
|
|
||||||
lua_pushnil(L);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void luax_registerloader(lua_State* L, lua_CFunction loader, int index) {
|
void luax_registerloader(lua_State* L, lua_CFunction loader, int index) {
|
||||||
lua_getglobal(L, "table");
|
lua_getglobal(L, "table");
|
||||||
lua_getfield(L, -1, "insert");
|
lua_getfield(L, -1, "insert");
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#define luax_checktype(L, i, T) ((T*) _luax_checktype(L, i, #T))
|
#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_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_registerloader(lua_State* L, lua_CFunction loader, int index);
|
||||||
void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions);
|
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);
|
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions);
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
#include "lib/vec/vec.h"
|
#include "lib/vec/vec.h"
|
||||||
#ifdef EMSCRIPTEN
|
|
||||||
#define _Thread_local
|
|
||||||
#else
|
|
||||||
#include "lib/tinycthread/tinycthread.h"
|
#include "lib/tinycthread/tinycthread.h"
|
||||||
#endif
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue