diff --git a/CMakeLists.txt b/CMakeLists.txt index e65fe3c7..7bce983a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -517,6 +517,7 @@ if(WIN32) set_target_properties(lovr PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") set_target_properties(lovr PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") target_compile_definitions(lovr PUBLIC -D_CRT_SECURE_NO_WARNINGS) + target_compile_definitions(lovr PUBLIC -D_CRT_NONSTDC_NO_WARNINGS) if(MSVC_VERSION VERSION_LESS 1900) target_compile_definitions(lovr PUBLIC -Dinline=__inline -Dsnprintf=_snprintf) diff --git a/src/api/data.c b/src/api/data.c index 9034e730..d0de0361 100644 --- a/src/api/data.c +++ b/src/api/data.c @@ -37,7 +37,7 @@ static int l_lovrDataNewBlob(lua_State* L) { static int l_lovrDataNewAudioStream(lua_State* L) { Blob* blob = luax_readblob(L, 1, "AudioStream"); - size_t bufferSize = luaL_optinteger(L, 2, 4096); + int bufferSize = luaL_optinteger(L, 2, 4096); AudioStream* stream = lovrAudioStreamCreate(blob, bufferSize); luax_pushobject(L, stream); lovrRelease(blob); diff --git a/src/api/filesystem.c b/src/api/filesystem.c index 223d2c56..8bcd3b85 100644 --- a/src/api/filesystem.c +++ b/src/api/filesystem.c @@ -26,7 +26,7 @@ Blob* luax_readblob(lua_State* L, int index, const char* debug) { static int pushDirectoryItem(void* userdata, const char* path, const char* filename) { lua_State* L = userdata; - int n = lua_objlen(L, -1); + int n = luax_len(L, -1); lua_pushstring(L, filename); lua_rawseti(L, -2, n + 1); return 1; diff --git a/src/api/graphics.c b/src/api/graphics.c index 182e5d09..d0825a6a 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -13,7 +13,6 @@ #include "data/textureData.h" #include "filesystem/filesystem.h" #include "util.h" -#define _USE_MATH_DEFINES #include #include @@ -205,7 +204,7 @@ const char* WrapModes[] = { static uint32_t luax_getvertexcount(lua_State* L, int index) { int type = lua_type(L, index); if (type == LUA_TTABLE) { - size_t count = lua_objlen(L, index); + int count = luax_len(L, index); lua_rawgeti(L, index, 1); int tableType = lua_type(L, -1); lua_pop(L, 1); @@ -1138,14 +1137,14 @@ static int l_lovrGraphicsNewMesh(lua_State* L) { } else if (lua_istable(L, 2)) { drawModeIndex++; formatIndex = 1; - count = lua_objlen(L, 2); + count = luax_len(L, 2); dataIndex = 2; } else if ((blob = luax_totype(L, 2, Blob)) != NULL) { drawModeIndex++; formatIndex = 1; dataIndex = 2; } else { - count = lua_objlen(L, 1); + count = luax_len(L, 1); dataIndex = 1; } } else { @@ -1168,7 +1167,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) { attributeNames[1] = "lovrNormal"; attributeNames[2] = "lovrTexCoord"; } else { - attributeCount = lua_objlen(L, formatIndex); + attributeCount = luax_len(L, formatIndex); lovrAssert(attributeCount >= 0 && attributeCount <= MAX_ATTRIBUTES, "Attribute count must be between 0 and %d", MAX_ATTRIBUTES); for (int i = 0; i < attributeCount; i++) { lua_rawgeti(L, formatIndex, i + 1); @@ -1178,7 +1177,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) { lua_rawgeti(L, -3, 1); attributeNames[i] = lua_tostring(L, -1); - attributes[i].offset = stride; + attributes[i].offset = (uint32_t) stride; attributes[i].type = luaL_checkoption(L, -2, "float", AttributeTypes); attributes[i].components = luaL_optinteger(L, -3, 1); @@ -1192,7 +1191,8 @@ static int l_lovrGraphicsNewMesh(lua_State* L) { } if (blob) { - count = blob->size / stride; + lovrAssert(blob->size / stride < UINT32_MAX, "Too many vertices in Blob"); + count = (uint32_t) (blob->size / stride); } DrawMode mode = luaL_checkoption(L, drawModeIndex, "fan", DrawModes); @@ -1232,7 +1232,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) { int component = 0; for (int j = 0; j < attributeCount; j++) { MeshAttribute* attribute = &attributes[j]; - for (int k = 0; k < attribute->components; k++) { + for (unsigned k = 0; k < attribute->components; k++) { lua_rawgeti(L, -1, ++component); switch (attribute->type) { case I8: *data.i8++ = luaL_optinteger(L, -1, 0); break; @@ -1341,7 +1341,7 @@ static int l_lovrGraphicsNewTexture(lua_State* L) { depth = 1; index++; } else { - depth = lua_objlen(L, index++); + depth = luax_len(L, index++); type = depth > 0 ? TEXTURE_ARRAY : TEXTURE_CUBE; } diff --git a/src/api/headset.c b/src/api/headset.c index 68524459..12748a03 100644 --- a/src/api/headset.c +++ b/src/api/headset.c @@ -345,7 +345,7 @@ int luaopen_lovr_headset(lua_State* L) { // Drivers lua_getfield(L, -1, "drivers"); - int n = lua_objlen(L, -1); + int n = luax_len(L, -1); for (int i = 0; i < n; i++) { lua_rawgeti(L, -1, i + 1); vec_push(&drivers, luaL_checkoption(L, -1, NULL, HeadsetDrivers)); diff --git a/src/api/math.c b/src/api/math.c index 00d567cf..a038bfe8 100644 --- a/src/api/math.c +++ b/src/api/math.c @@ -82,7 +82,7 @@ static int l_lovrMathNewCurve(lua_State* L) { if (lua_istable(L, 1)) { int pointIndex = 0; - int length = lua_objlen(L, 1); + int length = luax_len(L, 1); for (int i = 1; i <= length;) { lua_rawgeti(L, 1, i + 0); lua_rawgeti(L, 1, i + 1); diff --git a/src/api/physics.c b/src/api/physics.c index 2d3d51ac..ea701fba 100644 --- a/src/api/physics.c +++ b/src/api/physics.c @@ -25,7 +25,7 @@ static int l_lovrPhysicsNewWorld(lua_State* L) { const char* tags[16]; int tagCount; if (lua_type(L, 5) == LUA_TTABLE) { - tagCount = lua_objlen(L, 5); + tagCount = luax_len(L, 5); for (int i = 0; i < tagCount; i++) { lua_rawgeti(L, -1, i + 1); if (lua_isstring(L, -1)) { diff --git a/src/api/types/canvas.c b/src/api/types/canvas.c index 1eaef2de..581f711a 100644 --- a/src/api/types/canvas.c +++ b/src/api/types/canvas.c @@ -42,7 +42,7 @@ void luax_readattachments(lua_State* L, int index, Attachment* attachments, int* int n; if (lua_istable(L, index)) { - n = lua_objlen(L, index); + n = luax_len(L, index); n = MIN(n, 3 * MAX_CANVAS_ATTACHMENTS); for (int i = 0; i < n; i++) { lua_rawgeti(L, index, i + 1); diff --git a/src/api/types/collider.c b/src/api/types/collider.c index c13cac66..5f53ca19 100644 --- a/src/api/types/collider.c +++ b/src/api/types/collider.c @@ -53,16 +53,16 @@ static int l_lovrColliderGetJoints(lua_State* L) { static int l_lovrColliderGetUserData(lua_State* L) { Collider* collider = luax_checktype(L, 1, Collider); - int ref = (int) lovrColliderGetUserData(collider); - lua_rawgeti(L, LUA_REGISTRYINDEX, ref); + union { int i; void* p; } ref = { .p = lovrColliderGetUserData(collider) }; + lua_rawgeti(L, LUA_REGISTRYINDEX, ref.i); return 1; } static int l_lovrColliderSetUserData(lua_State* L) { Collider* collider = luax_checktype(L, 1, Collider); - uint64_t ref = (int) lovrColliderGetUserData(collider); - if (ref) { - luaL_unref(L, LUA_REGISTRYINDEX, ref); + union { int i; void* p; } ref = { .p = lovrColliderGetUserData(collider) }; + if (ref.i) { + luaL_unref(L, LUA_REGISTRYINDEX, ref.i); } if (lua_gettop(L) < 2) { @@ -70,8 +70,8 @@ static int l_lovrColliderSetUserData(lua_State* L) { } lua_settop(L, 2); - ref = luaL_ref(L, LUA_REGISTRYINDEX); - lovrColliderSetUserData(collider, (void*) ref); + ref.i = luaL_ref(L, LUA_REGISTRYINDEX); + lovrColliderSetUserData(collider, ref.p); return 0; } @@ -164,7 +164,7 @@ static int l_lovrColliderSetMassData(lua_State* L) { float cz = luax_checkfloat(L, 4); float mass = luax_checkfloat(L, 5); float inertia[6]; - if (lua_istable(L, 6) && lua_objlen(L, 6) >= 6) { + if (lua_istable(L, 6) && luax_len(L, 6) >= 6) { for (int i = 0; i < 6; i++) { lua_rawgeti(L, 6, i + 1); if (!lua_isnumber(L, -1)) { diff --git a/src/api/types/joints.c b/src/api/types/joints.c index fb465ca3..c7cf08e5 100644 --- a/src/api/types/joints.c +++ b/src/api/types/joints.c @@ -25,16 +25,16 @@ static int l_lovrJointGetColliders(lua_State* L) { static int l_lovrJointGetUserData(lua_State* L) { Joint* joint = luax_checktype(L, 1, Joint); - int ref = (int) lovrJointGetUserData(joint); - lua_rawgeti(L, LUA_REGISTRYINDEX, ref); + union { int i; void* p; } ref = { .p = lovrJointGetUserData(joint) }; + lua_rawgeti(L, LUA_REGISTRYINDEX, ref.i); return 1; } static int l_lovrJointSetUserData(lua_State* L) { Joint* joint = luax_checktype(L, 1, Joint); - uint64_t ref = (int) lovrJointGetUserData(joint); - if (ref) { - luaL_unref(L, LUA_REGISTRYINDEX, ref); + union { int i; void* p; } ref = { .p = lovrJointGetUserData(joint) }; + if (ref.i) { + luaL_unref(L, LUA_REGISTRYINDEX, ref.i); } if (lua_gettop(L) < 2) { @@ -42,8 +42,8 @@ static int l_lovrJointSetUserData(lua_State* L) { } lua_settop(L, 2); - ref = luaL_ref(L, LUA_REGISTRYINDEX); - lovrJointSetUserData(joint, (void*) ref); + ref.i = luaL_ref(L, LUA_REGISTRYINDEX); + lovrJointSetUserData(joint, ref.p); return 0; } diff --git a/src/api/types/mesh.c b/src/api/types/mesh.c index 44c3dd85..bc18a795 100644 --- a/src/api/types/mesh.c +++ b/src/api/types/mesh.c @@ -18,7 +18,7 @@ static int l_lovrMeshAttachAttributes(lua_State* L) { lovrMeshAttachAttribute(mesh, other->attributeNames[i], &attachment); } } else if (lua_istable(L, 4)) { - int length = lua_objlen(L, 4); + int length = luax_len(L, 4); for (int i = 0; i < length; i++) { lua_rawgeti(L, 4, i + 1); const char* name = lua_tostring(L, -1); @@ -56,7 +56,7 @@ static int l_lovrMeshDetachAttributes(lua_State* L) { lovrMeshDetachAttribute(mesh, other->attributeNames[i]); } } else if (lua_istable(L, 2)) { - int length = lua_objlen(L, 2); + int length = luax_len(L, 2); for (int i = 0; i < length; i++) { lua_rawgeti(L, 2, i + 1); lovrMeshDetachAttribute(mesh, lua_tostring(L, -1)); @@ -152,7 +152,7 @@ static int l_lovrMeshGetVertex(lua_State* L) { if (attribute->buffer != mesh->vertexBuffer) { break; } - for (int j = 0; j < attribute->components; j++, components++) { + for (unsigned j = 0; j < attribute->components; j++, components++) { switch (attribute->type) { case I8: lua_pushinteger(L, *data.i8++); break; case U8: lua_pushinteger(L, *data.u8++); break; @@ -186,7 +186,7 @@ static int l_lovrMeshSetVertex(lua_State* L) { break; } - for (int j = 0; j < attribute->components; j++) { + for (unsigned j = 0; j < attribute->components; j++) { int k = 3 + j; if (table) { lua_rawgeti(L, 3, ++component); @@ -223,7 +223,7 @@ static int l_lovrMeshGetVertexAttribute(lua_State* L) { lovrAssert(mesh->attributes[attributeIndex].buffer == mesh->vertexBuffer, "Invalid mesh attribute: %d", attributeIndex + 1); MeshAttribute* attribute = &mesh->attributes[attributeIndex]; AttributeData data = { .raw = lovrBufferMap(buffer, vertexIndex * attribute->stride + attribute->offset) }; - for (int i = 0; i < attribute->components; i++) { + for (unsigned i = 0; i < attribute->components; i++) { switch (attribute->type) { case I8: lua_pushinteger(L, *data.i8++); break; case U8: lua_pushinteger(L, *data.u8++); break; @@ -247,7 +247,7 @@ static int l_lovrMeshSetVertexAttribute(lua_State* L) { lovrAssert(mesh->attributes[attributeIndex].buffer == mesh->vertexBuffer, "Invalid mesh attribute: %d", attributeIndex + 1); MeshAttribute* attribute = &mesh->attributes[attributeIndex]; AttributeData data = { .raw = lovrBufferMap(mesh->vertexBuffer, vertexIndex * attribute->stride + attribute->offset) }; - for (int i = 0; i < attribute->components; i++) { + for (unsigned i = 0; i < attribute->components; i++) { int index = 4 + i; if (table) { lua_rawgeti(L, 4, i + 1); @@ -276,7 +276,7 @@ static int l_lovrMeshSetVertices(lua_State* L) { Mesh* mesh = luax_checktype(L, 1, Mesh); uint32_t capacity = lovrMeshGetVertexCount(mesh); luaL_checktype(L, 2, LUA_TTABLE); - uint32_t sourceSize = lua_objlen(L, 2); + uint32_t sourceSize = luax_len(L, 2); uint32_t start = luaL_optinteger(L, 3, 1) - 1; uint32_t count = luaL_optinteger(L, 4, sourceSize); lovrAssert(start + count <= capacity, "Overflow in Mesh:setVertices: Mesh can only hold %d vertices", capacity); @@ -299,7 +299,7 @@ static int l_lovrMeshSetVertices(lua_State* L) { break; } - for (int k = 0; k < attribute->components; k++) { + for (unsigned k = 0; k < attribute->components; k++) { lua_rawgeti(L, -1, ++component); switch (attribute->type) { @@ -348,7 +348,7 @@ static int l_lovrMeshGetVertexMap(lua_State* L) { lua_createtable(L, count, 0); } - for (size_t i = 0; i < count; i++) { + for (uint32_t i = 0; i < count; i++) { uint32_t index = size == sizeof(uint32_t) ? indices.ints[i] : indices.shorts[i]; lua_pushinteger(L, index + 1); lua_rawseti(L, 2, i + 1); @@ -369,7 +369,8 @@ static int l_lovrMeshSetVertexMap(lua_State* L) { Blob* blob = luax_checktype(L, 2, Blob); size_t size = luaL_optinteger(L, 3, 4); lovrAssert(size == 2 || size == 4, "Size of Mesh indices should be 2 bytes or 4 bytes"); - uint32_t count = blob->size / size; + lovrAssert(blob->size / size < UINT32_MAX, "Too many Mesh indices"); + uint32_t count = (uint32_t) (blob->size / size); Buffer* indexBuffer = lovrMeshGetIndexBuffer(mesh); if (!indexBuffer || count * size > lovrBufferGetSize(indexBuffer)) { Buffer* vertexBuffer = lovrMeshGetVertexBuffer(mesh); @@ -384,7 +385,7 @@ static int l_lovrMeshSetVertexMap(lua_State* L) { } } else { luaL_checktype(L, 2, LUA_TTABLE); - uint32_t count = lua_objlen(L, 2); + uint32_t count = luax_len(L, 2); uint32_t vertexCount = lovrMeshGetVertexCount(mesh); size_t size = vertexCount > USHRT_MAX ? sizeof(uint32_t) : sizeof(uint16_t); diff --git a/src/api/types/shader.c b/src/api/types/shader.c index 15b69c57..e0a4f17c 100644 --- a/src/api/types/shader.c +++ b/src/api/types/shader.c @@ -49,7 +49,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des if (components == 1) { bool isTable = lua_istable(L, index); - int length = isTable ? lua_objlen(L, index) : count; + int length = isTable ? luax_len(L, index) : count; length = MIN(length, count); for (int i = 0; i < count; i++) { int j = index + i; @@ -95,7 +95,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des } if (wrappedTable) { - int length = lua_objlen(L, index); + int length = luax_len(L, index); length = MIN(length, count); for (int i = 0; i < length; i++) { lua_rawgeti(L, index, i + 1); diff --git a/src/api/types/shapes.c b/src/api/types/shapes.c index 68875abf..51f35271 100644 --- a/src/api/types/shapes.c +++ b/src/api/types/shapes.c @@ -34,16 +34,16 @@ static int l_lovrShapeSetEnabled(lua_State* L) { static int l_lovrShapeGetUserData(lua_State* L) { Shape* shape = luax_checktype(L, 1, Shape); - int ref = (int) lovrShapeGetUserData(shape); - lua_rawgeti(L, LUA_REGISTRYINDEX, ref); + union { int i; void* p; } ref = { .p = lovrShapeGetUserData(shape) }; + lua_rawgeti(L, LUA_REGISTRYINDEX, ref.i); return 1; } static int l_lovrShapeSetUserData(lua_State* L) { Shape* shape = luax_checktype(L, 1, Shape); - uint64_t ref = (int) lovrShapeGetUserData(shape); - if (ref) { - luaL_unref(L, LUA_REGISTRYINDEX, ref); + union { int i; void* p; } ref = { .p = lovrShapeGetUserData(shape) }; + if (ref.i) { + luaL_unref(L, LUA_REGISTRYINDEX, ref.i); } if (lua_gettop(L) < 2) { @@ -51,8 +51,8 @@ static int l_lovrShapeSetUserData(lua_State* L) { } lua_settop(L, 2); - ref = luaL_ref(L, LUA_REGISTRYINDEX); - lovrShapeSetUserData(shape, (void*) ref); + ref.i = luaL_ref(L, LUA_REGISTRYINDEX); + lovrShapeSetUserData(shape, ref.p); return 0; } diff --git a/src/audio/source.c b/src/audio/source.c index 1f067ae1..0e7b27f5 100644 --- a/src/audio/source.c +++ b/src/audio/source.c @@ -1,7 +1,6 @@ #include "audio/source.h" #include "audio/audio.h" #include "data/audioStream.h" -#define _USE_MATH_DEFINES #include #include @@ -17,7 +16,7 @@ Source* lovrSourceInitStatic(Source* source, SoundData* soundData) { source->soundData = soundData; alGenSources(1, &source->id); alGenBuffers(1, source->buffers); - alBufferData(source->buffers[0], format, soundData->blob.data, soundData->blob.size, soundData->sampleRate); + alBufferData(source->buffers[0], format, soundData->blob.data, (ALsizei) soundData->blob.size, soundData->sampleRate); alSourcei(source->id, AL_BUFFER, source->buffers[0]); lovrRetain(soundData); return source; diff --git a/src/data/audioStream.c b/src/data/audioStream.c index 92d75ced..788ae7d5 100644 --- a/src/data/audioStream.c +++ b/src/data/audioStream.c @@ -3,8 +3,8 @@ #include "util.h" #include -AudioStream* lovrAudioStreamInit(AudioStream* stream, Blob* blob, size_t bufferSize) { - stb_vorbis* decoder = stb_vorbis_open_memory(blob->data, blob->size, NULL, NULL); +AudioStream* lovrAudioStreamInit(AudioStream* stream, Blob* blob, int bufferSize) { + stb_vorbis* decoder = stb_vorbis_open_memory(blob->data, (int) blob->size, NULL, NULL); lovrAssert(decoder, "Could not create audio stream for '%s'", blob->name); stb_vorbis_info info = stb_vorbis_get_info(decoder); @@ -30,7 +30,7 @@ void lovrAudioStreamDestroy(void* ref) { free(stream->buffer); } -int lovrAudioStreamDecode(AudioStream* stream, short* destination, size_t size) { +int lovrAudioStreamDecode(AudioStream* stream, short* destination, int size) { stb_vorbis* decoder = (stb_vorbis*) stream->decoder; short* buffer = destination ? destination : (short*) stream->buffer; int capacity = destination ? size : (stream->bufferSize / sizeof(short)); diff --git a/src/data/audioStream.h b/src/data/audioStream.h index 42e7d6aa..833a74d2 100644 --- a/src/data/audioStream.h +++ b/src/data/audioStream.h @@ -15,10 +15,10 @@ typedef struct { Blob* blob; } AudioStream; -AudioStream* lovrAudioStreamInit(AudioStream* stream, Blob* blob, size_t bufferSize); +AudioStream* lovrAudioStreamInit(AudioStream* stream, Blob* blob, int bufferSize); #define lovrAudioStreamCreate(...) lovrAudioStreamInit(lovrAlloc(AudioStream), __VA_ARGS__) void lovrAudioStreamDestroy(void* ref); -int lovrAudioStreamDecode(AudioStream* stream, short* destination, size_t size); +int lovrAudioStreamDecode(AudioStream* stream, short* destination, int size); void lovrAudioStreamRewind(AudioStream* stream); void lovrAudioStreamSeek(AudioStream* stream, int sample); int lovrAudioStreamTell(AudioStream* stream); diff --git a/src/data/modelData.h b/src/data/modelData.h index 1b6971b3..09c12e5b 100644 --- a/src/data/modelData.h +++ b/src/data/modelData.h @@ -106,7 +106,7 @@ typedef struct { } ModelBuffer; typedef struct { - size_t offset; + uint32_t offset; uint32_t buffer; uint32_t count; AttributeType type; diff --git a/src/data/modelData_gltf.c b/src/data/modelData_gltf.c index 7dff4bae..fba467b3 100644 --- a/src/data/modelData_gltf.c +++ b/src/data/modelData_gltf.c @@ -160,7 +160,7 @@ ModelData* lovrModelDataInitGltf(ModelData* model, Blob* source) { int tokenCount = 0; if ((tokenCount = jsmn_parse(&parser, json, jsonLength, stackTokens, MAX_STACK_TOKENS)) == JSMN_ERROR_NOMEM) { - size_t capacity = MAX_STACK_TOKENS; + int capacity = MAX_STACK_TOKENS; jsmn_init(&parser); // This shouldn't be necessary but not doing it caused an infinite loop? do { diff --git a/src/data/rasterizer.c b/src/data/rasterizer.c index b6b992fa..66500594 100644 --- a/src/data/rasterizer.c +++ b/src/data/rasterizer.c @@ -41,8 +41,7 @@ bool lovrRasterizerHasGlyph(Rasterizer* rasterizer, uint32_t character) { } bool lovrRasterizerHasGlyphs(Rasterizer* rasterizer, const char* str) { - int len = strlen(str); - const char* end = str + len; + const char* end = str + strlen(str); unsigned int codepoint; size_t bytes; diff --git a/src/data/soundData.c b/src/data/soundData.c index 2cd48617..b24bfad6 100644 --- a/src/data/soundData.c +++ b/src/data/soundData.c @@ -24,9 +24,9 @@ SoundData* lovrSoundDataInitFromAudioStream(SoundData* soundData, AudioStream* a int samples; short* buffer = soundData->blob.data; - size_t offset = 0; + int offset = 0; lovrAudioStreamRewind(audioStream); - while ((samples = lovrAudioStreamDecode(audioStream, buffer + offset, soundData->blob.size - (offset * sizeof(short)))) != 0) { + while ((samples = lovrAudioStreamDecode(audioStream, buffer + offset, (int) soundData->blob.size - (offset * sizeof(short)))) != 0) { offset += samples; } @@ -35,7 +35,7 @@ SoundData* lovrSoundDataInitFromAudioStream(SoundData* soundData, AudioStream* a SoundData* lovrSoundDataInitFromBlob(SoundData* soundData, Blob* blob) { soundData->bitDepth = 16; - soundData->samples = stb_vorbis_decode_memory(blob->data, blob->size, &soundData->channelCount, &soundData->sampleRate, (short**) &soundData->blob.data); + soundData->samples = stb_vorbis_decode_memory(blob->data, (int) blob->size, &soundData->channelCount, &soundData->sampleRate, (short**) &soundData->blob.data); soundData->blob.size = soundData->samples * soundData->channelCount * (soundData->bitDepth / 8); return soundData; } diff --git a/src/data/textureData.c b/src/data/textureData.c index f4f9cbe3..10f581ce 100644 --- a/src/data/textureData.c +++ b/src/data/textureData.c @@ -111,9 +111,9 @@ static int parseDDS(uint8_t* data, size_t size, TextureData* textureData) { // Load mipmaps for (int i = 0; i < mipmapCount; i++) { - size_t numBlocksWide = width ? MAX(1, (width + 3) / 4) : 0; - size_t numBlocksHigh = height ? MAX(1, (height + 3) / 4) : 0; - size_t mipmapSize = numBlocksWide * numBlocksHigh * blockBytes; + int numBlocksWide = width ? MAX(1, (width + 3) / 4) : 0; + int numBlocksHigh = height ? MAX(1, (height + 3) / 4) : 0; + int mipmapSize = numBlocksWide * numBlocksHigh * blockBytes; // Overflow check if (mipmapSize == 0 || (offset + mipmapSize) > size) { @@ -158,13 +158,14 @@ TextureData* lovrTextureDataInitFromBlob(TextureData* textureData, Blob* blob, b return textureData; } + int length = (int) blob->size; stbi_set_flip_vertically_on_load(flip); - if (stbi_is_hdr_from_memory(blob->data, blob->size)) { + if (stbi_is_hdr_from_memory(blob->data, length)) { textureData->format = FORMAT_RGBA32F; - textureData->blob.data = stbi_loadf_from_memory(blob->data, blob->size, &textureData->width, &textureData->height, NULL, 4); + textureData->blob.data = stbi_loadf_from_memory(blob->data, length, &textureData->width, &textureData->height, NULL, 4); } else { textureData->format = FORMAT_RGBA; - textureData->blob.data = stbi_load_from_memory(blob->data, blob->size, &textureData->width, &textureData->height, NULL, 4); + textureData->blob.data = stbi_load_from_memory(blob->data, length, &textureData->width, &textureData->height, NULL, 4); } if (!textureData->blob.data) { @@ -250,7 +251,7 @@ bool lovrTextureDataEncode(TextureData* textureData, const char* filename) { int width = textureData->width; int height = textureData->height; void* data = (uint8_t*) textureData->blob.data + (textureData->height - 1) * textureData->width * components; - size_t stride = -textureData->width * components; + int stride = -textureData->width * components; bool success = stbi_write_png_to_func(writeCallback, &file, width, height, components, data, stride); lovrFileDestroy(&file); return success; diff --git a/src/data/textureData.h b/src/data/textureData.h index 62c596c7..2ee7c973 100644 --- a/src/data/textureData.h +++ b/src/data/textureData.h @@ -31,7 +31,7 @@ typedef struct { int width; int height; void* data; - size_t size; + int size; } Mipmap; typedef vec_t(Mipmap) vec_mipmap_t; diff --git a/src/filesystem/filesystem.c b/src/filesystem/filesystem.c index facf35d9..aa23f8be 100644 --- a/src/filesystem/filesystem.c +++ b/src/filesystem/filesystem.c @@ -118,7 +118,7 @@ int lovrFilesystemGetAppdataDirectory(char* dest, unsigned int size) { } void lovrFilesystemGetDirectoryItems(const char* path, getDirectoryItemsCallback callback, void* userdata) { - PHYSFS_enumerate(path, callback, userdata); + PHYSFS_enumerate(path, (PHYSFS_EnumerateCallback) callback, userdata); } int lovrFilesystemGetExecutablePath(char* path, uint32_t size) { diff --git a/src/filesystem/filesystem.h b/src/filesystem/filesystem.h index bd3fe768..a268241b 100644 --- a/src/filesystem/filesystem.h +++ b/src/filesystem/filesystem.h @@ -9,7 +9,7 @@ extern const char lovrDirSep; -typedef int getDirectoryItemsCallback(void* userdata, const char* dir, const char* file); +typedef int (*getDirectoryItemsCallback)(void* userdata, const char* dir, const char* file); typedef struct { bool initialized; diff --git a/src/graphics/buffer.c b/src/graphics/buffer.c index c2fad9bd..ed8abc3b 100644 --- a/src/graphics/buffer.c +++ b/src/graphics/buffer.c @@ -25,5 +25,5 @@ void lovrBufferFlush(Buffer* buffer) { lovrBufferFlushRange(buffer, buffer->flushFrom, buffer->flushTo - buffer->flushFrom); buffer->flushFrom = SIZE_MAX; - buffer->flushTo = -SIZE_MAX; + buffer->flushTo = 0; } diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index c3732256..c5ae59ee 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -8,7 +8,6 @@ #include "lib/stb/stb_image.h" #include #include -#define _USE_MATH_DEFINES #include static GraphicsState state; @@ -21,7 +20,7 @@ static void gammaCorrectColor(Color* color) { } } -static void onCloseWindow() { +static void onCloseWindow(void) { lovrEventPush((Event) { .type = EVENT_QUIT, .data.quit = { false, 0 } }); } @@ -30,7 +29,7 @@ static void onResizeWindow(int width, int height) { state.height = height; } -static const size_t BUFFER_COUNTS[] = { +static const uint32_t BUFFER_COUNTS[] = { [STREAM_VERTEX] = (1 << 16) - 1, [STREAM_INDEX] = 1 << 16, [STREAM_DRAW_ID] = (1 << 16) - 1, @@ -61,7 +60,7 @@ static void lovrGraphicsInitBuffers() { } // Compute the max number of draws per batch, since the hard cap of 256 won't always fit in a UBO - size_t maxBlockSize = lovrGpuGetLimits()->blockSize; + int maxBlockSize = lovrGpuGetLimits()->blockSize; state.maxDraws = MIN(maxBlockSize / sizeof(DrawData) / 64 * 64, 256); // The identity buffer is used for autoinstanced meshes and instanced primitives and maps the @@ -95,7 +94,7 @@ static void lovrGraphicsInitBuffers() { static void* lovrGraphicsMapBuffer(BufferRole role, uint32_t count) { Buffer* buffer = state.buffers[role]; - size_t limit = BUFFER_COUNTS[role]; + uint32_t limit = BUFFER_COUNTS[role]; lovrAssert(count <= limit, "Whoa there! Tried to get %d elements from a buffer that only has %d elements.", count, limit); if (state.cursors[role] + count > limit) { @@ -239,8 +238,8 @@ void lovrGraphicsSetCamera(Camera* camera, bool clear) { memset(&state.camera, 0, sizeof(Camera)); mat4_identity(state.camera.viewMatrix[0]); mat4_identity(state.camera.viewMatrix[1]); - mat4_perspective(state.camera.projection[0], .01f, 100.f, 67. * M_PI / 180., (float) state.width / state.height); - mat4_perspective(state.camera.projection[1], .01f, 100.f, 67. * M_PI / 180., (float) state.width / state.height); + mat4_perspective(state.camera.projection[0], .01f, 100.f, 67.f * M_PI / 180.f, (float) state.width / state.height); + mat4_perspective(state.camera.projection[1], .01f, 100.f, 67.f * M_PI / 180.f, (float) state.width / state.height); } else { state.camera = *camera; } @@ -496,7 +495,7 @@ void lovrGraphicsBatch(BatchRequest* req) { if (req->type == BATCH_MESH) { float* pose = req->params.mesh.pose ? req->params.mesh.pose : (float[]) MAT4_IDENTITY; - size_t count = req->params.mesh.pose ? (MAX_BONES * 16) : 16; + int count = req->params.mesh.pose ? (MAX_BONES * 16) : 16; lovrShaderSetMatrices(shader, "lovrPose", pose, 0, count); } @@ -537,7 +536,7 @@ void lovrGraphicsBatch(BatchRequest* req) { for (int i = 0; i < MAX_BUFFER_ROLES; i++) { if (streamRequirements[i] > 0 && state.cursors[i] + streamRequirements[i] > BUFFER_COUNTS[i]) { - size_t oldCursor = state.cursors[i]; + uint32_t oldCursor = state.cursors[i]; lovrGraphicsFlush(); state.locks[i][MAX_LOCKS - 1] = lovrGpuLock(); state.cursors[i] = state.cursors[i] >= oldCursor ? 0 : state.cursors[i]; @@ -821,9 +820,9 @@ void lovrGraphicsFlush() { if (batch->vertexCount > 0) { size_t lockSize = BUFFER_COUNTS[STREAM_VERTEX] / MAX_LOCKS + 1; - int firstLock = batch->vertexStart / lockSize; - int lastLock = (batch->vertexStart + batch->vertexCount) / lockSize; - for (int i = firstLock; i < lastLock; i++) { + size_t firstLock = batch->vertexStart / lockSize; + size_t lastLock = (batch->vertexStart + batch->vertexCount) / lockSize; + for (size_t i = firstLock; i < lastLock; i++) { state.locks[STREAM_VERTEX][i] = lovrGpuLock(); if (!instanced) { state.locks[STREAM_DRAW_ID][i] = lovrGpuLock(); @@ -833,18 +832,18 @@ void lovrGraphicsFlush() { if (batch->indexCount > 0) { size_t lockSize = BUFFER_COUNTS[STREAM_INDEX] / MAX_LOCKS + 1; - int firstLock = batch->indexStart / lockSize; - int lastLock = (batch->indexStart + batch->indexCount) / lockSize; - for (int i = firstLock; i < lastLock; i++) { + size_t firstLock = batch->indexStart / lockSize; + size_t lastLock = (batch->indexStart + batch->indexCount) / lockSize; + for (size_t i = firstLock; i < lastLock; i++) { state.locks[STREAM_INDEX][i] = lovrGpuLock(); } } if (batch->drawCount > 0) { size_t lockSize = BUFFER_COUNTS[STREAM_DRAW_DATA] / MAX_LOCKS; - int firstLock = batch->drawStart / lockSize; - int lastLock = MIN(batch->drawStart + state.maxDraws, BUFFER_COUNTS[STREAM_DRAW_DATA] - 1) / lockSize; - for (int i = firstLock; i < lastLock; i++) { + size_t firstLock = batch->drawStart / lockSize; + size_t lastLock = MIN(batch->drawStart + state.maxDraws, BUFFER_COUNTS[STREAM_DRAW_DATA] - 1) / lockSize; + for (size_t i = firstLock; i < lastLock; i++) { state.locks[STREAM_DRAW_DATA][i] = lovrGpuLock(); } } diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 20f2bb39..a14afeab 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -185,7 +185,7 @@ typedef struct { Mesh* instancedMesh; Buffer* identityBuffer; Buffer* buffers[MAX_BUFFER_ROLES]; - size_t cursors[MAX_BUFFER_ROLES]; + uint32_t cursors[MAX_BUFFER_ROLES]; void* locks[MAX_BUFFER_ROLES][MAX_LOCKS]; Batch cachedGeometry; Batch batches[MAX_BATCHES]; diff --git a/src/graphics/shader.c b/src/graphics/shader.c index 59be8d3f..a18e3ef0 100644 --- a/src/graphics/shader.c +++ b/src/graphics/shader.c @@ -163,7 +163,7 @@ size_t lovrShaderComputeUniformLayout(vec_uniform_t* uniforms) { size_t size = 0; Uniform* uniform; int i; vec_foreach_ptr(uniforms, uniform, i) { - size_t align; + int align; if (uniform->count > 1 || uniform->type == UNIFORM_MATRIX) { align = 16 * (uniform->type == UNIFORM_MATRIX ? uniform->components : 1); uniform->size = align * uniform->count; diff --git a/src/headset/desktop.c b/src/headset/desktop.c index 7cfa5e75..ff8437e4 100644 --- a/src/headset/desktop.c +++ b/src/headset/desktop.c @@ -2,7 +2,6 @@ #include "graphics/graphics.h" #include "lib/math.h" #include "platform.h" -#define _USE_MATH_DEFINES #include #include #include @@ -58,7 +57,7 @@ static bool desktopInit(float offset, int msaa) { return true; } -static void desktopDestroy() { +static void desktopDestroy(void) { Controller *controller; int i; vec_foreach(&state.controllers, controller, i) { lovrRelease(controller); @@ -67,15 +66,15 @@ static void desktopDestroy() { memset(&state, 0, sizeof(state)); } -static HeadsetType desktopGetType() { +static HeadsetType desktopGetType(void) { return HEADSET_UNKNOWN; } -static HeadsetOrigin desktopGetOriginType() { +static HeadsetOrigin desktopGetOriginType(void) { return ORIGIN_HEAD; } -static bool desktopIsMounted() { +static bool desktopIsMounted(void) { return true; } @@ -181,7 +180,7 @@ static void desktopRenderTo(void (*callback)(void*), void* userdata) { uint32_t width, height; desktopGetDisplayDimensions(&width, &height); Camera camera = { .canvas = NULL, .viewMatrix = { MAT4_IDENTITY }, .stereo = true }; - mat4_perspective(camera.projection[0], state.clipNear, state.clipFar, 67 * M_PI / 180., (float) width / 2.f / height); + mat4_perspective(camera.projection[0], state.clipNear, state.clipFar, 67.f * M_PI / 180.f, (float) width / 2.f / height); mat4_multiply(camera.viewMatrix[0], state.transform); mat4_invertPose(camera.viewMatrix[0]); mat4_set(camera.projection[1], camera.projection[0]); diff --git a/src/headset/openvr.c b/src/headset/openvr.c index e1f8fa67..f25aebe5 100644 --- a/src/headset/openvr.c +++ b/src/headset/openvr.c @@ -10,6 +10,8 @@ #include #ifndef WIN32 #pragma pack(push, 4) +#else +#undef EXTERN_C #endif #include #ifndef WIN32 @@ -177,7 +179,7 @@ static bool openvrInit(float offset, int msaa) { return true; } -static void openvrDestroy() { +static void openvrDestroy(void) { lovrRelease(state.canvas); for (int i = 0; i < 16; i++) { if (state.deviceModels[i]) { @@ -199,11 +201,11 @@ static void openvrDestroy() { memset(&state, 0, sizeof(HeadsetState)); } -static HeadsetType openvrGetType() { +static HeadsetType openvrGetType(void) { return state.type; } -static HeadsetOrigin openvrGetOriginType() { +static HeadsetOrigin openvrGetOriginType(void) { switch (state.compositor->GetTrackingSpace()) { case ETrackingUniverseOrigin_TrackingUniverseSeated: return ORIGIN_HEAD; case ETrackingUniverseOrigin_TrackingUniverseStanding: return ORIGIN_FLOOR; @@ -211,7 +213,7 @@ static HeadsetOrigin openvrGetOriginType() { } } -static bool openvrIsMounted() { +static bool openvrIsMounted(void) { VRControllerState_t input; state.system->GetControllerState(HEADSET_INDEX, &input, sizeof(input)); return (input.ulButtonPressed >> EVRButtonId_k_EButton_ProximitySensor) & 1; @@ -592,7 +594,7 @@ static void openvrUpdate(float dt) { } } -static Texture* openvrGetMirrorTexture() { +static Texture* openvrGetMirrorTexture(void) { return lovrCanvasGetAttachments(state.canvas, NULL)[0].texture; } diff --git a/src/lib/lua-cjson/lua_cjson.c b/src/lib/lua-cjson/lua_cjson.c index 61fdf1cb..75c7e950 100644 --- a/src/lib/lua-cjson/lua_cjson.c +++ b/src/lib/lua-cjson/lua_cjson.c @@ -481,7 +481,7 @@ static void json_append_string(lua_State *l, strbuf_t *json, int lindex) * This buffer is reused constantly for small strings * If there are any excess pages, they won't be hit anyway. * This gains ~5% speedup. */ - strbuf_ensure_empty_length(json, len * 6 + 2); + strbuf_ensure_empty_length(json, (int) (len * 6 + 2)); strbuf_append_char_unsafe(json, '\"'); for (i = 0; i < len; i++) { @@ -1290,7 +1290,7 @@ static int json_decode(lua_State *l) /* Ensure the temporary buffer can hold the entire string. * This means we no longer need to do length checks since the decoded * string must be smaller than the entire json string */ - json.tmp = strbuf_new(json_len); + json.tmp = strbuf_new((int) json_len); json_next_token(&json, &token); json_process_value(l, &json, &token); diff --git a/src/lib/lua-cjson/strbuf.c b/src/lib/lua-cjson/strbuf.c index ac779e4a..c3272f09 100644 --- a/src/lib/lua-cjson/strbuf.c +++ b/src/lib/lua-cjson/strbuf.c @@ -94,8 +94,8 @@ void strbuf_set_increment(strbuf_t *s, int increment) static inline void debug_stats(strbuf_t *s) { if (s->debug) { - fprintf(stderr, "strbuf(%lx) reallocs: %d, length: %d, size: %d\n", - (long)s, s->reallocs, s->length, s->size); + fprintf(stderr, "strbuf(%p) reallocs: %d, length: %d, size: %d\n", + s, s->reallocs, s->length, s->size); } } @@ -168,8 +168,8 @@ void strbuf_resize(strbuf_t *s, int len) newsize = calculate_new_size(s, len); if (s->debug > 1) { - fprintf(stderr, "strbuf(%lx) resize: %d => %d\n", - (long)s, s->size, newsize); + fprintf(stderr, "strbuf(%p) resize: %d => %d\n", + s, s->size, newsize); } s->size = newsize; diff --git a/src/lib/map/map.c b/src/lib/map/map.c index 308ccad0..c8d83a97 100644 --- a/src/lib/map/map.c +++ b/src/lib/map/map.c @@ -29,7 +29,7 @@ static unsigned map_hash(const char *str) { static map_node_t *map_newnode(const char *key, void *value, int vsize) { map_node_t *node; - int ksize = strlen(key) + 1; + int ksize = (int) strlen(key) + 1; int voffset = ksize + ((sizeof(void*) - ksize) % sizeof(void*)); node = malloc(sizeof(*node) + voffset + vsize); if (!node) return NULL; diff --git a/src/lib/math.c b/src/lib/math.c index 44e12a88..fcf7a616 100644 --- a/src/lib/math.c +++ b/src/lib/math.c @@ -1,5 +1,4 @@ #include "math.h" -#define _USE_MATH_DEFINES #include #include #ifdef LOVR_USE_SSE diff --git a/src/lib/sds/sds.c b/src/lib/sds/sds.c index a1b837c7..8b904959 100644 --- a/src/lib/sds/sds.c +++ b/src/lib/sds/sds.c @@ -107,34 +107,34 @@ sds sdsnewlen(const void *init, size_t initlen) { fp = ((unsigned char*)s)-1; switch(type) { case SDS_TYPE_5: { - *fp = type | (initlen << SDS_TYPE_BITS); + *fp = (unsigned char) (type | (initlen << SDS_TYPE_BITS)); break; } case SDS_TYPE_8: { SDS_HDR_VAR(8,s); - sh->len = initlen; - sh->alloc = initlen; + sh->len = (uint8_t) initlen; + sh->alloc = (uint8_t) initlen; *fp = type; break; } case SDS_TYPE_16: { SDS_HDR_VAR(16,s); - sh->len = initlen; - sh->alloc = initlen; + sh->len = (uint16_t) initlen; + sh->alloc = (uint16_t) initlen; *fp = type; break; } case SDS_TYPE_32: { SDS_HDR_VAR(32,s); - sh->len = initlen; - sh->alloc = initlen; + sh->len = (uint32_t) initlen; + sh->alloc = (uint32_t) initlen; *fp = type; break; } case SDS_TYPE_64: { SDS_HDR_VAR(64,s); - sh->len = initlen; - sh->alloc = initlen; + sh->len = (uint64_t) initlen; + sh->alloc = (uint64_t) initlen; *fp = type; break; } @@ -472,7 +472,7 @@ int sdsll2str(char *s, long long value) { s++; p--; } - return l; + return (int) l; } /* Identical sdsll2str(), but for unsigned long long type. */ @@ -501,7 +501,7 @@ int sdsull2str(char *s, unsigned long long v) { s++; p--; } - return l; + return (int) l; } /* Create an sds string from a long long value. It is much faster than: @@ -602,7 +602,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) { va_start(ap,fmt); f = fmt; /* Next format specifier byte to process. */ - i = initlen; /* Position of the next byte to write to dest str. */ + i = (long) initlen; /* Position of the next byte to write to dest str. */ while(*f) { char next, *str; size_t l; @@ -628,7 +628,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) { } memcpy(s+i,str,l); sdsinclen(s,l); - i += l; + i += (long) l; break; case 'i': case 'I': @@ -644,7 +644,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) { } memcpy(s+i,buf,l); sdsinclen(s,l); - i += l; + i += (long) l; } break; case 'u': @@ -661,7 +661,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) { } memcpy(s+i,buf,l); sdsinclen(s,l); - i += l; + i += (long) l; } break; default: /* Handle %% and generally %. */ diff --git a/src/lib/sds/sds.h b/src/lib/sds/sds.h index f2f6fb97..18209eee 100644 --- a/src/lib/sds/sds.h +++ b/src/lib/sds/sds.h @@ -149,20 +149,20 @@ static inline void sdssetlen(sds s, size_t newlen) { case SDS_TYPE_5: { unsigned char *fp = ((unsigned char*)s)-1; - *fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS); + *fp = (unsigned char) (SDS_TYPE_5 | (newlen << SDS_TYPE_BITS)); } break; case SDS_TYPE_8: - SDS_HDR(8,s)->len = newlen; + SDS_HDR(8,s)->len = (uint8_t) newlen; break; case SDS_TYPE_16: - SDS_HDR(16,s)->len = newlen; + SDS_HDR(16,s)->len = (uint16_t) newlen; break; case SDS_TYPE_32: - SDS_HDR(32,s)->len = newlen; + SDS_HDR(32,s)->len = (uint32_t) newlen; break; case SDS_TYPE_64: - SDS_HDR(64,s)->len = newlen; + SDS_HDR(64,s)->len = (uint64_t) newlen; break; } } @@ -173,21 +173,21 @@ static inline void sdsinclen(sds s, size_t inc) { case SDS_TYPE_5: { unsigned char *fp = ((unsigned char*)s)-1; - unsigned char newlen = SDS_TYPE_5_LEN(flags)+inc; - *fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS); + unsigned char newlen = (unsigned char) (SDS_TYPE_5_LEN(flags)+inc); + *fp = (unsigned char) (SDS_TYPE_5 | (newlen << SDS_TYPE_BITS)); } break; case SDS_TYPE_8: - SDS_HDR(8,s)->len += inc; + SDS_HDR(8,s)->len += (uint8_t) inc; break; case SDS_TYPE_16: - SDS_HDR(16,s)->len += inc; + SDS_HDR(16,s)->len += (uint16_t) inc; break; case SDS_TYPE_32: - SDS_HDR(32,s)->len += inc; + SDS_HDR(32,s)->len += (uint32_t) inc; break; case SDS_TYPE_64: - SDS_HDR(64,s)->len += inc; + SDS_HDR(64,s)->len += (uint64_t) inc; break; } } @@ -217,16 +217,16 @@ static inline void sdssetalloc(sds s, size_t newlen) { /* Nothing to do, this type has no total allocation info. */ break; case SDS_TYPE_8: - SDS_HDR(8,s)->alloc = newlen; + SDS_HDR(8,s)->alloc = (uint8_t) newlen; break; case SDS_TYPE_16: - SDS_HDR(16,s)->alloc = newlen; + SDS_HDR(16,s)->alloc = (uint16_t) newlen; break; case SDS_TYPE_32: - SDS_HDR(32,s)->alloc = newlen; + SDS_HDR(32,s)->alloc = (uint32_t) newlen; break; case SDS_TYPE_64: - SDS_HDR(64,s)->alloc = newlen; + SDS_HDR(64,s)->alloc = (uint64_t) newlen; break; } } diff --git a/src/luax.c b/src/luax.c index ab74dd1b..3191458e 100644 --- a/src/luax.c +++ b/src/luax.c @@ -18,7 +18,7 @@ static int luax_meta__gc(lua_State* L) { static int luax_module__gc(lua_State* L) { lua_getfield(L, LUA_REGISTRYINDEX, "_lovrmodules"); - for (int i = lua_objlen(L, 2); i >= 1; i--) { + for (int i = luax_len(L, 2); i >= 1; i--) { lua_rawgeti(L, 2, i); luax_destructor destructor = (luax_destructor) lua_touserdata(L, -1); destructor(); @@ -80,7 +80,7 @@ void luax_atexit(lua_State* L, luax_destructor destructor) { lua_setfield(L, LUA_REGISTRYINDEX, "_lovrmodules"); } - int length = lua_objlen(L, -1); + int length = luax_len(L, -1); lua_pushlightuserdata(L, (void*) destructor); lua_rawseti(L, -2, length + 1); lua_pop(L, 1); diff --git a/src/luax.h b/src/luax.h index bf6a047f..96a697ec 100644 --- a/src/luax.h +++ b/src/luax.h @@ -10,6 +10,7 @@ #define LUA_RIDX_MAINTHREAD 1 #endif +#define luax_len(L, i) (int) lua_objlen(L, i) #define luax_totype(L, i, T) ((T*) _luax_totype(L, i, #T)) #define luax_checktype(L, i, T) ((T*) _luax_checktype(L, i, #T)) #define luax_checkfloat(L, i) (float) luaL_checknumber(L, i) diff --git a/src/math/randomGenerator.c b/src/math/randomGenerator.c index 06af328d..9784c60b 100644 --- a/src/math/randomGenerator.c +++ b/src/math/randomGenerator.c @@ -1,5 +1,4 @@ #include "math/randomGenerator.h" -#define _USE_MATH_DEFINES #include #include #include diff --git a/src/platform/glfw.h b/src/platform/glfw.h index 88c04d3d..7efd08a1 100644 --- a/src/platform/glfw.h +++ b/src/platform/glfw.h @@ -38,6 +38,7 @@ static int convertMouseButton(MouseButton button) { switch (button) { case MOUSE_LEFT: return GLFW_MOUSE_BUTTON_LEFT; case MOUSE_RIGHT: return GLFW_MOUSE_BUTTON_RIGHT; + default: lovrThrow("Unreachable"); } } @@ -53,6 +54,7 @@ static int convertKeyCode(KeyCode key) { case KEY_DOWN: return GLFW_KEY_DOWN; case KEY_LEFT: return GLFW_KEY_LEFT; case KEY_RIGHT: return GLFW_KEY_RIGHT; + default: lovrThrow("Unreachable"); } } diff --git a/src/util.h b/src/util.h index 852fe643..716bea74 100644 --- a/src/util.h +++ b/src/util.h @@ -36,6 +36,10 @@ #define CLAMP(x, min, max) MAX(min, MIN(max, x)) #define ALIGN(p, n) ((uintptr_t) p & -n) +#ifndef M_PI +#define M_PI 3.14159265358979323846264f +#endif + typedef struct ref { void (*destructor)(void*); const char* type;