diff --git a/CMakeLists.txt b/CMakeLists.txt index 48d43a84..d6fde749 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -337,17 +337,17 @@ target_link_libraries(lovr ) if(LOVR_ENABLE_AUDIO) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_AUDIO) target_sources(lovr PRIVATE src/modules/audio/audio.c src/api/l_audio.c src/api/l_audio_source.c src/api/l_audio_microphone.c ) +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_AUDIO) endif() if(LOVR_ENABLE_DATA) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_DATA) target_sources(lovr PRIVATE src/modules/data/audioStream.c src/modules/data/blob.c @@ -369,27 +369,30 @@ if(LOVR_ENABLE_DATA) src/lib/stb/stb_vorbis.c src/lib/jsmn/jsmn.c ) +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_DATA) endif() if(LOVR_ENABLE_EVENT) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_EVENT) target_sources(lovr PRIVATE src/modules/event/event.c src/api/l_event.c ) +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_EVENT) endif() if(LOVR_ENABLE_FILESYSTEM) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_FILESYSTEM) target_sources(lovr PRIVATE src/modules/filesystem/filesystem.c src/modules/filesystem/file.c src/api/l_filesystem.c ) +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_FILESYSTEM) endif() if(LOVR_ENABLE_GRAPHICS) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_GRAPHICS) target_sources(lovr PRIVATE src/modules/graphics/font.c src/modules/graphics/graphics.c @@ -409,9 +412,10 @@ if(LOVR_ENABLE_GRAPHICS) src/lib/glad/glad.c ) endif() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_GRAPHICS) +endif() if(LOVR_ENABLE_HEADSET) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_HEADSET) target_sources(lovr PRIVATE src/api/l_headset.c src/modules/headset/headset.c @@ -445,10 +449,11 @@ if(LOVR_ENABLE_HEADSET) target_compile_definitions(lovr PRIVATE LOVR_USE_DESKTOP_HEADSET) target_sources(lovr PRIVATE src/modules/headset/headset_desktop.c) endif() +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_HEADSET) endif() if(LOVR_ENABLE_MATH) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_MATH) target_sources(lovr PRIVATE src/modules/math/math.c src/modules/math/curve.c @@ -460,10 +465,11 @@ if(LOVR_ENABLE_MATH) src/api/l_math_vectors.c src/lib/noise1234/noise1234.c ) +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_MATH) endif() if(LOVR_ENABLE_PHYSICS) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_PHYSICS) target_sources(lovr PRIVATE src/modules/physics/physics.c src/api/l_physics.c @@ -472,10 +478,11 @@ if(LOVR_ENABLE_PHYSICS) src/api/l_physics_shapes.c src/api/l_physics_world.c ) +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_PHYSICS) endif() if(LOVR_ENABLE_THREAD) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_THREAD) target_sources(lovr PRIVATE src/modules/thread/channel.c src/modules/thread/thread.c @@ -484,11 +491,14 @@ if(LOVR_ENABLE_THREAD) src/api/l_thread_thread.c src/lib/tinycthread/tinycthread.c ) +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_THREAD) endif() if(LOVR_ENABLE_TIMER) - target_compile_definitions(lovr PRIVATE LOVR_ENABLE_TIMER) target_sources(lovr PRIVATE src/modules/timer/timer.c src/api/l_timer.c) +else() + target_compile_definitions(lovr PRIVATE LOVR_DISABLE_TIMER) endif() # Resources diff --git a/Tuprules.tup b/Tuprules.tup index 43b81479..773d1714 100644 --- a/Tuprules.tup +++ b/Tuprules.tup @@ -59,16 +59,16 @@ EXTRAS_web = bin/lovr.js bin/lovr.wasm EXTRAS_@(THREAD)_web += bin/lovr.worker.js ## Modules -CFLAGS_@(AUDIO) += -DLOVR_ENABLE_AUDIO -CFLAGS_@(DATA) += -DLOVR_ENABLE_DATA -CFLAGS_@(EVENT) += -DLOVR_ENABLE_EVENT -CFLAGS_@(FILESYSTEM) += -DLOVR_ENABLE_FILESYSTEM -CFLAGS_@(GRAPHICS) += -DLOVR_ENABLE_GRAPHICS -CFLAGS_@(HEADSET) += -DLOVR_ENABLE_HEADSET -CFLAGS_@(MATH) += -DLOVR_ENABLE_MATH -CFLAGS_@(PHYSICS) += -DLOVR_ENABLE_PHYSICS -CFLAGS_@(THREAD) += -DLOVR_ENABLE_THREAD -CFLAGS_@(TIMER) += -DLOVR_ENABLE_TIMER +DISABLE_@(AUDIO) += -DLOVR_DISABLE_AUDIO +DISABLE_@(DATA) += -DLOVR_DISABLE_DATA +DISABLE_@(EVENT) += -DLOVR_DISABLE_EVENT +DISABLE_@(FILESYSTEM) += -DLOVR_DISABLE_FILESYSTEM +DISABLE_@(GRAPHICS) += -DLOVR_DISABLE_GRAPHICS +DISABLE_@(HEADSET) += -DLOVR_DISABLE_HEADSET +DISABLE_@(MATH) += -DLOVR_DISABLE_MATH +DISABLE_@(PHYSICS) += -DLOVR_DISABLE_PHYSICS +DISABLE_@(THREAD) += -DLOVR_DISABLE_THREAD +DISABLE_@(TIMER) += -DLOVR_DISABLE_TIMER ## Headset backends CFLAGS_@(SIMULATOR) += -DLOVR_USE_DESKTOP_HEADSET @@ -271,13 +271,13 @@ LIBS += $(LIBS_y_web) SUFFIX = .html endif -CFLAGS += $(FLAGS) $(FLAGS_y) +CFLAGS += $(FLAGS) $(FLAGS_y) $(DISABLE_n) $(CFLAGS_y) LDFLAGS += $(FLAGS) $(FLAGS_y) CFLAGS += @(EXTRA_CFLAGS) LDFLAGS += @(EXTRA_LDFLAGS) ## Macros -!cc = |> ^o CC %b^ $(CC) $(CFLAGS_y) $(CFLAGS) -o %o -c %f |> +!cc = |> ^o CC %b^ $(CC) $(CFLAGS) -o %o -c %f |> !ld = |> ^ LD %o^ $(CC) -o %o %f $(LDFLAGS_y) $(LDFLAGS) |> !xd = |> ^ XD %f^ xxd -i %f > %o |> !cp = |> ^ CP %b^ cp %f %o |> diff --git a/src/api/api.h b/src/api/api.h index ca0e3c3d..11cb6d02 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -156,22 +156,22 @@ void luax_readcolor(lua_State* L, int index, struct Color* color); // Module helpers -#ifdef LOVR_ENABLE_DATA +#ifndef LOVR_DISABLE_DATA struct Blob; struct Blob* luax_readblob(lua_State* L, int index, const char* debug); #endif -#ifdef LOVR_ENABLE_EVENT +#ifndef LOVR_DISABLE_EVENT struct Variant; void luax_checkvariant(lua_State* L, int index, struct Variant* variant); int luax_pushvariant(lua_State* L, struct Variant* variant); #endif -#ifdef LOVR_ENABLE_FILESYSTEM +#ifndef LOVR_DISABLE_FILESYSTEM void* luax_readfile(const char* filename, size_t* bytesRead); #endif -#ifdef LOVR_ENABLE_GRAPHICS +#ifndef LOVR_DISABLE_GRAPHICS struct Attachment; struct Texture; struct Uniform; @@ -180,7 +180,7 @@ int luax_optmipmap(lua_State* L, int index, struct Texture* texture); void luax_readattachments(lua_State* L, int index, struct Attachment* attachments, int* count); #endif -#ifdef LOVR_ENABLE_MATH +#ifndef LOVR_DISABLE_MATH #include "math/pool.h" // TODO float* luax_tovector(lua_State* L, int index, VectorType* type); float* luax_checkvector(lua_State* L, int index, VectorType type, const char* expected); @@ -192,7 +192,7 @@ int luax_readmat4(lua_State* L, int index, float* m, int scaleComponents); uint64_t luax_checkrandomseed(lua_State* L, int index); #endif -#ifdef LOVR_ENABLE_PHYSICS +#ifndef LOVR_DISABLE_PHYSICS struct Joint; struct Shape; void luax_pushjoint(lua_State* L, struct Joint* joint); diff --git a/src/api/l_event.c b/src/api/l_event.c index 39df57a6..091fec0c 100644 --- a/src/api/l_event.c +++ b/src/api/l_event.c @@ -15,7 +15,7 @@ StringEntry lovrEventType[] = { [EVENT_KEYPRESSED] = ENTRY("keypressed"), [EVENT_KEYRELEASED] = ENTRY("keyreleased"), [EVENT_TEXTINPUT] = ENTRY("textinput"), -#ifdef LOVR_ENABLE_THREAD +#ifndef LOVR_DISABLE_THREAD [EVENT_THREAD_ERROR] = ENTRY("threaderror"), #endif { 0 } @@ -220,7 +220,7 @@ static int nextEvent(lua_State* L) { lua_pushinteger(L, event.data.text.codepoint); return 3; -#ifdef LOVR_ENABLE_THREAD +#ifndef LOVR_DISABLE_THREAD case EVENT_THREAD_ERROR: luax_pushtype(L, Thread, event.data.thread.thread); lua_pushstring(L, event.data.thread.error); diff --git a/src/api/l_lovr.c b/src/api/l_lovr.c index aaafee99..2144c64e 100644 --- a/src/api/l_lovr.c +++ b/src/api/l_lovr.c @@ -4,34 +4,34 @@ const luaL_Reg lovrModules[] = { { "lovr", luaopen_lovr }, -#ifdef LOVR_ENABLE_AUDIO +#ifndef LOVR_DISABLE_AUDIO { "lovr.audio", luaopen_lovr_audio }, #endif -#ifdef LOVR_ENABLE_DATA +#ifndef LOVR_DISABLE_DATA { "lovr.data", luaopen_lovr_data }, #endif -#ifdef LOVR_ENABLE_EVENT +#ifndef LOVR_DISABLE_EVENT { "lovr.event", luaopen_lovr_event }, #endif -#ifdef LOVR_ENABLE_FILESYSTEM +#ifndef LOVR_DISABLE_FILESYSTEM { "lovr.filesystem", luaopen_lovr_filesystem }, #endif -#ifdef LOVR_ENABLE_GRAPHICS +#ifndef LOVR_DISABLE_GRAPHICS { "lovr.graphics", luaopen_lovr_graphics }, #endif -#ifdef LOVR_ENABLE_HEADSET +#ifndef LOVR_DISABLE_HEADSET { "lovr.headset", luaopen_lovr_headset }, #endif -#ifdef LOVR_ENABLE_MATH +#ifndef LOVR_DISABLE_MATH { "lovr.math", luaopen_lovr_math }, #endif -#ifdef LOVR_ENABLE_PHYSICS +#ifndef LOVR_DISABLE_PHYSICS { "lovr.physics", luaopen_lovr_physics }, #endif -#ifdef LOVR_ENABLE_THREAD +#ifndef LOVR_DISABLE_THREAD { "lovr.thread", luaopen_lovr_thread }, #endif -#ifdef LOVR_ENABLE_TIMER +#ifndef LOVR_DISABLE_TIMER { "lovr.timer", luaopen_lovr_timer }, #endif { NULL, NULL } diff --git a/src/core/ref.h b/src/core/ref.h index cd0c4477..10e56de5 100644 --- a/src/core/ref.h +++ b/src/core/ref.h @@ -7,7 +7,7 @@ #define __has_builtin(x) 0 #endif -#ifndef LOVR_ENABLE_THREAD +#ifdef LOVR_DISABLE_THREAD // Thread module is off, don't use atomics @@ -39,7 +39,7 @@ static inline uint32_t ref_dec(Ref* ref) { return __atomic_sub_fetch(ref, 1, __A // stdatomic.h doesn't work in c++ (except on Android, where it is fine) #if !defined(__ANDROID__) && defined(__cplusplus) -#error "The header core/ref.h cannot currently be included from C++ when threading is enabled with this compiler. Either remove your ref.h include from any C++ files, or rebuild LOVR with -DLOVR_ENABLE_THREAD=OFF" +#error "The header core/ref.h cannot currently be included from C++ when threading is enabled with this compiler. Either remove your ref.h include from any C++ files, or rebuild LOVR with -DLOVR_DISABLE_THREAD=ON" #endif #include diff --git a/src/modules/event/event.c b/src/modules/event/event.c index 8f678d70..83705a0e 100644 --- a/src/modules/event/event.c +++ b/src/modules/event/event.c @@ -53,7 +53,7 @@ void lovrEventDestroy() { for (size_t i = state.head; i < state.events.length; i++) { Event* event = &state.events.data[i]; switch (event->type) { -#if LOVR_ENABLE_THREAD +#ifndef LOVR_DISABLE_THREAD case EVENT_THREAD_ERROR: lovrRelease(Thread, event->data.thread.thread); break; #endif case EVENT_CUSTOM: @@ -75,7 +75,7 @@ void lovrEventPump() { } void lovrEventPush(Event event) { -#ifdef LOVR_ENABLE_THREAD +#ifndef LOVR_DISABLE_THREAD if (event.type == EVENT_THREAD_ERROR) { lovrRetain(event.data.thread.thread); } diff --git a/src/modules/event/event.h b/src/modules/event/event.h index 2e5b9e2d..16a42a23 100644 --- a/src/modules/event/event.h +++ b/src/modules/event/event.h @@ -16,7 +16,7 @@ typedef enum { EVENT_KEYRELEASED, EVENT_TEXTINPUT, EVENT_CUSTOM, -#ifdef LOVR_ENABLE_THREAD +#ifndef LOVR_DISABLE_THREAD EVENT_THREAD_ERROR, #endif } EventType;