From 90cacd03ca6c69327b1397e236088b0aa30b05f8 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 11 Jan 2019 22:37:54 -0800 Subject: [PATCH] Handle numbers more consistently in Lua API; I still don't know if I should cast or not, but at least now things will be consistently right or wrong. --- src/api/audio.c | 4 +-- src/api/data.c | 8 +++--- src/api/graphics.c | 46 +++++++++++++++------------------ src/api/headset.c | 4 +-- src/api/math.c | 8 +++--- src/api/physics.c | 2 +- src/api/timer.c | 2 +- src/api/types/collider.c | 4 +-- src/api/types/controller.c | 4 +-- src/api/types/curve.c | 4 +-- src/api/types/font.c | 4 +-- src/api/types/mat4.c | 16 ++++++------ src/api/types/quat.c | 8 +++--- src/api/types/randomGenerator.c | 4 +-- src/api/types/shader.c | 8 +++--- src/api/types/texture.c | 2 +- src/api/types/vec3.c | 10 +++---- src/api/types/vertexData.c | 2 +- src/api/types/world.c | 38 +++++++++++++-------------- src/data/rasterizer.c | 2 +- src/data/rasterizer.h | 4 +-- src/luax.c | 4 +-- 22 files changed, 92 insertions(+), 96 deletions(-) diff --git a/src/api/audio.c b/src/api/audio.c index a99a0117..ef441ae5 100644 --- a/src/api/audio.c +++ b/src/api/audio.c @@ -146,8 +146,8 @@ static int l_lovrAudioRewind(lua_State* L) { } static int l_lovrAudioSetDopplerEffect(lua_State* L) { - float factor = luaL_optnumber(L, 1, 1.); - float speedOfSound = luaL_optnumber(L, 2, 343.29); + float factor = luaL_optnumber(L, 1, 1.f); + float speedOfSound = luaL_optnumber(L, 2, 343.29f); lovrAudioSetDopplerEffect(factor, speedOfSound); return 0; } diff --git a/src/api/data.c b/src/api/data.c index 5f3508d7..52863026 100644 --- a/src/api/data.c +++ b/src/api/data.c @@ -55,10 +55,10 @@ static int l_lovrDataNewRasterizer(lua_State* L) { float size; if (lua_type(L, 1) == LUA_TNUMBER || lua_isnoneornil(L, 1)) { - size = luaL_optnumber(L, 1, 32); + size = luaL_optnumber(L, 1, 32.f); } else { blob = luax_readblob(L, 1, "Font"); - size = luaL_optnumber(L, 2, 32); + size = luaL_optnumber(L, 2, 32.f); } Rasterizer* rasterizer = lovrRasterizerCreate(blob, size); @@ -99,8 +99,8 @@ static int l_lovrDataNewSoundData(lua_State* L) { static int l_lovrDataNewTextureData(lua_State* L) { TextureData* textureData = NULL; if (lua_type(L, 1) == LUA_TNUMBER) { - int width = luaL_checknumber(L, 1); - int height = luaL_checknumber(L, 2); + int width = luaL_checkinteger(L, 1); + int height = luaL_checkinteger(L, 2); TextureFormat format = luaL_checkoption(L, 3, "rgba", TextureFormats); textureData = lovrTextureDataCreate(width, height, 0x0, format); } else { diff --git a/src/api/graphics.c b/src/api/graphics.c index 94d5ea6b..ea770251 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -407,11 +407,7 @@ static int l_lovrGraphicsGetBackgroundColor(lua_State* L) { } static int l_lovrGraphicsSetBackgroundColor(lua_State* L) { - Color color; - color.r = luaL_checknumber(L, 1); - color.g = luaL_checknumber(L, 2); - color.b = luaL_checknumber(L, 3); - color.a = luaL_optnumber(L, 4, 1.); + Color color = luax_checkcolor(L, 1); lovrGraphicsSetBackgroundColor(color); return 0; } @@ -481,7 +477,7 @@ static int l_lovrGraphicsGetDefaultFilter(lua_State* L) { static int l_lovrGraphicsSetDefaultFilter(lua_State* L) { FilterMode mode = luaL_checkoption(L, 1, NULL, FilterModes); - float anisotropy = luaL_optnumber(L, 2, 1.); + float anisotropy = luaL_optnumber(L, 2, 1.f); lovrGraphicsSetDefaultFilter((TextureFilter) { .mode = mode, .anisotropy = anisotropy }); return 0; } @@ -670,7 +666,7 @@ static int l_lovrGraphicsClear(lua_State* L) { color.r = luaL_checknumber(L, index++); color.g = luaL_checknumber(L, index++); color.b = luaL_checknumber(L, index++); - color.a = luaL_optnumber(L, index++, 1.); + color.a = luaL_optnumber(L, index++, 1.f); } else { clearColor = lua_toboolean(L, index++); } @@ -794,8 +790,8 @@ static int l_lovrGraphicsArc(lua_State* L) { } float transform[16]; index = luax_readmat4(L, index, transform, 1, NULL); - float r1 = luaL_optnumber(L, index++, 0); - float r2 = luaL_optnumber(L, index++, 2 * M_PI); + float r1 = luaL_optnumber(L, index++, 0.f); + float r2 = luaL_optnumber(L, index++, 2.f * M_PI); int segments = luaL_optinteger(L, index, 64) * (MIN(fabsf(r2 - r1), 2 * M_PI) / (2 * M_PI)); lovrGraphicsArc(style, mode, material, transform, r1, r2, segments); return 0; @@ -811,7 +807,7 @@ static int l_lovrGraphicsCircle(lua_State* L) { } float transform[16]; int index = luax_readmat4(L, 2, transform, 1, NULL); - int segments = luaL_optnumber(L, index, 32); + int segments = luaL_optinteger(L, index, 32); lovrGraphicsCircle(style, material, transform, segments); return 0; } @@ -821,10 +817,10 @@ static int l_lovrGraphicsCylinder(lua_State* L) { int index = 1; Material* material = lua_isuserdata(L, index) ? luax_checktype(L, index++, Material) : NULL; index = luax_readmat4(L, index, transform, 1, NULL); - float r1 = luaL_optnumber(L, index++, 1.); - float r2 = luaL_optnumber(L, index++, 1.); + float r1 = luaL_optnumber(L, index++, 1.f); + float r2 = luaL_optnumber(L, index++, 1.f); bool capped = lua_isnoneornil(L, index) ? true : lua_toboolean(L, index++); - int segments = luaL_optnumber(L, index, floorf(16 + 16 * MAX(r1, r2))); + int segments = luaL_optinteger(L, index, (lua_Integer) floorf(16 + 16 * MAX(r1, r2))); lovrGraphicsCylinder(material, transform, r1, r2, capped, segments); return 0; } @@ -834,17 +830,17 @@ static int l_lovrGraphicsSphere(lua_State* L) { int index = 1; Material* material = lua_isuserdata(L, index) ? luax_checktype(L, index++, Material) : NULL; index = luax_readmat4(L, index, transform, 1, NULL); - int segments = luaL_optnumber(L, index, 30); + int segments = luaL_optinteger(L, index, 30); lovrGraphicsSphere(material, transform, segments); return 0; } static int l_lovrGraphicsSkybox(lua_State* L) { Texture* texture = luax_checktexture(L, 1); - float angle = luaL_optnumber(L, 2, 0); - float ax = luaL_optnumber(L, 3, 0); - float ay = luaL_optnumber(L, 4, 1); - float az = luaL_optnumber(L, 5, 0); + float angle = luaL_optnumber(L, 2, 0.f); + float ax = luaL_optnumber(L, 3, 0.f); + float ay = luaL_optnumber(L, 4, 1.f); + float az = luaL_optnumber(L, 5, 0.f); lovrGraphicsSkybox(texture, angle, ax, ay, az); return 0; } @@ -854,7 +850,7 @@ static int l_lovrGraphicsPrint(lua_State* L) { const char* str = luaL_checklstring(L, 1, &length); float transform[16]; int index = luax_readmat4(L, 2, transform, 1, NULL); - float wrap = luaL_optnumber(L, index++, 0); + float wrap = luaL_optnumber(L, index++, 0.f); HorizontalAlign halign = luaL_checkoption(L, index++, "center", HorizontalAligns); VerticalAlign valign = luaL_checkoption(L, index++, "middle", VerticalAligns); lovrGraphicsPrint(str, length, transform, wrap, halign, valign); @@ -877,10 +873,10 @@ 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); - float u = luaL_optnumber(L, 2, 0.); - float v = luaL_optnumber(L, 3, 0.); - float w = luaL_optnumber(L, 4, 1. - u); - float h = luaL_optnumber(L, 5, 1. - v); + float u = luaL_optnumber(L, 2, 0.f); + float v = luaL_optnumber(L, 3, 0.f); + float w = luaL_optnumber(L, 4, 1.f - u); + float h = luaL_optnumber(L, 5, 1.f - v); lovrGraphicsFill(texture, u, v, w, h); return 0; } @@ -1068,10 +1064,10 @@ static int l_lovrGraphicsNewFont(lua_State* L) { float size; if (lua_type(L, 1) == LUA_TNUMBER || lua_isnoneornil(L, 1)) { - size = luaL_optnumber(L, 1, 32); + size = luaL_optinteger(L, 1, 32); } else { blob = luax_readblob(L, 1, "Font"); - size = luaL_optnumber(L, 2, 32); + size = luaL_optinteger(L, 2, 32); } rasterizer = lovrRasterizerCreate(blob, size); diff --git a/src/api/headset.c b/src/api/headset.c index f003a2d9..89e1306b 100644 --- a/src/api/headset.c +++ b/src/api/headset.c @@ -355,12 +355,12 @@ int luaopen_lovr_headset(lua_State* L) { // Offset lua_getfield(L, -1, "offset"); - offset = luaL_optnumber(L, -1, 1.7); + offset = luaL_optnumber(L, -1, 1.7f); lua_pop(L, 1); // MSAA lua_getfield(L, -1, "msaa"); - msaa = luaL_optnumber(L, -1, 4); + msaa = luaL_optinteger(L, -1, 4); lua_pop(L, 1); } diff --git a/src/api/math.c b/src/api/math.c index 191cffc8..54a64567 100644 --- a/src/api/math.c +++ b/src/api/math.c @@ -121,7 +121,7 @@ static int l_lovrMathNewRandomGenerator(lua_State* L) { static int l_lovrMathLookAt(lua_State* L) { float from[3] = { luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3) }; float to[3] = { luaL_checknumber(L, 4), luaL_checknumber(L, 5), luaL_checknumber(L, 6) }; - float up[3] = { luaL_optnumber(L, 7, 0), luaL_optnumber(L, 8, 1), luaL_optnumber(L, 9, 0) }; + float up[3] = { luaL_optnumber(L, 7, 0.f), luaL_optnumber(L, 8, 1.f), luaL_optnumber(L, 9, 0.f) }; float m[16], q[4], angle, ax, ay, az; mat4_lookAt(m, from, to, up); quat_fromMat4(q, m); @@ -135,9 +135,9 @@ static int l_lovrMathLookAt(lua_State* L) { static int l_lovrMathOrientationToDirection(lua_State* L) { float angle = luaL_checknumber(L, 1); - float ax = luaL_optnumber(L, 2, 0); - float ay = luaL_optnumber(L, 3, 1); - float az = luaL_optnumber(L, 4, 0); + float ax = luaL_optnumber(L, 2, 0.f); + float ay = luaL_optnumber(L, 3, 1.f); + float az = luaL_optnumber(L, 4, 0.f); float v[3]; lovrMathOrientationToDirection(angle, ax, ay, az, v); lua_pushnumber(L, v[0]); diff --git a/src/api/physics.c b/src/api/physics.c index 625a51b2..d8535ee1 100644 --- a/src/api/physics.c +++ b/src/api/physics.c @@ -19,7 +19,7 @@ const char* JointTypes[] = { static int l_lovrPhysicsNewWorld(lua_State* L) { float xg = luaL_optnumber(L, 1, 0.f); - float yg = luaL_optnumber(L, 2, -9.81); + float yg = luaL_optnumber(L, 2, -9.81f); float zg = luaL_optnumber(L, 3, 0.f); bool allowSleep = lua_gettop(L) < 4 || lua_toboolean(L, 4); const char* tags[16]; diff --git a/src/api/timer.c b/src/api/timer.c index 68e6ac37..a5fab33d 100644 --- a/src/api/timer.c +++ b/src/api/timer.c @@ -12,7 +12,7 @@ static int l_lovrTimerGetAverageDelta(lua_State* L) { } static int l_lovrTimerGetFPS(lua_State* L) { - lua_pushnumber(L, lovrTimerGetFPS()); + lua_pushinteger(L, lovrTimerGetFPS()); return 1; } diff --git a/src/api/types/collider.c b/src/api/types/collider.c index 07f65c4d..d5e1ea06 100644 --- a/src/api/types/collider.c +++ b/src/api/types/collider.c @@ -277,7 +277,7 @@ int l_lovrColliderGetLinearDamping(lua_State* L) { int l_lovrColliderSetLinearDamping(lua_State* L) { Collider* collider = luax_checktype(L, 1, Collider); float damping = luaL_checknumber(L, 2); - float threshold = luaL_optnumber(L, 3, .01); + float threshold = luaL_optnumber(L, 3, .01f); lovrColliderSetLinearDamping(collider, damping, threshold); return 0; } @@ -294,7 +294,7 @@ int l_lovrColliderGetAngularDamping(lua_State* L) { int l_lovrColliderSetAngularDamping(lua_State* L) { Collider* collider = luax_checktype(L, 1, Collider); float damping = luaL_checknumber(L, 2); - float threshold = luaL_optnumber(L, 3, .01); + float threshold = luaL_optnumber(L, 3, .01f); lovrColliderSetAngularDamping(collider, damping, threshold); return 0; } diff --git a/src/api/types/controller.c b/src/api/types/controller.c index c4d41cd1..82f03d53 100644 --- a/src/api/types/controller.c +++ b/src/api/types/controller.c @@ -76,8 +76,8 @@ int l_lovrControllerIsTouched(lua_State* L) { int l_lovrControllerVibrate(lua_State* L) { Controller* controller = luax_checktype(L, 1, Controller); - float duration = luaL_optnumber(L, 2, .5); - float power = luaL_optnumber(L, 3, 1); + float duration = luaL_optnumber(L, 2, .5f); + float power = luaL_optnumber(L, 3, 1.f); lovrHeadsetDriver->controllerVibrate(controller, duration, power); return 0; } diff --git a/src/api/types/curve.c b/src/api/types/curve.c index ed98653c..561b62d9 100644 --- a/src/api/types/curve.c +++ b/src/api/types/curve.c @@ -26,8 +26,8 @@ int l_lovrCurveGetTangent(lua_State* L) { int l_lovrCurveRender(lua_State* L) { Curve* curve = luax_checktype(L, 1, Curve); int n = luaL_optinteger(L, 2, 32); - float t1 = luaL_optnumber(L, 3, 0.f); - float t2 = luaL_optnumber(L, 4, 1.f); + float t1 = luaL_optnumber(L, 3, 0.); + float t2 = luaL_optnumber(L, 4, 1.); float* points = malloc(3 * n * sizeof(float)); lovrCurveRender(curve, t1, t2, points, n); lua_createtable(L, n, 0); diff --git a/src/api/types/font.c b/src/api/types/font.c index 178549ea..663b4543 100644 --- a/src/api/types/font.c +++ b/src/api/types/font.c @@ -5,7 +5,7 @@ int l_lovrFontGetWidth(lua_State* L) { Font* font = luax_checktype(L, 1, Font); size_t length; const char* string = luaL_checklstring(L, 2, &length); - float wrap = luaL_optnumber(L, 3, 0); + float wrap = luaL_optnumber(L, 3, 0.f); float width; uint32_t lineCount; uint32_t glyphCount; @@ -59,7 +59,7 @@ int l_lovrFontGetPixelDensity(lua_State* L) { int l_lovrFontSetPixelDensity(lua_State* L) { Font* font = luax_checktype(L, 1, Font); - float pixelDensity = luaL_optnumber(L, 2, -1); + float pixelDensity = luaL_optnumber(L, 2, -1.f); lovrFontSetPixelDensity(font, pixelDensity); return 0; } diff --git a/src/api/types/mat4.c b/src/api/types/mat4.c index dddef543..89328637 100644 --- a/src/api/types/mat4.c +++ b/src/api/types/mat4.c @@ -172,16 +172,16 @@ static int l_lovrMat4GetTransform(lua_State* L) { static int l_lovrMat4SetTransform(lua_State* L) { mat4 m = luax_checkmathtype(L, 1, MATH_MAT4, NULL); - float x = luaL_optnumber(L, 2, 0.); - float y = luaL_optnumber(L, 3, 0.); - float z = luaL_optnumber(L, 4, 0.); - float sx = luaL_optnumber(L, 5, 1.); + float x = luaL_optnumber(L, 2, 0.f); + float y = luaL_optnumber(L, 3, 0.f); + float z = luaL_optnumber(L, 4, 0.f); + float sx = luaL_optnumber(L, 5, 1.f); float sy = luaL_optnumber(L, 6, sx); float sz = luaL_optnumber(L, 7, sx); - float angle = luaL_optnumber(L, 8, 0.); - float ax = luaL_optnumber(L, 9, 0.); - float ay = luaL_optnumber(L, 10, 1.); - float az = luaL_optnumber(L, 11, 0.); + float angle = luaL_optnumber(L, 8, 0.f); + float ax = luaL_optnumber(L, 9, 0.f); + float ay = luaL_optnumber(L, 10, 1.f); + float az = luaL_optnumber(L, 11, 0.f); mat4_setTransform(m, x, y, z, sx, sy, sz, angle, ax, ay, az); lua_settop(L, 1); return 1; diff --git a/src/api/types/quat.c b/src/api/types/quat.c index 16832613..89bf8fa3 100644 --- a/src/api/types/quat.c +++ b/src/api/types/quat.c @@ -10,10 +10,10 @@ int luax_readquat(lua_State* L, int index, quat q, const char* expected) { quat_set(q, 0, 0, 0, 0); return ++index; case LUA_TNUMBER: - angle = luaL_optnumber(L, index++, 0.); - ax = luaL_optnumber(L, index++, 0.); - ay = luaL_optnumber(L, index++, 1.); - az = luaL_optnumber(L, index++, 0.); + angle = luaL_optnumber(L, index++, 0.f); + ax = luaL_optnumber(L, index++, 0.f); + ay = luaL_optnumber(L, index++, 1.f); + az = luaL_optnumber(L, index++, 0.f); quat_fromAngleAxis(q, angle, ax, ay, az); return index; default: diff --git a/src/api/types/randomGenerator.c b/src/api/types/randomGenerator.c index 412f69c2..f9cc1e59 100644 --- a/src/api/types/randomGenerator.c +++ b/src/api/types/randomGenerator.c @@ -79,8 +79,8 @@ int l_lovrRandomGeneratorRandom(lua_State* L) { int l_lovrRandomGeneratorRandomNormal(lua_State* L) { RandomGenerator* generator = luax_checktype(L, 1, RandomGenerator); - float sigma = luaL_optnumber(L, 2, 1); - float mu = luaL_optnumber(L, 3, 0); + float sigma = luaL_optnumber(L, 2, 1.f); + float mu = luaL_optnumber(L, 3, 0.f); lua_pushnumber(L, mu + lovrRandomGeneratorRandomNormal(generator) * sigma); return 1; } diff --git a/src/api/types/shader.c b/src/api/types/shader.c index 6eccc7ec..79cf3b1d 100644 --- a/src/api/types/shader.c +++ b/src/api/types/shader.c @@ -59,7 +59,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des } switch (uniformType) { - case UNIFORM_FLOAT: *((float*) dest + i) = luaL_optnumber(L, j, 0.); break; + case UNIFORM_FLOAT: *((float*) dest + i) = luaL_optnumber(L, j, 0.f); break; case UNIFORM_INT: *((int*) dest + i) = luaL_optinteger(L, j, 0); break; case UNIFORM_SAMPLER: *((Texture**) dest + i) = luax_checktype(L, j, Texture); @@ -121,7 +121,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des switch (uniformType) { case UNIFORM_FLOAT: case UNIFORM_MATRIX: - *((float*) dest + i * components + j) = luaL_optnumber(L, -1, 0.); + *((float*) dest + i * components + j) = luaL_optnumber(L, -1, 0.f); break; case UNIFORM_INT: @@ -160,11 +160,11 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des switch (uniformType) { case UNIFORM_FLOAT: case UNIFORM_MATRIX: - *((float*) dest + i * components + j) = luaL_optnumber(L, -1, 0.); + *((float*) dest + i * components + j) = luaL_optnumber(L, -1, 0.f); break; case UNIFORM_INT: - *((float*) dest + i * components + j) = luaL_optinteger(L, -1, 0); + *((int*) dest + i * components + j) = luaL_optinteger(L, -1, 0); break; case UNIFORM_SAMPLER: diff --git a/src/api/types/texture.c b/src/api/types/texture.c index 6a16fa37..7a5fa7b7 100644 --- a/src/api/types/texture.c +++ b/src/api/types/texture.c @@ -92,7 +92,7 @@ int l_lovrTextureReplacePixels(lua_State* L) { int l_lovrTextureSetFilter(lua_State* L) { Texture* texture = luax_checktype(L, 1, Texture); FilterMode mode = luaL_checkoption(L, 2, NULL, FilterModes); - float anisotropy = luaL_optnumber(L, 3, 1.); + float anisotropy = luaL_optnumber(L, 3, 1.f); TextureFilter filter = { .mode = mode, .anisotropy = anisotropy }; lovrTextureSetFilter(texture, filter); return 0; diff --git a/src/api/types/vec3.c b/src/api/types/vec3.c index 921d6774..8b0ff2d4 100644 --- a/src/api/types/vec3.c +++ b/src/api/types/vec3.c @@ -10,9 +10,9 @@ int luax_readvec3(lua_State* L, int index, vec3 v, const char* expected) { v[0] = v[1] = v[2] = 0.f; return ++index; case LUA_TNUMBER: - v[0] = luaL_optnumber(L, index++, 0.); - v[1] = luaL_optnumber(L, index++, 0.); - v[2] = luaL_optnumber(L, index++, 0.); + v[0] = luaL_optnumber(L, index++, 0.f); + v[1] = luaL_optnumber(L, index++, 0.f); + v[2] = luaL_optnumber(L, index++, 0.f); return index; default: vec3_init(v, luax_checkmathtype(L, index++, MATH_VEC3, expected ? expected : "vec3 or number")); @@ -28,7 +28,7 @@ int luax_readscale(lua_State* L, int index, vec3 v, int components, const char* return index + components; case LUA_TNUMBER: if (components == 1) { - v[0] = v[1] = v[2] = luaL_optnumber(L, index++, 0.); + v[0] = v[1] = v[2] = luaL_optnumber(L, index++, 0.f); } else { v[0] = 1.f; for (int i = 0; i < components; i++) { @@ -67,7 +67,7 @@ static int l_lovrVec3Unpack(lua_State* L) { int l_lovrVec3Set(lua_State* L) { vec3 v = luax_checkmathtype(L, 1, MATH_VEC3, NULL); if (lua_isnoneornil(L, 2) || lua_type(L, 2) == LUA_TNUMBER) { - float x = luaL_optnumber(L, 2, 0.); + float x = luaL_optnumber(L, 2, 0.f); vec3_set(v, x, luaL_optnumber(L, 3, x), luaL_optnumber(L, 4, x)); } else { vec3 u = luax_checkmathtype(L, 2, MATH_VEC3, "vec3 or number"); diff --git a/src/api/types/vertexData.c b/src/api/types/vertexData.c index cb9cc9d7..f8280a9b 100644 --- a/src/api/types/vertexData.c +++ b/src/api/types/vertexData.c @@ -199,7 +199,7 @@ int l_lovrVertexDataSetVertices(lua_State* L) { VertexFormat* format = &vertexData->format; luaL_checktype(L, 2, LUA_TTABLE); uint32_t vertexCount = lua_objlen(L, 2); - int start = luaL_optnumber(L, 3, 1) - 1; + int start = luaL_optinteger(L, 3, 1) - 1; lovrAssert(start + vertexCount <= vertexData->count, "VertexData can only hold %d vertices", vertexData->count); VertexPointer vertices = { .raw = vertexData->blob.data }; vertices.bytes += start * format->stride; diff --git a/src/api/types/world.c b/src/api/types/world.c index f42c3631..41782bee 100644 --- a/src/api/types/world.c +++ b/src/api/types/world.c @@ -39,9 +39,9 @@ static void raycastCallback(Shape* shape, float x, float y, float z, float nx, f int l_lovrWorldNewCollider(lua_State* L) { World* world = luax_checktype(L, 1, World); - float x = luaL_optnumber(L, 2, 0); - float y = luaL_optnumber(L, 3, 0); - float z = luaL_optnumber(L, 4, 0); + float x = luaL_optnumber(L, 2, 0.f); + float y = luaL_optnumber(L, 3, 0.f); + float z = luaL_optnumber(L, 4, 0.f); Collider* collider = lovrColliderCreate(world, x, y, z); luax_pushobject(L, collider); lovrRelease(collider); @@ -50,9 +50,9 @@ int l_lovrWorldNewCollider(lua_State* L) { int l_lovrWorldNewBoxCollider(lua_State* L) { World* world = luax_checktype(L, 1, World); - float x = luaL_optnumber(L, 2, 0); - float y = luaL_optnumber(L, 3, 0); - float z = luaL_optnumber(L, 4, 0); + float x = luaL_optnumber(L, 2, 0.f); + float y = luaL_optnumber(L, 3, 0.f); + float z = luaL_optnumber(L, 4, 0.f); float sx = luaL_optnumber(L, 5, 1.f); float sy = luaL_optnumber(L, 6, sx); float sz = luaL_optnumber(L, 7, sx); @@ -67,9 +67,9 @@ int l_lovrWorldNewBoxCollider(lua_State* L) { int l_lovrWorldNewCapsuleCollider(lua_State* L) { World* world = luax_checktype(L, 1, World); - float x = luaL_optnumber(L, 2, 0); - float y = luaL_optnumber(L, 3, 0); - float z = luaL_optnumber(L, 4, 0); + float x = luaL_optnumber(L, 2, 0.f); + float y = luaL_optnumber(L, 3, 0.f); + float z = luaL_optnumber(L, 4, 0.f); float radius = luaL_optnumber(L, 5, 1.f); float length = luaL_optnumber(L, 6, 1.f); Collider* collider = lovrColliderCreate(world, x, y, z); @@ -83,9 +83,9 @@ int l_lovrWorldNewCapsuleCollider(lua_State* L) { int l_lovrWorldNewCylinderCollider(lua_State* L) { World* world = luax_checktype(L, 1, World); - float x = luaL_optnumber(L, 2, 0); - float y = luaL_optnumber(L, 3, 0); - float z = luaL_optnumber(L, 4, 0); + float x = luaL_optnumber(L, 2, 0.f); + float y = luaL_optnumber(L, 3, 0.f); + float z = luaL_optnumber(L, 4, 0.f); float radius = luaL_optnumber(L, 5, 1.f); float length = luaL_optnumber(L, 6, 1.f); Collider* collider = lovrColliderCreate(world, x, y, z); @@ -99,9 +99,9 @@ int l_lovrWorldNewCylinderCollider(lua_State* L) { int l_lovrWorldNewSphereCollider(lua_State* L) { World* world = luax_checktype(L, 1, World); - float x = luaL_optnumber(L, 2, 0); - float y = luaL_optnumber(L, 3, 0); - float z = luaL_optnumber(L, 4, 0); + float x = luaL_optnumber(L, 2, 0.f); + float y = luaL_optnumber(L, 3, 0.f); + float z = luaL_optnumber(L, 4, 0.f); float radius = luaL_optnumber(L, 5, 1.f); Collider* collider = lovrColliderCreate(world, x, y, z); SphereShape* shape = lovrSphereShapeCreate(radius); @@ -144,8 +144,8 @@ int l_lovrWorldCollide(lua_State* L) { World* world = luax_checktype(L, 1, World); Shape* a = luax_checktype(L, 2, Shape); Shape* b = luax_checktype(L, 3, Shape); - float friction = luaL_optnumber(L, 4, -1); - float restitution = luaL_optnumber(L, 5, -1); + float friction = luaL_optnumber(L, 4, -1.f); + float restitution = luaL_optnumber(L, 5, -1.f); lua_pushboolean(L, lovrWorldCollide(world, a, b, friction, restitution)); return 1; } @@ -181,7 +181,7 @@ int l_lovrWorldGetLinearDamping(lua_State* L) { int l_lovrWorldSetLinearDamping(lua_State* L) { World* world = luax_checktype(L, 1, World); float damping = luaL_checknumber(L, 2); - float threshold = luaL_optnumber(L, 3, .01); + float threshold = luaL_optnumber(L, 3, .01f); lovrWorldSetLinearDamping(world, damping, threshold); return 0; } @@ -198,7 +198,7 @@ int l_lovrWorldGetAngularDamping(lua_State* L) { int l_lovrWorldSetAngularDamping(lua_State* L) { World* world = luax_checktype(L, 1, World); float damping = luaL_checknumber(L, 2); - float threshold = luaL_optnumber(L, 3, .01); + float threshold = luaL_optnumber(L, 3, .01f); lovrWorldSetAngularDamping(world, damping, threshold); return 0; } diff --git a/src/data/rasterizer.c b/src/data/rasterizer.c index eb841232..b6b992fa 100644 --- a/src/data/rasterizer.c +++ b/src/data/rasterizer.c @@ -5,7 +5,7 @@ #include "msdfgen-c.h" #include -Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, int size) { +Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, float size) { stbtt_fontinfo* font = &rasterizer->font; unsigned char* data = blob ? blob->data : VarelaRound_ttf; if (!stbtt_InitFont(font, data, stbtt_GetFontOffsetForIndex(data, 0))) { diff --git a/src/data/rasterizer.h b/src/data/rasterizer.h index 39e36944..e11ef6d8 100644 --- a/src/data/rasterizer.h +++ b/src/data/rasterizer.h @@ -14,7 +14,7 @@ typedef struct { Ref ref; stbtt_fontinfo font; Blob* blob; - int size; + float size; float scale; int glyphCount; int height; @@ -38,7 +38,7 @@ typedef struct { typedef map_t(Glyph) map_glyph_t; -Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, int size); +Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, float size); #define lovrRasterizerCreate(...) lovrRasterizerInit(lovrAlloc(Rasterizer), __VA_ARGS__) void lovrRasterizerDestroy(void* ref); bool lovrRasterizerHasGlyph(Rasterizer* fontData, uint32_t character); diff --git a/src/luax.c b/src/luax.c index 21f19458..a276a2e6 100644 --- a/src/luax.c +++ b/src/luax.c @@ -275,13 +275,13 @@ Color luax_checkcolor(lua_State* L, int index) { color.r = luaL_checknumber(L, -4); color.g = luaL_checknumber(L, -3); color.b = luaL_checknumber(L, -2); - color.a = luaL_optnumber(L, -1, 1); + color.a = luaL_optnumber(L, -1, 1.f); lua_pop(L, 4); } else if (lua_gettop(L) >= index + 2) { color.r = luaL_checknumber(L, index); color.g = luaL_checknumber(L, index + 1); color.b = luaL_checknumber(L, index + 2); - color.a = luaL_optnumber(L, index + 3, 1); + color.a = luaL_optnumber(L, index + 3, 1.f); } else { luaL_error(L, "Invalid color, expected 3 numbers, 4 numbers, or a table"); }