From 3bc2c00b790c8efde1100e4f1fbd973855264902 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 25 Dec 2020 12:50:26 -0700 Subject: [PATCH] api doesn't include util; --- src/api/api.c | 1 - src/api/api.h | 9 ++++++++- src/api/l_audio.c | 1 + src/api/l_audio_microphone.c | 1 + src/api/l_audio_source.c | 5 ++--- src/api/l_data_audioStream.c | 1 + src/api/l_data_blob.c | 1 + src/api/l_data_rasterizer.c | 1 + src/api/l_data_soundData.c | 1 + src/api/l_filesystem.c | 1 + src/api/l_graphics_font.c | 1 + src/api/l_math_randomGenerator.c | 1 + src/api/l_math_vectors.c | 1 + src/api/l_physics.c | 1 + src/api/l_physics_collider.c | 1 + src/api/l_physics_joints.c | 1 + src/api/l_physics_shapes.c | 1 + src/api/l_physics_world.c | 1 + src/api/l_thread.c | 1 + src/api/l_thread_channel.c | 1 + src/api/l_thread_thread.c | 1 + src/core/maf.h | 28 ++++++++++++++++------------ src/core/util.h | 2 -- 23 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/api/api.c b/src/api/api.c index 7215e9a1..a1a6e7de 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -4,7 +4,6 @@ #include "core/util.h" #include #include -#include typedef void voidFn(void); typedef void destructorFn(void*); diff --git a/src/api/api.h b/src/api/api.h index 685d4876..ca0e3c3d 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -3,10 +3,17 @@ #include #include #include -#include "core/util.h" #pragma once +struct Color; + +#ifdef _WIN32 +#define LOVR_EXPORT __declspec(dllexport) +#else +#define LOVR_EXPORT __attribute__((visibility("default"))) +#endif + // Modules LOVR_EXPORT int luaopen_lovr(lua_State* L); LOVR_EXPORT int luaopen_lovr_audio(lua_State* L); diff --git a/src/api/l_audio.c b/src/api/l_audio.c index 631a835c..9473775e 100644 --- a/src/api/l_audio.c +++ b/src/api/l_audio.c @@ -5,6 +5,7 @@ #include "data/soundData.h" #include "core/maf.h" #include "core/ref.h" +#include "core/util.h" #include StringEntry lovrSourceType[] = { diff --git a/src/api/l_audio_microphone.c b/src/api/l_audio_microphone.c index fcf12acc..f6af299f 100644 --- a/src/api/l_audio_microphone.c +++ b/src/api/l_audio_microphone.c @@ -2,6 +2,7 @@ #include "audio/audio.h" #include "data/soundData.h" #include "core/ref.h" +#include "core/util.h" #include static int l_lovrMicrophoneGetBitDepth(lua_State* L) { diff --git a/src/api/l_audio_source.c b/src/api/l_audio_source.c index 8d519bb4..65276f36 100644 --- a/src/api/l_audio_source.c +++ b/src/api/l_audio_source.c @@ -1,7 +1,7 @@ #include "api.h" #include "audio/audio.h" #include "core/maf.h" -#include +#include "core/util.h" static int l_lovrSourceGetBitDepth(lua_State* L) { Source* source = luax_checktype(L, 1, Source); @@ -227,8 +227,7 @@ static int l_lovrSourceSetPosition(lua_State* L) { static int l_lovrSourceSetRelative(lua_State* L) { Source* source = luax_checktype(L, 1, Source); - bool isRelative = lua_toboolean(L, 2); - lovrSourceSetRelative(source, isRelative); + lovrSourceSetRelative(source, lua_toboolean(L, 2)); return 0; } diff --git a/src/api/l_data_audioStream.c b/src/api/l_data_audioStream.c index 0dbbeb9e..a9a5d30d 100644 --- a/src/api/l_data_audioStream.c +++ b/src/api/l_data_audioStream.c @@ -2,6 +2,7 @@ #include "data/audioStream.h" #include "data/soundData.h" #include "core/ref.h" +#include "core/util.h" #include #include diff --git a/src/api/l_data_blob.c b/src/api/l_data_blob.c index eb0a7035..50078827 100644 --- a/src/api/l_data_blob.c +++ b/src/api/l_data_blob.c @@ -1,5 +1,6 @@ #include "api.h" #include "data/blob.h" +#include "core/util.h" static int l_lovrBlobGetName(lua_State* L) { Blob* blob = luax_checktype(L, 1, Blob); diff --git a/src/api/l_data_rasterizer.c b/src/api/l_data_rasterizer.c index ef8cf68a..2ec42a23 100644 --- a/src/api/l_data_rasterizer.c +++ b/src/api/l_data_rasterizer.c @@ -1,5 +1,6 @@ #include "api.h" #include "data/rasterizer.h" +#include "core/util.h" static int l_lovrRasterizerGetHeight(lua_State* L) { Rasterizer* rasterizer = luax_checktype(L, 1, Rasterizer); diff --git a/src/api/l_data_soundData.c b/src/api/l_data_soundData.c index 0e06d656..cf725079 100644 --- a/src/api/l_data_soundData.c +++ b/src/api/l_data_soundData.c @@ -1,5 +1,6 @@ #include "api.h" #include "data/soundData.h" +#include "core/util.h" static int l_lovrSoundDataGetBitDepth(lua_State* L) { SoundData* soundData = luax_checktype(L, 1, SoundData); diff --git a/src/api/l_filesystem.c b/src/api/l_filesystem.c index 68b26f40..7907dc60 100644 --- a/src/api/l_filesystem.c +++ b/src/api/l_filesystem.c @@ -4,6 +4,7 @@ #include "core/fs.h" #include "core/os.h" #include "core/ref.h" +#include "core/util.h" #include #include diff --git a/src/api/l_graphics_font.c b/src/api/l_graphics_font.c index 278f22b8..ae36eb81 100644 --- a/src/api/l_graphics_font.c +++ b/src/api/l_graphics_font.c @@ -1,6 +1,7 @@ #include "api.h" #include "graphics/font.h" #include "data/rasterizer.h" +#include "core/util.h" static int l_lovrFontGetWidth(lua_State* L) { Font* font = luax_checktype(L, 1, Font); diff --git a/src/api/l_math_randomGenerator.c b/src/api/l_math_randomGenerator.c index d3b8e249..26cbb282 100644 --- a/src/api/l_math_randomGenerator.c +++ b/src/api/l_math_randomGenerator.c @@ -1,5 +1,6 @@ #include "api.h" #include "math/randomGenerator.h" +#include "core/util.h" #include static double luax_checkrandomseedpart(lua_State* L, int index) { diff --git a/src/api/l_math_vectors.c b/src/api/l_math_vectors.c index f3458298..33043c61 100644 --- a/src/api/l_math_vectors.c +++ b/src/api/l_math_vectors.c @@ -1,6 +1,7 @@ #include "api.h" #include "math/math.h" #include "core/maf.h" +#include "core/util.h" static const uint32_t* swizzles[5] = { [2] = (uint32_t[]) { diff --git a/src/api/l_physics.c b/src/api/l_physics.c index 66b219e5..14c09d22 100644 --- a/src/api/l_physics.c +++ b/src/api/l_physics.c @@ -1,6 +1,7 @@ #include "api.h" #include "physics/physics.h" #include "core/ref.h" +#include "core/util.h" StringEntry lovrShapeType[] = { [SHAPE_SPHERE] = ENTRY("sphere"), diff --git a/src/api/l_physics_collider.c b/src/api/l_physics_collider.c index e8e459b2..87ad526f 100644 --- a/src/api/l_physics_collider.c +++ b/src/api/l_physics_collider.c @@ -1,5 +1,6 @@ #include "api.h" #include "physics/physics.h" +#include "core/util.h" #include static int l_lovrColliderDestroy(lua_State* L) { diff --git a/src/api/l_physics_joints.c b/src/api/l_physics_joints.c index 5bb3ec50..0e3d7efa 100644 --- a/src/api/l_physics_joints.c +++ b/src/api/l_physics_joints.c @@ -1,5 +1,6 @@ #include "api.h" #include "physics/physics.h" +#include "core/util.h" void luax_pushjoint(lua_State* L, Joint* joint) { switch (joint->type) { diff --git a/src/api/l_physics_shapes.c b/src/api/l_physics_shapes.c index 0f64fabd..977d2f87 100644 --- a/src/api/l_physics_shapes.c +++ b/src/api/l_physics_shapes.c @@ -1,5 +1,6 @@ #include "api.h" #include "physics/physics.h" +#include "core/util.h" void luax_pushshape(lua_State* L, Shape* shape) { switch (shape->type) { diff --git a/src/api/l_physics_world.c b/src/api/l_physics_world.c index 65647d07..0e7e2d17 100644 --- a/src/api/l_physics_world.c +++ b/src/api/l_physics_world.c @@ -1,6 +1,7 @@ #include "api.h" #include "physics/physics.h" #include "core/ref.h" +#include "core/util.h" #include static void collisionResolver(World* world, void* userdata) { diff --git a/src/api/l_thread.c b/src/api/l_thread.c index dec13a0b..bc7c2807 100644 --- a/src/api/l_thread.c +++ b/src/api/l_thread.c @@ -3,6 +3,7 @@ #include "thread/thread.h" #include "thread/channel.h" #include "core/ref.h" +#include "core/util.h" #include #include diff --git a/src/api/l_thread_channel.c b/src/api/l_thread_channel.c index 81ffa5f2..6962a29f 100644 --- a/src/api/l_thread_channel.c +++ b/src/api/l_thread_channel.c @@ -1,6 +1,7 @@ #include "api.h" #include "thread/channel.h" #include "event/event.h" +#include "core/util.h" #include static void luax_checktimeout(lua_State* L, int index, double* timeout) { diff --git a/src/api/l_thread_thread.c b/src/api/l_thread_thread.c index a7819baf..d2913c67 100644 --- a/src/api/l_thread_thread.c +++ b/src/api/l_thread_thread.c @@ -1,5 +1,6 @@ #include "api.h" #include "thread/thread.h" +#include "core/util.h" static int l_lovrThreadStart(lua_State* L) { Thread* thread = luax_checktype(L, 1, Thread); diff --git a/src/core/maf.h b/src/core/maf.h index bc64fe71..4aead8c1 100644 --- a/src/core/maf.h +++ b/src/core/maf.h @@ -94,10 +94,10 @@ MAF vec3 vec3_lerp(vec3 v, const vec3 u, float t) { } MAF vec3 vec3_min(vec3 v, const vec3 u) { - float x = MIN(v[0], u[0]); - float y = MIN(v[1], u[1]); - float z = MIN(v[2], u[2]); - float w = MIN(v[3], u[3]); + float x = v[0] < u[0] ? v[0] : u[0]; + float y = v[1] < u[1] ? v[1] : u[1]; + float z = v[2] < u[2] ? v[2] : u[2]; + float w = v[3] < u[3] ? v[3] : u[3]; v[0] = x; v[1] = y; v[2] = z; @@ -106,10 +106,10 @@ MAF vec3 vec3_min(vec3 v, const vec3 u) { } MAF vec3 vec3_max(vec3 v, const vec3 u) { - float x = MAX(v[0], u[0]); - float y = MAX(v[1], u[1]); - float z = MAX(v[2], u[2]); - float w = MAX(v[3], u[3]); + float x = v[0] > u[0] ? v[0] : u[0]; + float y = v[1] > u[1] ? v[1] : u[1]; + float z = v[2] > u[2] ? v[2] : u[2]; + float w = v[3] > u[3] ? v[3] : u[3]; v[0] = x; v[1] = y; v[2] = z; @@ -142,10 +142,14 @@ MAF quat quat_fromAngleAxis(quat q, float angle, float ax, float ay, float az) { } MAF quat quat_fromMat4(quat q, mat4 m) { - float x = sqrtf(MAX(0.f, 1.f + m[0] - m[5] - m[10])) / 2.f; - float y = sqrtf(MAX(0.f, 1.f - m[0] + m[5] - m[10])) / 2.f; - float z = sqrtf(MAX(0.f, 1.f - m[0] - m[5] + m[10])) / 2.f; - float w = sqrtf(MAX(0.f, 1.f + m[0] + m[5] + m[10])) / 2.f; + float a = 1.f + m[0] - m[5] - m[10]; + float b = 1.f - m[0] + m[5] - m[10]; + float c = 1.f - m[0] - m[5] + m[10]; + float d = 1.f + m[0] + m[5] + m[10]; + float x = sqrtf(a > 0.f ? a : 0.f) / 2.f; + float y = sqrtf(b > 0.f ? b : 0.f) / 2.f; + float z = sqrtf(c > 0.f ? c : 0.f) / 2.f; + float w = sqrtf(d > 0.f ? d : 0.f) / 2.f; x = (m[9] - m[6]) > 0.f ? -x : x; y = (m[2] - m[8]) > 0.f ? -y : y; z = (m[4] - m[1]) > 0.f ? -z : z; diff --git a/src/core/util.h b/src/core/util.h index afa9134d..00666b8e 100644 --- a/src/core/util.h +++ b/src/core/util.h @@ -10,13 +10,11 @@ #define LOVR_VERSION_ALIAS "Maximum Moss" #ifdef _WIN32 -#define LOVR_EXPORT __declspec(dllexport) #define LOVR_NORETURN __declspec(noreturn) #define LOVR_THREAD_LOCAL __declspec(thread) #define LOVR_ALIGN(n) __declspec(align(n)) #define LOVR_RESTRICT __restrict #else -#define LOVR_EXPORT __attribute__((visibility("default"))) #define LOVR_NORETURN __attribute__((noreturn)) #define LOVR_THREAD_LOCAL __thread #define LOVR_ALIGN(n) __attribute__((aligned(n)))