mirror of https://github.com/bjornbytes/lovr.git
Disable threads in WebVR;
Browser/emscripten support is currently unstable.
This commit is contained in:
parent
2f6a25a1ff
commit
012ba07063
|
@ -161,7 +161,7 @@ elseif(WIN32)
|
|||
else()
|
||||
pkg_search_module(ODE REQUIRED ode)
|
||||
include_directories(${ODE_INCLUDE_DIRS})
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++ -lpthread")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
|
||||
if(APPLE)
|
||||
set(LOVR_ODE ode ccd)
|
||||
else()
|
||||
|
@ -216,6 +216,13 @@ if(NOT EMSCRIPTEN)
|
|||
set(LOVR_OPENVR openvr_api)
|
||||
endif()
|
||||
|
||||
# pthreads
|
||||
if(NOT WIN32 AND NOT EMSCRIPTEN)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
set(LOVR_PTHREADS Threads::Threads)
|
||||
endif()
|
||||
|
||||
# LÖVR
|
||||
set(LOVR_SRC
|
||||
src/api/audio.c
|
||||
|
@ -227,13 +234,11 @@ 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
|
||||
|
@ -249,7 +254,6 @@ 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
|
||||
|
@ -285,8 +289,6 @@ set(LOVR_SRC
|
|||
src/lib/stb/stb_image.c
|
||||
src/lib/stb/stb_image_write.c
|
||||
src/lib/stb/stb_vorbis.c
|
||||
src/lib/tinycthread/tinycthread.c
|
||||
src/lib/tinycthread/tinycthread.h
|
||||
src/lib/vec/vec.c
|
||||
src/lovr.c
|
||||
src/luax.c
|
||||
|
@ -299,8 +301,6 @@ 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
|
||||
)
|
||||
|
@ -308,7 +308,15 @@ set(LOVR_SRC
|
|||
if(EMSCRIPTEN)
|
||||
set(LOVR_SRC ${LOVR_SRC} src/headset/webvr.c)
|
||||
else()
|
||||
set(LOVR_SRC ${LOVR_SRC} src/headset/openvr.c)
|
||||
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
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
|
@ -333,6 +341,7 @@ target_link_libraries(lovr
|
|||
${LOVR_OPENGL}
|
||||
${LOVR_OPENVR}
|
||||
${LOVR_PHYSFS}
|
||||
${LOVR_PTHREADS}
|
||||
|
||||
${LOVR_EMSCRIPTEN_FLAGS}
|
||||
)
|
||||
|
|
|
@ -31,11 +31,13 @@ static int nextEvent(lua_State* L) {
|
|||
lua_pushboolean(L, event.data.mount.mounted);
|
||||
return 2;
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
case EVENT_THREAD_ERROR:
|
||||
luax_pushtype(L, Thread, event.data.threaderror.thread);
|
||||
lua_pushstring(L, event.data.threaderror.error);
|
||||
free((void*) event.data.threaderror.error);
|
||||
return 3;
|
||||
#endif
|
||||
|
||||
case EVENT_CONTROLLER_ADDED:
|
||||
luax_pushtype(L, Controller, event.data.controlleradded.controller);
|
||||
|
@ -120,10 +122,12 @@ int l_lovrEventPush(lua_State* L) {
|
|||
data.mount.mounted = lua_toboolean(L, 2);
|
||||
break;
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
case EVENT_THREAD_ERROR:
|
||||
data.threaderror.thread = luax_checktype(L, 2, Thread);
|
||||
data.threaderror.error = luaL_checkstring(L, 3);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case EVENT_CONTROLLER_ADDED:
|
||||
data.controlleradded.controller = luax_checktype(L, 2, Controller);
|
||||
|
|
|
@ -19,7 +19,11 @@ 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_stubnil);
|
||||
#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);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "api.h"
|
||||
#include "thread/thread.h"
|
||||
#include "event/event.h"
|
||||
#include "thread/thread.h"
|
||||
|
||||
static int threadRunner(void* data) {
|
||||
Thread* thread = (Thread*) data;
|
||||
|
|
|
@ -8,7 +8,6 @@ void lovrEventInit() {
|
|||
if (state.initialized) return;
|
||||
vec_init(&state.pumps);
|
||||
vec_init(&state.events);
|
||||
mtx_init(&state.lock, mtx_plain);
|
||||
lovrEventAddPump(glfwPollEvents);
|
||||
atexit(lovrEventDestroy);
|
||||
state.initialized = true;
|
||||
|
@ -18,20 +17,15 @@ void lovrEventDestroy() {
|
|||
if (!state.initialized) return;
|
||||
vec_deinit(&state.pumps);
|
||||
vec_deinit(&state.events);
|
||||
mtx_destroy(&state.lock);
|
||||
memset(&state, 0, sizeof(EventState));
|
||||
}
|
||||
|
||||
void lovrEventAddPump(EventPump pump) {
|
||||
mtx_lock(&state.lock);
|
||||
vec_push(&state.pumps, pump);
|
||||
mtx_unlock(&state.lock);
|
||||
}
|
||||
|
||||
void lovrEventRemovePump(EventPump pump) {
|
||||
mtx_lock(&state.lock);
|
||||
vec_remove(&state.pumps, pump);
|
||||
mtx_unlock(&state.lock);
|
||||
}
|
||||
|
||||
void lovrEventPump() {
|
||||
|
@ -42,25 +36,18 @@ void lovrEventPump() {
|
|||
}
|
||||
|
||||
void lovrEventPush(Event event) {
|
||||
mtx_lock(&state.lock);
|
||||
vec_insert(&state.events, 0, event);
|
||||
mtx_unlock(&state.lock);
|
||||
}
|
||||
|
||||
bool lovrEventPoll(Event* event) {
|
||||
mtx_lock(&state.lock);
|
||||
if (state.events.length == 0) {
|
||||
mtx_unlock(&state.lock);
|
||||
return false;
|
||||
}
|
||||
|
||||
*event = vec_pop(&state.events);
|
||||
mtx_unlock(&state.lock);
|
||||
return true;
|
||||
}
|
||||
|
||||
void lovrEventClear() {
|
||||
mtx_lock(&state.lock);
|
||||
vec_clear(&state.events);
|
||||
mtx_unlock(&state.lock);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "headset/headset.h"
|
||||
#ifndef EMSCRIPTEN
|
||||
#include "thread/thread.h"
|
||||
#include "lib/tinycthread/tinycthread.h"
|
||||
#endif
|
||||
#include "lib/vec/vec.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -30,10 +31,12 @@ typedef struct {
|
|||
bool mounted;
|
||||
} MountEvent;
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
typedef struct {
|
||||
Thread* thread;
|
||||
const char* error;
|
||||
} ThreadErrorEvent;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
Controller* controller;
|
||||
|
@ -57,7 +60,9 @@ typedef union {
|
|||
QuitEvent quit;
|
||||
FocusEvent focus;
|
||||
MountEvent mount;
|
||||
#ifndef EMSCRIPTEN
|
||||
ThreadErrorEvent threaderror;
|
||||
#endif
|
||||
ControllerAddedEvent controlleradded;
|
||||
ControllerRemovedEvent controllerremoved;
|
||||
ControllerPressedEvent controllerpressed;
|
||||
|
@ -78,7 +83,6 @@ typedef struct {
|
|||
bool initialized;
|
||||
vec_pump_t pumps;
|
||||
vec_event_t events;
|
||||
mtx_t lock;
|
||||
} EventState;
|
||||
|
||||
void lovrEventInit();
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#include "graphics/graphics.h"
|
||||
#include "math/math.h"
|
||||
#include "physics/physics.h"
|
||||
#ifndef EMSCRIPTEN
|
||||
#include "thread/thread.h"
|
||||
#endif
|
||||
#include "timer/timer.h"
|
||||
|
||||
void lovrDestroy() {
|
||||
|
@ -15,7 +18,9 @@ void lovrDestroy() {
|
|||
lovrHeadsetDestroy();
|
||||
lovrMathDestroy();
|
||||
lovrPhysicsDestroy();
|
||||
#ifndef EMSCRIPTEN
|
||||
lovrThreadDeinit();
|
||||
#endif
|
||||
lovrTimerDestroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int luax_stubnil(lua_State* L) {
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions) {
|
||||
|
||||
// Push metatable
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
else if (!luax_getobject(L, x)) { luax_newobject(L, T, x); }
|
||||
|
||||
int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f);
|
||||
int luax_stubnil(lua_State* L);
|
||||
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);
|
||||
int luax_releasetype(lua_State* L);
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#include "lib/vec/vec.h"
|
||||
#ifdef EMSCRIPTEN
|
||||
#define _Thread_local
|
||||
#else
|
||||
#include "lib/tinycthread/tinycthread.h"
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
|
Loading…
Reference in New Issue