From 4a47afca3891b2ce3b565f447d6b2037d55565e7 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 17 May 2019 17:11:22 -0700 Subject: [PATCH] Organize api folder; --- CMakeLists.txt | 80 +++++++++---------- src/{ => api}/api.h | 39 ++++++++- src/api/data.h | 3 - src/api/event.h | 4 - src/api/graphics.h | 9 --- src/api/{types/animator.c => l_animator.c} | 0 src/api/{audio.c => l_audio.c} | 6 +- .../{types/audioStream.c => l_audioStream.c} | 0 src/api/{types/blob.c => l_blob.c} | 0 src/api/{types/canvas.c => l_canvas.c} | 11 --- src/api/{types/channel.c => l_channel.c} | 1 - src/api/{types/collider.c => l_collider.c} | 0 src/api/{types/curve.c => l_curve.c} | 1 - src/api/{data.c => l_data.c} | 2 +- src/api/{event.c => l_event.c} | 1 - src/api/{filesystem.c => l_filesystem.c} | 1 - src/api/{types/font.c => l_font.c} | 0 src/api/{graphics.c => l_graphics.c} | 47 +++++++++-- src/api/{headset.c => l_headset.c} | 1 - src/api/{types/joints.c => l_joints.c} | 0 src/api/{lovr.c => l_lovr.c} | 0 src/api/{types/mat4.c => l_mat4.c} | 2 +- src/api/{types/material.c => l_material.c} | 4 +- src/api/{math.c => l_math.c} | 11 ++- src/api/{types/mesh.c => l_mesh.c} | 3 +- .../{types/microphone.c => l_microphone.c} | 0 src/api/{types/model.c => l_model.c} | 1 - src/api/{types/modelData.c => l_modelData.c} | 0 src/api/{physics.c => l_physics.c} | 0 src/api/{types/pool.c => l_pool.c} | 5 +- src/api/{types/quat.c => l_quat.c} | 1 - .../randomGenerator.c => l_randomGenerator.c} | 1 - .../{types/rasterizer.c => l_rasterizer.c} | 0 src/api/{types/shader.c => l_shader.c} | 32 +------- .../{types/shaderBlock.c => l_shaderBlock.c} | 1 - src/api/{types/shapes.c => l_shapes.c} | 0 src/api/{types/soundData.c => l_soundData.c} | 0 src/api/{types/source.c => l_source.c} | 2 +- src/api/{types/texture.c => l_texture.c} | 1 - .../{types/textureData.c => l_textureData.c} | 0 src/api/{types/thread.c => l_thread.c} | 0 src/api/{thread.c => l_thread_module.c} | 0 src/api/{timer.c => l_timer.c} | 0 src/api/{types/vec3.c => l_vec3.c} | 1 - src/api/{types/world.c => l_world.c} | 0 src/api/math.h | 20 ----- src/event/event.h | 2 +- src/graphics/canvas.h | 2 +- src/graphics/shader.h | 2 +- src/main.c | 2 +- src/{api => resources}/math.lua | 0 src/{api => resources}/math.lua.h | 0 52 files changed, 147 insertions(+), 152 deletions(-) rename src/{ => api}/api.h (68%) delete mode 100644 src/api/data.h delete mode 100644 src/api/event.h delete mode 100644 src/api/graphics.h rename src/api/{types/animator.c => l_animator.c} (100%) rename src/api/{audio.c => l_audio.c} (98%) rename src/api/{types/audioStream.c => l_audioStream.c} (100%) rename src/api/{types/blob.c => l_blob.c} (100%) rename src/api/{types/canvas.c => l_canvas.c} (93%) rename src/api/{types/channel.c => l_channel.c} (98%) rename src/api/{types/collider.c => l_collider.c} (100%) rename src/api/{types/curve.c => l_curve.c} (99%) rename src/api/{data.c => l_data.c} (99%) rename src/api/{event.c => l_event.c} (99%) rename src/api/{filesystem.c => l_filesystem.c} (99%) rename src/api/{types/font.c => l_font.c} (100%) rename src/api/{graphics.c => l_graphics.c} (96%) rename src/api/{headset.c => l_headset.c} (99%) rename src/api/{types/joints.c => l_joints.c} (100%) rename src/api/{lovr.c => l_lovr.c} (100%) rename src/api/{types/mat4.c => l_mat4.c} (99%) rename src/api/{types/material.c => l_material.c} (98%) rename src/api/{math.c => l_math.c} (96%) rename src/api/{types/mesh.c => l_mesh.c} (99%) rename src/api/{types/microphone.c => l_microphone.c} (100%) rename src/api/{types/model.c => l_model.c} (98%) rename src/api/{types/modelData.c => l_modelData.c} (100%) rename src/api/{physics.c => l_physics.c} (100%) rename src/api/{types/pool.c => l_pool.c} (94%) rename src/api/{types/quat.c => l_quat.c} (99%) rename src/api/{types/randomGenerator.c => l_randomGenerator.c} (99%) rename src/api/{types/rasterizer.c => l_rasterizer.c} (100%) rename src/api/{types/shader.c => l_shader.c} (88%) rename src/api/{types/shaderBlock.c => l_shaderBlock.c} (99%) rename src/api/{types/shapes.c => l_shapes.c} (100%) rename src/api/{types/soundData.c => l_soundData.c} (100%) rename src/api/{types/source.c => l_source.c} (99%) rename src/api/{types/texture.c => l_texture.c} (99%) rename src/api/{types/textureData.c => l_textureData.c} (100%) rename src/api/{types/thread.c => l_thread.c} (100%) rename src/api/{thread.c => l_thread_module.c} (100%) rename src/api/{timer.c => l_timer.c} (100%) rename src/api/{types/vec3.c => l_vec3.c} (99%) rename src/api/{types/world.c => l_world.c} (100%) delete mode 100644 src/api/math.h rename src/{api => resources}/math.lua (100%) rename src/{api => resources}/math.lua.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4370b409..180c28fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -324,7 +324,7 @@ set(LOVR_SRC src/util.c src/luax.c src/types.c - src/api/lovr.c + src/api/l_lovr.c src/lib/utf.c src/lib/maf.c src/lib/map/map.c @@ -363,9 +363,9 @@ if(LOVR_ENABLE_AUDIO) src/audio/audio.c src/audio/source.c src/audio/microphone.c - src/api/audio.c - src/api/types/source.c - src/api/types/microphone.c + src/api/l_audio.c + src/api/l_source.c + src/api/l_microphone.c ) endif() @@ -380,13 +380,13 @@ if(LOVR_ENABLE_DATA) src/data/rasterizer.c src/data/soundData.c src/data/textureData.c - src/api/data.c - src/api/types/audioStream.c - src/api/types/blob.c - src/api/types/modelData.c - src/api/types/rasterizer.c - src/api/types/soundData.c - src/api/types/textureData.c + src/api/l_data.c + src/api/l_audioStream.c + src/api/l_blob.c + src/api/l_modelData.c + src/api/l_rasterizer.c + src/api/l_soundData.c + src/api/l_textureData.c src/lib/stb/stb_image.c src/lib/stb/stb_image_write.c src/lib/stb/stb_truetype.c @@ -399,7 +399,7 @@ if(LOVR_ENABLE_EVENT) add_definitions(-DLOVR_ENABLE_EVENT) target_sources(lovr PRIVATE src/event/event.c - src/api/event.c + src/api/l_event.c ) endif() @@ -408,7 +408,7 @@ if(LOVR_ENABLE_FILESYSTEM) target_sources(lovr PRIVATE src/filesystem/file.c src/filesystem/filesystem.c - src/api/filesystem.c + src/api/l_filesystem.c ) endif() @@ -426,16 +426,16 @@ if(LOVR_ENABLE_GRAPHICS) src/graphics/opengl.c src/graphics/shader.c src/graphics/texture.c - src/api/graphics.c - src/api/types/animator.c - src/api/types/canvas.c - src/api/types/font.c - src/api/types/material.c - src/api/types/mesh.c - src/api/types/model.c - src/api/types/shader.c - src/api/types/shaderBlock.c - src/api/types/texture.c + src/api/l_graphics.c + src/api/l_animator.c + src/api/l_canvas.c + src/api/l_font.c + src/api/l_material.c + src/api/l_mesh.c + src/api/l_model.c + src/api/l_shader.c + src/api/l_shaderBlock.c + src/api/l_texture.c src/resources/shaders.c src/lib/glad/glad.c ) @@ -444,7 +444,7 @@ endif() if(LOVR_ENABLE_HEADSET) add_definitions(-DLOVR_ENABLE_HEADSET) target_sources(lovr PRIVATE - src/api/headset.c + src/api/l_headset.c src/headset/headset.c ) @@ -481,13 +481,13 @@ if(LOVR_ENABLE_MATH) src/math/curve.c src/math/pool.c src/math/randomGenerator.c - src/api/math.c - src/api/types/curve.c - src/api/types/pool.c - src/api/types/randomGenerator.c - src/api/types/vec3.c - src/api/types/quat.c - src/api/types/mat4.c + src/api/l_math.c + src/api/l_curve.c + src/api/l_pool.c + src/api/l_randomGenerator.c + src/api/l_vec3.c + src/api/l_quat.c + src/api/l_mat4.c src/lib/noise1234/noise1234.c ) @@ -500,11 +500,11 @@ if(LOVR_ENABLE_PHYSICS) add_definitions(-DLOVR_ENABLE_PHYSICS) target_sources(lovr PRIVATE src/physics/physics.c - src/api/physics.c - src/api/types/collider.c - src/api/types/joints.c - src/api/types/shapes.c - src/api/types/world.c + src/api/l_physics.c + src/api/l_collider.c + src/api/l_joints.c + src/api/l_shapes.c + src/api/l_world.c ) endif() @@ -513,16 +513,16 @@ if(LOVR_ENABLE_THREAD) target_sources(lovr PRIVATE src/thread/channel.c src/thread/thread.c - src/api/thread.c - src/api/types/channel.c - src/api/types/thread.c + src/api/l_thread_module.c + src/api/l_channel.c + src/api/l_thread.c src/lib/tinycthread/tinycthread.c ) endif() if(LOVR_ENABLE_TIMER) add_definitions(-DLOVR_ENABLE_TIMER) - target_sources(lovr PRIVATE src/timer/timer.c src/api/timer.c) + target_sources(lovr PRIVATE src/timer/timer.c src/api/l_timer.c) endif() if(LOVR_ENABLE_ENET) diff --git a/src/api.h b/src/api/api.h similarity index 68% rename from src/api.h rename to src/api/api.h index f00ef993..ac6d08e6 100644 --- a/src/api.h +++ b/src/api/api.h @@ -1,7 +1,7 @@ #include "luax.h" #include "util.h" -// Module loaders +// Modules LOVR_EXPORT int luaopen_lovr(lua_State* L); LOVR_EXPORT int luaopen_lovr_audio(lua_State* L); LOVR_EXPORT int luaopen_lovr_data(lua_State* L); @@ -87,3 +87,40 @@ extern const char* UniformAccesses[]; extern const char* VerticalAligns[]; extern const char* Windings[]; extern const char* WrapModes[]; + +// Helpers + +#ifdef LOVR_ENABLE_DATA +struct Blob; +struct Blob* luax_readblob(lua_State* L, int index, const char* debug); +#endif + +#ifdef LOVR_ENABLE_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_GRAPHICS +struct Attachment; +struct Texture; +struct Uniform; +int luax_checkuniform(lua_State* L, int index, const struct Uniform* uniform, void* dest, const char* debug); +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 +#include +#include "math/pool.h" // TODO +#include "math/randomGenerator.h" // TODO +void luax_pushlightmathtype(lua_State* L, float* p, MathType type); +float* luax_tomathtype(lua_State* L, int index, MathType* type); +float* luax_checkmathtype(lua_State* L, int index, MathType type, const char* expected); +float* luax_newmathtype(lua_State* L, MathType type); +int luax_readvec3(lua_State* L, int index, float* v, const char* expected); +int luax_readscale(lua_State* L, int index, float* v, int components, const char* expected); +int luax_readquat(lua_State* L, int index, float* q, const char* expected); +int luax_readmat4(lua_State* L, int index, float* m, int scaleComponents); +Seed luax_checkrandomseed(lua_State* L, int index); +#endif diff --git a/src/api/data.h b/src/api/data.h deleted file mode 100644 index 6a0333c6..00000000 --- a/src/api/data.h +++ /dev/null @@ -1,3 +0,0 @@ -#include "data/blob.h" - -Blob* luax_readblob(lua_State* L, int index, const char* debug); diff --git a/src/api/event.h b/src/api/event.h deleted file mode 100644 index d177f2e7..00000000 --- a/src/api/event.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "event/event.h" - -void luax_checkvariant(lua_State* L, int index, Variant* variant); -int luax_pushvariant(lua_State* L, Variant* variant); diff --git a/src/api/graphics.h b/src/api/graphics.h deleted file mode 100644 index c3bf1139..00000000 --- a/src/api/graphics.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "graphics/canvas.h" -#include "graphics/shader.h" -#include "graphics/texture.h" - -int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* dest, const char* debug); -void luax_checkuniformtype(lua_State* L, int index, UniformType* baseType, int* components); -int luax_optmipmap(lua_State* L, int index, Texture* texture); -Texture* luax_checktexture(lua_State* L, int index); -void luax_readattachments(lua_State* L, int index, Attachment* attachments, int* count); diff --git a/src/api/types/animator.c b/src/api/l_animator.c similarity index 100% rename from src/api/types/animator.c rename to src/api/l_animator.c diff --git a/src/api/audio.c b/src/api/l_audio.c similarity index 98% rename from src/api/audio.c rename to src/api/l_audio.c index 01b612e1..8844692b 100644 --- a/src/api/audio.c +++ b/src/api/l_audio.c @@ -1,13 +1,15 @@ #include "api.h" -#include "api/data.h" -#include "api/math.h" #include "audio/audio.h" #include "audio/microphone.h" #include "audio/source.h" +#include "data/blob.h" #include "data/audioStream.h" #include "data/soundData.h" +#include "lib/maf.h" #include +struct Blob* luax_readblob(lua_State* L, int index, const char* debug); + const char* SourceTypes[] = { [SOURCE_STATIC] = "static", [SOURCE_STREAM] = "stream", diff --git a/src/api/types/audioStream.c b/src/api/l_audioStream.c similarity index 100% rename from src/api/types/audioStream.c rename to src/api/l_audioStream.c diff --git a/src/api/types/blob.c b/src/api/l_blob.c similarity index 100% rename from src/api/types/blob.c rename to src/api/l_blob.c diff --git a/src/api/types/canvas.c b/src/api/l_canvas.c similarity index 93% rename from src/api/types/canvas.c rename to src/api/l_canvas.c index 0a3ddb4f..8009a38d 100644 --- a/src/api/types/canvas.c +++ b/src/api/l_canvas.c @@ -1,18 +1,7 @@ #include "api.h" -#include "api/graphics.h" #include "graphics/canvas.h" #include "graphics/graphics.h" -Texture* luax_checktexture(lua_State* L, int index) { - Canvas* canvas = luax_totype(L, index, Canvas); - if (canvas) { - const Attachment* attachment = lovrCanvasGetAttachments(canvas, NULL); - return attachment->texture; - } else { - return luax_checktype(L, index, Texture); - } -} - static int luax_checkattachment(lua_State* L, int index, Attachment* attachment) { if (lua_istable(L, index)) { lua_rawgeti(L, index, 1); diff --git a/src/api/types/channel.c b/src/api/l_channel.c similarity index 98% rename from src/api/types/channel.c rename to src/api/l_channel.c index 6e7783de..80f42150 100644 --- a/src/api/types/channel.c +++ b/src/api/l_channel.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/event.h" #include "thread/channel.h" #include diff --git a/src/api/types/collider.c b/src/api/l_collider.c similarity index 100% rename from src/api/types/collider.c rename to src/api/l_collider.c diff --git a/src/api/types/curve.c b/src/api/l_curve.c similarity index 99% rename from src/api/types/curve.c rename to src/api/l_curve.c index bbf1c23e..8594d0c7 100644 --- a/src/api/types/curve.c +++ b/src/api/l_curve.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/math.h" #include "math/curve.h" static int l_lovrCurveEvaluate(lua_State* L) { diff --git a/src/api/data.c b/src/api/l_data.c similarity index 99% rename from src/api/data.c rename to src/api/l_data.c index 7d4e33f6..fc2092e8 100644 --- a/src/api/data.c +++ b/src/api/l_data.c @@ -1,6 +1,6 @@ #include "api.h" -#include "api/data.h" #include "data/audioStream.h" +#include "data/blob.h" #include "data/modelData.h" #include "data/rasterizer.h" #include "data/soundData.h" diff --git a/src/api/event.c b/src/api/l_event.c similarity index 99% rename from src/api/event.c rename to src/api/l_event.c index 03ad4204..741ba1c6 100644 --- a/src/api/event.c +++ b/src/api/l_event.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/event.h" #include "event/event.h" #include #include diff --git a/src/api/filesystem.c b/src/api/l_filesystem.c similarity index 99% rename from src/api/filesystem.c rename to src/api/l_filesystem.c index fc2b1c89..6d1c3927 100644 --- a/src/api/filesystem.c +++ b/src/api/l_filesystem.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/data.h" #include "filesystem/filesystem.h" #include "data/blob.h" #include diff --git a/src/api/types/font.c b/src/api/l_font.c similarity index 100% rename from src/api/types/font.c rename to src/api/l_font.c diff --git a/src/api/graphics.c b/src/api/l_graphics.c similarity index 96% rename from src/api/graphics.c rename to src/api/l_graphics.c index 643785bd..2851aace 100644 --- a/src/api/graphics.c +++ b/src/api/l_graphics.c @@ -1,7 +1,4 @@ #include "api.h" -#include "api/data.h" -#include "api/graphics.h" -#include "api/math.h" #include "graphics/graphics.h" #include "graphics/animator.h" #include "graphics/buffer.h" @@ -9,6 +6,7 @@ #include "graphics/material.h" #include "graphics/mesh.h" #include "graphics/model.h" +#include "data/blob.h" #include "data/modelData.h" #include "data/rasterizer.h" #include "data/textureData.h" @@ -861,7 +859,7 @@ static int l_lovrGraphicsSphere(lua_State* L) { } static int l_lovrGraphicsSkybox(lua_State* L) { - Texture* texture = luax_checktexture(L, 1); + Texture* texture = luax_checktype(L, 1, Texture); float angle = luax_optfloat(L, 2, 0.f); float ax = luax_optfloat(L, 3, 0.f); float ay = luax_optfloat(L, 4, 1.f); @@ -897,7 +895,15 @@ static int l_lovrGraphicsStencil(lua_State* L) { } static int l_lovrGraphicsFill(lua_State* L) { - Texture* texture = lua_isnoneornil(L, 1) ? NULL : luax_checktexture(L, 1); + Texture* texture = NULL; + if (!lua_isnoneornil(L, 1)) { + Canvas* canvas = luax_totype(L, 1, Canvas); + if (canvas) { + texture = lovrCanvasGetAttachments(canvas, NULL)->texture; + } else { + texture = luax_checktype(L, 1, Texture); + } + } float u = luax_optfloat(L, 2, 0.f); float v = luax_optfloat(L, 3, 0.f); float w = luax_optfloat(L, 4, 1.f - u); @@ -925,6 +931,35 @@ static int l_lovrGraphicsNewAnimator(lua_State* L) { return 1; } +static void luax_checkuniformtype(lua_State* L, int index, UniformType* baseType, int* components) { + size_t length; + lovrAssert(lua_type(L, index) == LUA_TSTRING, "Uniform types must be strings, got %s", lua_typename(L, index)); + const char* type = lua_tolstring(L, index, &length); + + if (!strcmp(type, "float")) { + *baseType = UNIFORM_FLOAT; + *components = 1; + } else if (!strcmp(type, "int")) { + *baseType = UNIFORM_INT; + *components = 1; + } else { + int n = type[length - 1] - '0'; + lovrAssert(n >= 2 && n <= 4, "Unknown uniform type '%s'", type); + if (type[0] == 'v' && type[1] == 'e' && type[2] == 'c' && length == 4) { + *baseType = UNIFORM_FLOAT; + *components = n; + } else if (type[0] == 'i' && type[1] == 'v' && type[2] == 'e' && type[3] == 'c' && length == 5) { + *baseType = UNIFORM_INT; + *components = n; + } else if (type[0] == 'm' && type[1] == 'a' && type[2] == 't' && length == 4) { + *baseType = UNIFORM_MATRIX; + *components = n; + } else { + lovrThrow("Unknown uniform type '%s'", type); + } + } +} + static int l_lovrGraphicsNewShaderBlock(lua_State* L) { vec_uniform_t uniforms; vec_init(&uniforms); @@ -1122,7 +1157,7 @@ static int l_lovrGraphicsNewMaterial(lua_State* L) { lovrRelease(TextureData, textureData); lovrRelease(Texture, texture); } else if (lua_isuserdata(L, index)) { - Texture* texture = luax_checktexture(L, index); + Texture* texture = luax_checktype(L, index, Texture); lovrMaterialSetTexture(material, TEXTURE_DIFFUSE, texture); index++; } diff --git a/src/api/headset.c b/src/api/l_headset.c similarity index 99% rename from src/api/headset.c rename to src/api/l_headset.c index 0bf9f3ad..42ae7465 100644 --- a/src/api/headset.c +++ b/src/api/l_headset.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/math.h" #include "headset/headset.h" #include "data/modelData.h" #include "graphics/model.h" diff --git a/src/api/types/joints.c b/src/api/l_joints.c similarity index 100% rename from src/api/types/joints.c rename to src/api/l_joints.c diff --git a/src/api/lovr.c b/src/api/l_lovr.c similarity index 100% rename from src/api/lovr.c rename to src/api/l_lovr.c diff --git a/src/api/types/mat4.c b/src/api/l_mat4.c similarity index 99% rename from src/api/types/mat4.c rename to src/api/l_mat4.c index e1959e41..675f86a4 100644 --- a/src/api/types/mat4.c +++ b/src/api/l_mat4.c @@ -1,6 +1,6 @@ #include "api.h" -#include "api/math.h" #include "math/math.h" +#include "math/pool.h" #include "lib/maf.h" int luax_readmat4(lua_State* L, int index, mat4 m, int scaleComponents) { diff --git a/src/api/types/material.c b/src/api/l_material.c similarity index 98% rename from src/api/types/material.c rename to src/api/l_material.c index cc59f446..11cab937 100644 --- a/src/api/types/material.c +++ b/src/api/l_material.c @@ -1,6 +1,6 @@ #include "api.h" -#include "api/graphics.h" #include "graphics/material.h" +#include "graphics/texture.h" static int l_lovrMaterialGetColor(lua_State* L) { Material* material = luax_checktype(L, 1, Material); @@ -59,7 +59,7 @@ static int l_lovrMaterialSetTexture(lua_State* L) { textureType = luaL_checkoption(L, index, NULL, MaterialTextures); index++; } - Texture* texture = lua_isnoneornil(L, index) ? NULL : luax_checktexture(L, index); + Texture* texture = lua_isnoneornil(L, index) ? NULL : luax_checktype(L, index, Texture); lovrMaterialSetTexture(material, textureType, texture); return 0; } diff --git a/src/api/math.c b/src/api/l_math.c similarity index 96% rename from src/api/math.c rename to src/api/l_math.c index c6b225f8..46ebe979 100644 --- a/src/api/math.c +++ b/src/api/l_math.c @@ -1,10 +1,17 @@ #include "api.h" -#include "api/math.h" -#include "api/math.lua.h" #include "math/math.h" #include "math/curve.h" #include "math/pool.h" #include "math/randomGenerator.h" +#include "resources/math.lua.h" + +int l_lovrRandomGeneratorRandom(lua_State* L); +int l_lovrRandomGeneratorRandomNormal(lua_State* L); +int l_lovrRandomGeneratorGetSeed(lua_State* L); +int l_lovrRandomGeneratorSetSeed(lua_State* L); +int l_lovrVec3Set(lua_State* L); +int l_lovrQuatSet(lua_State* L); +int l_lovrMat4Set(lua_State* L); static const char* lovrMathTypeNames[] = { [MATH_VEC3] = "vec3", diff --git a/src/api/types/mesh.c b/src/api/l_mesh.c similarity index 99% rename from src/api/types/mesh.c rename to src/api/l_mesh.c index 542c265a..88a9b055 100644 --- a/src/api/types/mesh.c +++ b/src/api/l_mesh.c @@ -1,10 +1,9 @@ #include "api.h" -#include "api/data.h" -#include "api/math.h" #include "graphics/buffer.h" #include "graphics/graphics.h" #include "graphics/material.h" #include "graphics/mesh.h" +#include "data/blob.h" #include static int l_lovrMeshAttachAttributes(lua_State* L) { diff --git a/src/api/types/microphone.c b/src/api/l_microphone.c similarity index 100% rename from src/api/types/microphone.c rename to src/api/l_microphone.c diff --git a/src/api/types/model.c b/src/api/l_model.c similarity index 98% rename from src/api/types/model.c rename to src/api/l_model.c index 8274b849..7c7f90be 100644 --- a/src/api/types/model.c +++ b/src/api/l_model.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/math.h" #include "graphics/animator.h" #include "graphics/material.h" #include "graphics/model.h" diff --git a/src/api/types/modelData.c b/src/api/l_modelData.c similarity index 100% rename from src/api/types/modelData.c rename to src/api/l_modelData.c diff --git a/src/api/physics.c b/src/api/l_physics.c similarity index 100% rename from src/api/physics.c rename to src/api/l_physics.c diff --git a/src/api/types/pool.c b/src/api/l_pool.c similarity index 94% rename from src/api/types/pool.c rename to src/api/l_pool.c index 13196928..a6022cf1 100644 --- a/src/api/types/pool.c +++ b/src/api/l_pool.c @@ -1,8 +1,11 @@ #include "api.h" -#include "api/math.h" #include "math/pool.h" #include "lib/maf.h" +int l_lovrVec3Set(lua_State* L); +int l_lovrQuatSet(lua_State* L); +int l_lovrMat4Set(lua_State* L); + static int l_lovrPoolVec3(lua_State* L) { Pool* pool = luax_checktype(L, 1, Pool); vec3 v = lovrPoolAllocate(pool, MATH_VEC3); diff --git a/src/api/types/quat.c b/src/api/l_quat.c similarity index 99% rename from src/api/types/quat.c rename to src/api/l_quat.c index 2b783fc4..90fa6c3c 100644 --- a/src/api/types/quat.c +++ b/src/api/l_quat.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/math.h" #include "math/math.h" int luax_readquat(lua_State* L, int index, quat q, const char* expected) { diff --git a/src/api/types/randomGenerator.c b/src/api/l_randomGenerator.c similarity index 99% rename from src/api/types/randomGenerator.c rename to src/api/l_randomGenerator.c index 79b333b3..e266383a 100644 --- a/src/api/types/randomGenerator.c +++ b/src/api/l_randomGenerator.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/math.h" #include "math/randomGenerator.h" #include diff --git a/src/api/types/rasterizer.c b/src/api/l_rasterizer.c similarity index 100% rename from src/api/types/rasterizer.c rename to src/api/l_rasterizer.c diff --git a/src/api/types/shader.c b/src/api/l_shader.c similarity index 88% rename from src/api/types/shader.c rename to src/api/l_shader.c index 0b1ba216..218bb2ee 100644 --- a/src/api/types/shader.c +++ b/src/api/l_shader.c @@ -1,8 +1,7 @@ #include "api.h" -#include "api/graphics.h" -#include "api/math.h" #include "graphics/buffer.h" #include "graphics/shader.h" +#include "lib/maf.h" struct TempData { void* data; @@ -183,35 +182,6 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des return 0; } -void luax_checkuniformtype(lua_State* L, int index, UniformType* baseType, int* components) { - size_t length; - lovrAssert(lua_type(L, index) == LUA_TSTRING, "Uniform types must be strings, got %s", lua_typename(L, index)); - const char* type = lua_tolstring(L, index, &length); - - if (!strcmp(type, "float")) { - *baseType = UNIFORM_FLOAT; - *components = 1; - } else if (!strcmp(type, "int")) { - *baseType = UNIFORM_INT; - *components = 1; - } else { - int n = type[length - 1] - '0'; - lovrAssert(n >= 2 && n <= 4, "Unknown uniform type '%s'", type); - if (type[0] == 'v' && type[1] == 'e' && type[2] == 'c' && length == 4) { - *baseType = UNIFORM_FLOAT; - *components = n; - } else if (type[0] == 'i' && type[1] == 'v' && type[2] == 'e' && type[3] == 'c' && length == 5) { - *baseType = UNIFORM_INT; - *components = n; - } else if (type[0] == 'm' && type[1] == 'a' && type[2] == 't' && length == 4) { - *baseType = UNIFORM_MATRIX; - *components = n; - } else { - lovrThrow("Unknown uniform type '%s'", type); - } - } -} - static int l_lovrShaderGetType(lua_State* L) { Shader* shader = luax_checktype(L, 1, Shader); lua_pushstring(L, ShaderTypes[lovrShaderGetType(shader)]); diff --git a/src/api/types/shaderBlock.c b/src/api/l_shaderBlock.c similarity index 99% rename from src/api/types/shaderBlock.c rename to src/api/l_shaderBlock.c index 3e974ecb..15df1c3a 100644 --- a/src/api/types/shaderBlock.c +++ b/src/api/l_shaderBlock.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/graphics.h" #include "graphics/buffer.h" #include "graphics/shader.h" diff --git a/src/api/types/shapes.c b/src/api/l_shapes.c similarity index 100% rename from src/api/types/shapes.c rename to src/api/l_shapes.c diff --git a/src/api/types/soundData.c b/src/api/l_soundData.c similarity index 100% rename from src/api/types/soundData.c rename to src/api/l_soundData.c diff --git a/src/api/types/source.c b/src/api/l_source.c similarity index 99% rename from src/api/types/source.c rename to src/api/l_source.c index a6a8ee44..3ee559e2 100644 --- a/src/api/types/source.c +++ b/src/api/l_source.c @@ -1,7 +1,7 @@ #include "api.h" -#include "api/math.h" #include "audio/audio.h" #include "audio/source.h" +#include "lib/maf.h" #include static int l_lovrSourceGetBitDepth(lua_State* L) { diff --git a/src/api/types/texture.c b/src/api/l_texture.c similarity index 99% rename from src/api/types/texture.c rename to src/api/l_texture.c index 9a69e48a..14fc0e2d 100644 --- a/src/api/types/texture.c +++ b/src/api/l_texture.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/graphics.h" #include "graphics/texture.h" int luax_optmipmap(lua_State* L, int index, Texture* texture) { diff --git a/src/api/types/textureData.c b/src/api/l_textureData.c similarity index 100% rename from src/api/types/textureData.c rename to src/api/l_textureData.c diff --git a/src/api/types/thread.c b/src/api/l_thread.c similarity index 100% rename from src/api/types/thread.c rename to src/api/l_thread.c diff --git a/src/api/thread.c b/src/api/l_thread_module.c similarity index 100% rename from src/api/thread.c rename to src/api/l_thread_module.c diff --git a/src/api/timer.c b/src/api/l_timer.c similarity index 100% rename from src/api/timer.c rename to src/api/l_timer.c diff --git a/src/api/types/vec3.c b/src/api/l_vec3.c similarity index 99% rename from src/api/types/vec3.c rename to src/api/l_vec3.c index b55d2249..2485064a 100644 --- a/src/api/types/vec3.c +++ b/src/api/l_vec3.c @@ -1,5 +1,4 @@ #include "api.h" -#include "api/math.h" #include "math/math.h" #include "lib/maf.h" diff --git a/src/api/types/world.c b/src/api/l_world.c similarity index 100% rename from src/api/types/world.c rename to src/api/l_world.c diff --git a/src/api/math.h b/src/api/math.h deleted file mode 100644 index af98f106..00000000 --- a/src/api/math.h +++ /dev/null @@ -1,20 +0,0 @@ -#include "lib/maf.h" -#include "math/pool.h" -#include "math/randomGenerator.h" - -void luax_pushlightmathtype(lua_State* L, float* p, MathType type); -float* luax_tomathtype(lua_State* L, int index, MathType* type); -float* luax_checkmathtype(lua_State* L, int index, MathType type, const char* expected); -float* luax_newmathtype(lua_State* L, MathType type); -int luax_readvec3(lua_State* L, int index, vec3 v, const char* expected); -int luax_readscale(lua_State* L, int index, vec3 v, int components, const char* expected); -int luax_readquat(lua_State* L, int index, quat q, const char* expected); -int luax_readmat4(lua_State* L, int index, mat4 m, int scaleComponents); -Seed luax_checkrandomseed(lua_State* L, int index); -int l_lovrRandomGeneratorRandom(lua_State* L); -int l_lovrRandomGeneratorRandomNormal(lua_State* L); -int l_lovrRandomGeneratorGetSeed(lua_State* L); -int l_lovrRandomGeneratorSetSeed(lua_State* L); -int l_lovrVec3Set(lua_State* L); -int l_lovrQuatSet(lua_State* L); -int l_lovrMat4Set(lua_State* L); diff --git a/src/event/event.h b/src/event/event.h index bf943e04..8737f4a3 100644 --- a/src/event/event.h +++ b/src/event/event.h @@ -30,7 +30,7 @@ typedef union { struct Ref* ref; } VariantValue; -typedef struct { +typedef struct Variant { VariantType type; VariantValue value; } Variant; diff --git a/src/graphics/canvas.h b/src/graphics/canvas.h index ac32ea27..6d745f61 100644 --- a/src/graphics/canvas.h +++ b/src/graphics/canvas.h @@ -8,7 +8,7 @@ struct Texture; struct TextureData; -typedef struct { +typedef struct Attachment { struct Texture* texture; int slice; int level; diff --git a/src/graphics/shader.h b/src/graphics/shader.h index efd6a6f6..d74b768d 100644 --- a/src/graphics/shader.h +++ b/src/graphics/shader.h @@ -67,7 +67,7 @@ typedef struct { UniformAccess access; } Image; -typedef struct { +typedef struct Uniform { char name[LOVR_MAX_UNIFORM_LENGTH]; UniformType type; int components; diff --git a/src/main.c b/src/main.c index 52336879..40cec606 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ #include "resources/boot.lua.h" #include "version.h" -#include "api.h" +#include "api/api.h" #include "luax.h" #include "platform.h" #include "util.h" diff --git a/src/api/math.lua b/src/resources/math.lua similarity index 100% rename from src/api/math.lua rename to src/resources/math.lua diff --git a/src/api/math.lua.h b/src/resources/math.lua.h similarity index 100% rename from src/api/math.lua.h rename to src/resources/math.lua.h