Fix MSVC warnings;

This commit is contained in:
bjorn 2019-03-17 00:58:01 -07:00
parent a9ca346ee1
commit 85c51399a6
41 changed files with 153 additions and 147 deletions

View File

@ -517,6 +517,7 @@ if(WIN32)
set_target_properties(lovr PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") set_target_properties(lovr PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
set_target_properties(lovr PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") 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_SECURE_NO_WARNINGS)
target_compile_definitions(lovr PUBLIC -D_CRT_NONSTDC_NO_WARNINGS)
if(MSVC_VERSION VERSION_LESS 1900) if(MSVC_VERSION VERSION_LESS 1900)
target_compile_definitions(lovr PUBLIC -Dinline=__inline -Dsnprintf=_snprintf) target_compile_definitions(lovr PUBLIC -Dinline=__inline -Dsnprintf=_snprintf)

View File

@ -37,7 +37,7 @@ static int l_lovrDataNewBlob(lua_State* L) {
static int l_lovrDataNewAudioStream(lua_State* L) { static int l_lovrDataNewAudioStream(lua_State* L) {
Blob* blob = luax_readblob(L, 1, "AudioStream"); 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); AudioStream* stream = lovrAudioStreamCreate(blob, bufferSize);
luax_pushobject(L, stream); luax_pushobject(L, stream);
lovrRelease(blob); lovrRelease(blob);

View File

@ -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) { static int pushDirectoryItem(void* userdata, const char* path, const char* filename) {
lua_State* L = userdata; lua_State* L = userdata;
int n = lua_objlen(L, -1); int n = luax_len(L, -1);
lua_pushstring(L, filename); lua_pushstring(L, filename);
lua_rawseti(L, -2, n + 1); lua_rawseti(L, -2, n + 1);
return 1; return 1;

View File

@ -13,7 +13,6 @@
#include "data/textureData.h" #include "data/textureData.h"
#include "filesystem/filesystem.h" #include "filesystem/filesystem.h"
#include "util.h" #include "util.h"
#define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
@ -205,7 +204,7 @@ const char* WrapModes[] = {
static uint32_t luax_getvertexcount(lua_State* L, int index) { static uint32_t luax_getvertexcount(lua_State* L, int index) {
int type = lua_type(L, index); int type = lua_type(L, index);
if (type == LUA_TTABLE) { if (type == LUA_TTABLE) {
size_t count = lua_objlen(L, index); int count = luax_len(L, index);
lua_rawgeti(L, index, 1); lua_rawgeti(L, index, 1);
int tableType = lua_type(L, -1); int tableType = lua_type(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
@ -1138,14 +1137,14 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
} else if (lua_istable(L, 2)) { } else if (lua_istable(L, 2)) {
drawModeIndex++; drawModeIndex++;
formatIndex = 1; formatIndex = 1;
count = lua_objlen(L, 2); count = luax_len(L, 2);
dataIndex = 2; dataIndex = 2;
} else if ((blob = luax_totype(L, 2, Blob)) != NULL) { } else if ((blob = luax_totype(L, 2, Blob)) != NULL) {
drawModeIndex++; drawModeIndex++;
formatIndex = 1; formatIndex = 1;
dataIndex = 2; dataIndex = 2;
} else { } else {
count = lua_objlen(L, 1); count = luax_len(L, 1);
dataIndex = 1; dataIndex = 1;
} }
} else { } else {
@ -1168,7 +1167,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
attributeNames[1] = "lovrNormal"; attributeNames[1] = "lovrNormal";
attributeNames[2] = "lovrTexCoord"; attributeNames[2] = "lovrTexCoord";
} else { } 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); lovrAssert(attributeCount >= 0 && attributeCount <= MAX_ATTRIBUTES, "Attribute count must be between 0 and %d", MAX_ATTRIBUTES);
for (int i = 0; i < attributeCount; i++) { for (int i = 0; i < attributeCount; i++) {
lua_rawgeti(L, formatIndex, i + 1); lua_rawgeti(L, formatIndex, i + 1);
@ -1178,7 +1177,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
lua_rawgeti(L, -3, 1); lua_rawgeti(L, -3, 1);
attributeNames[i] = lua_tostring(L, -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].type = luaL_checkoption(L, -2, "float", AttributeTypes);
attributes[i].components = luaL_optinteger(L, -3, 1); attributes[i].components = luaL_optinteger(L, -3, 1);
@ -1192,7 +1191,8 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
} }
if (blob) { 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); DrawMode mode = luaL_checkoption(L, drawModeIndex, "fan", DrawModes);
@ -1232,7 +1232,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
int component = 0; int component = 0;
for (int j = 0; j < attributeCount; j++) { for (int j = 0; j < attributeCount; j++) {
MeshAttribute* attribute = &attributes[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); lua_rawgeti(L, -1, ++component);
switch (attribute->type) { switch (attribute->type) {
case I8: *data.i8++ = luaL_optinteger(L, -1, 0); break; case I8: *data.i8++ = luaL_optinteger(L, -1, 0); break;
@ -1341,7 +1341,7 @@ static int l_lovrGraphicsNewTexture(lua_State* L) {
depth = 1; depth = 1;
index++; index++;
} else { } else {
depth = lua_objlen(L, index++); depth = luax_len(L, index++);
type = depth > 0 ? TEXTURE_ARRAY : TEXTURE_CUBE; type = depth > 0 ? TEXTURE_ARRAY : TEXTURE_CUBE;
} }

View File

@ -345,7 +345,7 @@ int luaopen_lovr_headset(lua_State* L) {
// Drivers // Drivers
lua_getfield(L, -1, "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++) { for (int i = 0; i < n; i++) {
lua_rawgeti(L, -1, i + 1); lua_rawgeti(L, -1, i + 1);
vec_push(&drivers, luaL_checkoption(L, -1, NULL, HeadsetDrivers)); vec_push(&drivers, luaL_checkoption(L, -1, NULL, HeadsetDrivers));

View File

@ -82,7 +82,7 @@ static int l_lovrMathNewCurve(lua_State* L) {
if (lua_istable(L, 1)) { if (lua_istable(L, 1)) {
int pointIndex = 0; int pointIndex = 0;
int length = lua_objlen(L, 1); int length = luax_len(L, 1);
for (int i = 1; i <= length;) { for (int i = 1; i <= length;) {
lua_rawgeti(L, 1, i + 0); lua_rawgeti(L, 1, i + 0);
lua_rawgeti(L, 1, i + 1); lua_rawgeti(L, 1, i + 1);

View File

@ -25,7 +25,7 @@ static int l_lovrPhysicsNewWorld(lua_State* L) {
const char* tags[16]; const char* tags[16];
int tagCount; int tagCount;
if (lua_type(L, 5) == LUA_TTABLE) { if (lua_type(L, 5) == LUA_TTABLE) {
tagCount = lua_objlen(L, 5); tagCount = luax_len(L, 5);
for (int i = 0; i < tagCount; i++) { for (int i = 0; i < tagCount; i++) {
lua_rawgeti(L, -1, i + 1); lua_rawgeti(L, -1, i + 1);
if (lua_isstring(L, -1)) { if (lua_isstring(L, -1)) {

View File

@ -42,7 +42,7 @@ void luax_readattachments(lua_State* L, int index, Attachment* attachments, int*
int n; int n;
if (lua_istable(L, index)) { if (lua_istable(L, index)) {
n = lua_objlen(L, index); n = luax_len(L, index);
n = MIN(n, 3 * MAX_CANVAS_ATTACHMENTS); n = MIN(n, 3 * MAX_CANVAS_ATTACHMENTS);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
lua_rawgeti(L, index, i + 1); lua_rawgeti(L, index, i + 1);

View File

@ -53,16 +53,16 @@ static int l_lovrColliderGetJoints(lua_State* L) {
static int l_lovrColliderGetUserData(lua_State* L) { static int l_lovrColliderGetUserData(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider); Collider* collider = luax_checktype(L, 1, Collider);
int ref = (int) lovrColliderGetUserData(collider); union { int i; void* p; } ref = { .p = lovrColliderGetUserData(collider) };
lua_rawgeti(L, LUA_REGISTRYINDEX, ref); lua_rawgeti(L, LUA_REGISTRYINDEX, ref.i);
return 1; return 1;
} }
static int l_lovrColliderSetUserData(lua_State* L) { static int l_lovrColliderSetUserData(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider); Collider* collider = luax_checktype(L, 1, Collider);
uint64_t ref = (int) lovrColliderGetUserData(collider); union { int i; void* p; } ref = { .p = lovrColliderGetUserData(collider) };
if (ref) { if (ref.i) {
luaL_unref(L, LUA_REGISTRYINDEX, ref); luaL_unref(L, LUA_REGISTRYINDEX, ref.i);
} }
if (lua_gettop(L) < 2) { if (lua_gettop(L) < 2) {
@ -70,8 +70,8 @@ static int l_lovrColliderSetUserData(lua_State* L) {
} }
lua_settop(L, 2); lua_settop(L, 2);
ref = luaL_ref(L, LUA_REGISTRYINDEX); ref.i = luaL_ref(L, LUA_REGISTRYINDEX);
lovrColliderSetUserData(collider, (void*) ref); lovrColliderSetUserData(collider, ref.p);
return 0; return 0;
} }
@ -164,7 +164,7 @@ static int l_lovrColliderSetMassData(lua_State* L) {
float cz = luax_checkfloat(L, 4); float cz = luax_checkfloat(L, 4);
float mass = luax_checkfloat(L, 5); float mass = luax_checkfloat(L, 5);
float inertia[6]; 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++) { for (int i = 0; i < 6; i++) {
lua_rawgeti(L, 6, i + 1); lua_rawgeti(L, 6, i + 1);
if (!lua_isnumber(L, -1)) { if (!lua_isnumber(L, -1)) {

View File

@ -25,16 +25,16 @@ static int l_lovrJointGetColliders(lua_State* L) {
static int l_lovrJointGetUserData(lua_State* L) { static int l_lovrJointGetUserData(lua_State* L) {
Joint* joint = luax_checktype(L, 1, Joint); Joint* joint = luax_checktype(L, 1, Joint);
int ref = (int) lovrJointGetUserData(joint); union { int i; void* p; } ref = { .p = lovrJointGetUserData(joint) };
lua_rawgeti(L, LUA_REGISTRYINDEX, ref); lua_rawgeti(L, LUA_REGISTRYINDEX, ref.i);
return 1; return 1;
} }
static int l_lovrJointSetUserData(lua_State* L) { static int l_lovrJointSetUserData(lua_State* L) {
Joint* joint = luax_checktype(L, 1, Joint); Joint* joint = luax_checktype(L, 1, Joint);
uint64_t ref = (int) lovrJointGetUserData(joint); union { int i; void* p; } ref = { .p = lovrJointGetUserData(joint) };
if (ref) { if (ref.i) {
luaL_unref(L, LUA_REGISTRYINDEX, ref); luaL_unref(L, LUA_REGISTRYINDEX, ref.i);
} }
if (lua_gettop(L) < 2) { if (lua_gettop(L) < 2) {
@ -42,8 +42,8 @@ static int l_lovrJointSetUserData(lua_State* L) {
} }
lua_settop(L, 2); lua_settop(L, 2);
ref = luaL_ref(L, LUA_REGISTRYINDEX); ref.i = luaL_ref(L, LUA_REGISTRYINDEX);
lovrJointSetUserData(joint, (void*) ref); lovrJointSetUserData(joint, ref.p);
return 0; return 0;
} }

View File

@ -18,7 +18,7 @@ static int l_lovrMeshAttachAttributes(lua_State* L) {
lovrMeshAttachAttribute(mesh, other->attributeNames[i], &attachment); lovrMeshAttachAttribute(mesh, other->attributeNames[i], &attachment);
} }
} else if (lua_istable(L, 4)) { } 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++) { for (int i = 0; i < length; i++) {
lua_rawgeti(L, 4, i + 1); lua_rawgeti(L, 4, i + 1);
const char* name = lua_tostring(L, -1); const char* name = lua_tostring(L, -1);
@ -56,7 +56,7 @@ static int l_lovrMeshDetachAttributes(lua_State* L) {
lovrMeshDetachAttribute(mesh, other->attributeNames[i]); lovrMeshDetachAttribute(mesh, other->attributeNames[i]);
} }
} else if (lua_istable(L, 2)) { } 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++) { for (int i = 0; i < length; i++) {
lua_rawgeti(L, 2, i + 1); lua_rawgeti(L, 2, i + 1);
lovrMeshDetachAttribute(mesh, lua_tostring(L, -1)); lovrMeshDetachAttribute(mesh, lua_tostring(L, -1));
@ -152,7 +152,7 @@ static int l_lovrMeshGetVertex(lua_State* L) {
if (attribute->buffer != mesh->vertexBuffer) { if (attribute->buffer != mesh->vertexBuffer) {
break; break;
} }
for (int j = 0; j < attribute->components; j++, components++) { for (unsigned j = 0; j < attribute->components; j++, components++) {
switch (attribute->type) { switch (attribute->type) {
case I8: lua_pushinteger(L, *data.i8++); break; case I8: lua_pushinteger(L, *data.i8++); break;
case U8: lua_pushinteger(L, *data.u8++); break; case U8: lua_pushinteger(L, *data.u8++); break;
@ -186,7 +186,7 @@ static int l_lovrMeshSetVertex(lua_State* L) {
break; break;
} }
for (int j = 0; j < attribute->components; j++) { for (unsigned j = 0; j < attribute->components; j++) {
int k = 3 + j; int k = 3 + j;
if (table) { if (table) {
lua_rawgeti(L, 3, ++component); 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); lovrAssert(mesh->attributes[attributeIndex].buffer == mesh->vertexBuffer, "Invalid mesh attribute: %d", attributeIndex + 1);
MeshAttribute* attribute = &mesh->attributes[attributeIndex]; MeshAttribute* attribute = &mesh->attributes[attributeIndex];
AttributeData data = { .raw = lovrBufferMap(buffer, vertexIndex * attribute->stride + attribute->offset) }; 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) { switch (attribute->type) {
case I8: lua_pushinteger(L, *data.i8++); break; case I8: lua_pushinteger(L, *data.i8++); break;
case U8: lua_pushinteger(L, *data.u8++); 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); lovrAssert(mesh->attributes[attributeIndex].buffer == mesh->vertexBuffer, "Invalid mesh attribute: %d", attributeIndex + 1);
MeshAttribute* attribute = &mesh->attributes[attributeIndex]; MeshAttribute* attribute = &mesh->attributes[attributeIndex];
AttributeData data = { .raw = lovrBufferMap(mesh->vertexBuffer, vertexIndex * attribute->stride + attribute->offset) }; 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; int index = 4 + i;
if (table) { if (table) {
lua_rawgeti(L, 4, i + 1); lua_rawgeti(L, 4, i + 1);
@ -276,7 +276,7 @@ static int l_lovrMeshSetVertices(lua_State* L) {
Mesh* mesh = luax_checktype(L, 1, Mesh); Mesh* mesh = luax_checktype(L, 1, Mesh);
uint32_t capacity = lovrMeshGetVertexCount(mesh); uint32_t capacity = lovrMeshGetVertexCount(mesh);
luaL_checktype(L, 2, LUA_TTABLE); 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 start = luaL_optinteger(L, 3, 1) - 1;
uint32_t count = luaL_optinteger(L, 4, sourceSize); uint32_t count = luaL_optinteger(L, 4, sourceSize);
lovrAssert(start + count <= capacity, "Overflow in Mesh:setVertices: Mesh can only hold %d vertices", capacity); 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; break;
} }
for (int k = 0; k < attribute->components; k++) { for (unsigned k = 0; k < attribute->components; k++) {
lua_rawgeti(L, -1, ++component); lua_rawgeti(L, -1, ++component);
switch (attribute->type) { switch (attribute->type) {
@ -348,7 +348,7 @@ static int l_lovrMeshGetVertexMap(lua_State* L) {
lua_createtable(L, count, 0); 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]; uint32_t index = size == sizeof(uint32_t) ? indices.ints[i] : indices.shorts[i];
lua_pushinteger(L, index + 1); lua_pushinteger(L, index + 1);
lua_rawseti(L, 2, i + 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); Blob* blob = luax_checktype(L, 2, Blob);
size_t size = luaL_optinteger(L, 3, 4); size_t size = luaL_optinteger(L, 3, 4);
lovrAssert(size == 2 || size == 4, "Size of Mesh indices should be 2 bytes or 4 bytes"); 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); Buffer* indexBuffer = lovrMeshGetIndexBuffer(mesh);
if (!indexBuffer || count * size > lovrBufferGetSize(indexBuffer)) { if (!indexBuffer || count * size > lovrBufferGetSize(indexBuffer)) {
Buffer* vertexBuffer = lovrMeshGetVertexBuffer(mesh); Buffer* vertexBuffer = lovrMeshGetVertexBuffer(mesh);
@ -384,7 +385,7 @@ static int l_lovrMeshSetVertexMap(lua_State* L) {
} }
} else { } else {
luaL_checktype(L, 2, LUA_TTABLE); 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); uint32_t vertexCount = lovrMeshGetVertexCount(mesh);
size_t size = vertexCount > USHRT_MAX ? sizeof(uint32_t) : sizeof(uint16_t); size_t size = vertexCount > USHRT_MAX ? sizeof(uint32_t) : sizeof(uint16_t);

View File

@ -49,7 +49,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des
if (components == 1) { if (components == 1) {
bool isTable = lua_istable(L, index); 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); length = MIN(length, count);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
int j = index + i; int j = index + i;
@ -95,7 +95,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des
} }
if (wrappedTable) { if (wrappedTable) {
int length = lua_objlen(L, index); int length = luax_len(L, index);
length = MIN(length, count); length = MIN(length, count);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
lua_rawgeti(L, index, i + 1); lua_rawgeti(L, index, i + 1);

View File

@ -34,16 +34,16 @@ static int l_lovrShapeSetEnabled(lua_State* L) {
static int l_lovrShapeGetUserData(lua_State* L) { static int l_lovrShapeGetUserData(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape); Shape* shape = luax_checktype(L, 1, Shape);
int ref = (int) lovrShapeGetUserData(shape); union { int i; void* p; } ref = { .p = lovrShapeGetUserData(shape) };
lua_rawgeti(L, LUA_REGISTRYINDEX, ref); lua_rawgeti(L, LUA_REGISTRYINDEX, ref.i);
return 1; return 1;
} }
static int l_lovrShapeSetUserData(lua_State* L) { static int l_lovrShapeSetUserData(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape); Shape* shape = luax_checktype(L, 1, Shape);
uint64_t ref = (int) lovrShapeGetUserData(shape); union { int i; void* p; } ref = { .p = lovrShapeGetUserData(shape) };
if (ref) { if (ref.i) {
luaL_unref(L, LUA_REGISTRYINDEX, ref); luaL_unref(L, LUA_REGISTRYINDEX, ref.i);
} }
if (lua_gettop(L) < 2) { if (lua_gettop(L) < 2) {
@ -51,8 +51,8 @@ static int l_lovrShapeSetUserData(lua_State* L) {
} }
lua_settop(L, 2); lua_settop(L, 2);
ref = luaL_ref(L, LUA_REGISTRYINDEX); ref.i = luaL_ref(L, LUA_REGISTRYINDEX);
lovrShapeSetUserData(shape, (void*) ref); lovrShapeSetUserData(shape, ref.p);
return 0; return 0;
} }

View File

@ -1,7 +1,6 @@
#include "audio/source.h" #include "audio/source.h"
#include "audio/audio.h" #include "audio/audio.h"
#include "data/audioStream.h" #include "data/audioStream.h"
#define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
@ -17,7 +16,7 @@ Source* lovrSourceInitStatic(Source* source, SoundData* soundData) {
source->soundData = soundData; source->soundData = soundData;
alGenSources(1, &source->id); alGenSources(1, &source->id);
alGenBuffers(1, source->buffers); 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]); alSourcei(source->id, AL_BUFFER, source->buffers[0]);
lovrRetain(soundData); lovrRetain(soundData);
return source; return source;

View File

@ -3,8 +3,8 @@
#include "util.h" #include "util.h"
#include <stdlib.h> #include <stdlib.h>
AudioStream* lovrAudioStreamInit(AudioStream* stream, Blob* blob, size_t bufferSize) { AudioStream* lovrAudioStreamInit(AudioStream* stream, Blob* blob, int bufferSize) {
stb_vorbis* decoder = stb_vorbis_open_memory(blob->data, blob->size, NULL, NULL); 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); lovrAssert(decoder, "Could not create audio stream for '%s'", blob->name);
stb_vorbis_info info = stb_vorbis_get_info(decoder); stb_vorbis_info info = stb_vorbis_get_info(decoder);
@ -30,7 +30,7 @@ void lovrAudioStreamDestroy(void* ref) {
free(stream->buffer); 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; stb_vorbis* decoder = (stb_vorbis*) stream->decoder;
short* buffer = destination ? destination : (short*) stream->buffer; short* buffer = destination ? destination : (short*) stream->buffer;
int capacity = destination ? size : (stream->bufferSize / sizeof(short)); int capacity = destination ? size : (stream->bufferSize / sizeof(short));

View File

@ -15,10 +15,10 @@ typedef struct {
Blob* blob; Blob* blob;
} AudioStream; } 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__) #define lovrAudioStreamCreate(...) lovrAudioStreamInit(lovrAlloc(AudioStream), __VA_ARGS__)
void lovrAudioStreamDestroy(void* ref); 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 lovrAudioStreamRewind(AudioStream* stream);
void lovrAudioStreamSeek(AudioStream* stream, int sample); void lovrAudioStreamSeek(AudioStream* stream, int sample);
int lovrAudioStreamTell(AudioStream* stream); int lovrAudioStreamTell(AudioStream* stream);

View File

@ -106,7 +106,7 @@ typedef struct {
} ModelBuffer; } ModelBuffer;
typedef struct { typedef struct {
size_t offset; uint32_t offset;
uint32_t buffer; uint32_t buffer;
uint32_t count; uint32_t count;
AttributeType type; AttributeType type;

View File

@ -160,7 +160,7 @@ ModelData* lovrModelDataInitGltf(ModelData* model, Blob* source) {
int tokenCount = 0; int tokenCount = 0;
if ((tokenCount = jsmn_parse(&parser, json, jsonLength, stackTokens, MAX_STACK_TOKENS)) == JSMN_ERROR_NOMEM) { 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? jsmn_init(&parser); // This shouldn't be necessary but not doing it caused an infinite loop?
do { do {

View File

@ -41,8 +41,7 @@ bool lovrRasterizerHasGlyph(Rasterizer* rasterizer, uint32_t character) {
} }
bool lovrRasterizerHasGlyphs(Rasterizer* rasterizer, const char* str) { bool lovrRasterizerHasGlyphs(Rasterizer* rasterizer, const char* str) {
int len = strlen(str); const char* end = str + strlen(str);
const char* end = str + len;
unsigned int codepoint; unsigned int codepoint;
size_t bytes; size_t bytes;

View File

@ -24,9 +24,9 @@ SoundData* lovrSoundDataInitFromAudioStream(SoundData* soundData, AudioStream* a
int samples; int samples;
short* buffer = soundData->blob.data; short* buffer = soundData->blob.data;
size_t offset = 0; int offset = 0;
lovrAudioStreamRewind(audioStream); 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; offset += samples;
} }
@ -35,7 +35,7 @@ SoundData* lovrSoundDataInitFromAudioStream(SoundData* soundData, AudioStream* a
SoundData* lovrSoundDataInitFromBlob(SoundData* soundData, Blob* blob) { SoundData* lovrSoundDataInitFromBlob(SoundData* soundData, Blob* blob) {
soundData->bitDepth = 16; 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); soundData->blob.size = soundData->samples * soundData->channelCount * (soundData->bitDepth / 8);
return soundData; return soundData;
} }

View File

@ -111,9 +111,9 @@ static int parseDDS(uint8_t* data, size_t size, TextureData* textureData) {
// Load mipmaps // Load mipmaps
for (int i = 0; i < mipmapCount; i++) { for (int i = 0; i < mipmapCount; i++) {
size_t numBlocksWide = width ? MAX(1, (width + 3) / 4) : 0; int numBlocksWide = width ? MAX(1, (width + 3) / 4) : 0;
size_t numBlocksHigh = height ? MAX(1, (height + 3) / 4) : 0; int numBlocksHigh = height ? MAX(1, (height + 3) / 4) : 0;
size_t mipmapSize = numBlocksWide * numBlocksHigh * blockBytes; int mipmapSize = numBlocksWide * numBlocksHigh * blockBytes;
// Overflow check // Overflow check
if (mipmapSize == 0 || (offset + mipmapSize) > size) { if (mipmapSize == 0 || (offset + mipmapSize) > size) {
@ -158,13 +158,14 @@ TextureData* lovrTextureDataInitFromBlob(TextureData* textureData, Blob* blob, b
return textureData; return textureData;
} }
int length = (int) blob->size;
stbi_set_flip_vertically_on_load(flip); 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->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 { } else {
textureData->format = FORMAT_RGBA; 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) { if (!textureData->blob.data) {
@ -250,7 +251,7 @@ bool lovrTextureDataEncode(TextureData* textureData, const char* filename) {
int width = textureData->width; int width = textureData->width;
int height = textureData->height; int height = textureData->height;
void* data = (uint8_t*) textureData->blob.data + (textureData->height - 1) * textureData->width * components; 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); bool success = stbi_write_png_to_func(writeCallback, &file, width, height, components, data, stride);
lovrFileDestroy(&file); lovrFileDestroy(&file);
return success; return success;

View File

@ -31,7 +31,7 @@ typedef struct {
int width; int width;
int height; int height;
void* data; void* data;
size_t size; int size;
} Mipmap; } Mipmap;
typedef vec_t(Mipmap) vec_mipmap_t; typedef vec_t(Mipmap) vec_mipmap_t;

View File

@ -118,7 +118,7 @@ int lovrFilesystemGetAppdataDirectory(char* dest, unsigned int size) {
} }
void lovrFilesystemGetDirectoryItems(const char* path, getDirectoryItemsCallback callback, void* userdata) { 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) { int lovrFilesystemGetExecutablePath(char* path, uint32_t size) {

View File

@ -9,7 +9,7 @@
extern const char lovrDirSep; 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 { typedef struct {
bool initialized; bool initialized;

View File

@ -25,5 +25,5 @@ void lovrBufferFlush(Buffer* buffer) {
lovrBufferFlushRange(buffer, buffer->flushFrom, buffer->flushTo - buffer->flushFrom); lovrBufferFlushRange(buffer, buffer->flushFrom, buffer->flushTo - buffer->flushFrom);
buffer->flushFrom = SIZE_MAX; buffer->flushFrom = SIZE_MAX;
buffer->flushTo = -SIZE_MAX; buffer->flushTo = 0;
} }

View File

@ -8,7 +8,6 @@
#include "lib/stb/stb_image.h" #include "lib/stb/stb_image.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
static GraphicsState state; 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 } }); lovrEventPush((Event) { .type = EVENT_QUIT, .data.quit = { false, 0 } });
} }
@ -30,7 +29,7 @@ static void onResizeWindow(int width, int height) {
state.height = height; state.height = height;
} }
static const size_t BUFFER_COUNTS[] = { static const uint32_t BUFFER_COUNTS[] = {
[STREAM_VERTEX] = (1 << 16) - 1, [STREAM_VERTEX] = (1 << 16) - 1,
[STREAM_INDEX] = 1 << 16, [STREAM_INDEX] = 1 << 16,
[STREAM_DRAW_ID] = (1 << 16) - 1, [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 // 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); state.maxDraws = MIN(maxBlockSize / sizeof(DrawData) / 64 * 64, 256);
// The identity buffer is used for autoinstanced meshes and instanced primitives and maps the // 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) { static void* lovrGraphicsMapBuffer(BufferRole role, uint32_t count) {
Buffer* buffer = state.buffers[role]; 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); 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) { if (state.cursors[role] + count > limit) {
@ -239,8 +238,8 @@ void lovrGraphicsSetCamera(Camera* camera, bool clear) {
memset(&state.camera, 0, sizeof(Camera)); memset(&state.camera, 0, sizeof(Camera));
mat4_identity(state.camera.viewMatrix[0]); mat4_identity(state.camera.viewMatrix[0]);
mat4_identity(state.camera.viewMatrix[1]); 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[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. * M_PI / 180., (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 { } else {
state.camera = *camera; state.camera = *camera;
} }
@ -496,7 +495,7 @@ void lovrGraphicsBatch(BatchRequest* req) {
if (req->type == BATCH_MESH) { if (req->type == BATCH_MESH) {
float* pose = req->params.mesh.pose ? req->params.mesh.pose : (float[]) MAT4_IDENTITY; 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); lovrShaderSetMatrices(shader, "lovrPose", pose, 0, count);
} }
@ -537,7 +536,7 @@ void lovrGraphicsBatch(BatchRequest* req) {
for (int i = 0; i < MAX_BUFFER_ROLES; i++) { for (int i = 0; i < MAX_BUFFER_ROLES; i++) {
if (streamRequirements[i] > 0 && state.cursors[i] + streamRequirements[i] > BUFFER_COUNTS[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(); lovrGraphicsFlush();
state.locks[i][MAX_LOCKS - 1] = lovrGpuLock(); state.locks[i][MAX_LOCKS - 1] = lovrGpuLock();
state.cursors[i] = state.cursors[i] >= oldCursor ? 0 : state.cursors[i]; state.cursors[i] = state.cursors[i] >= oldCursor ? 0 : state.cursors[i];
@ -821,9 +820,9 @@ void lovrGraphicsFlush() {
if (batch->vertexCount > 0) { if (batch->vertexCount > 0) {
size_t lockSize = BUFFER_COUNTS[STREAM_VERTEX] / MAX_LOCKS + 1; size_t lockSize = BUFFER_COUNTS[STREAM_VERTEX] / MAX_LOCKS + 1;
int firstLock = batch->vertexStart / lockSize; size_t firstLock = batch->vertexStart / lockSize;
int lastLock = (batch->vertexStart + batch->vertexCount) / lockSize; size_t lastLock = (batch->vertexStart + batch->vertexCount) / lockSize;
for (int i = firstLock; i < lastLock; i++) { for (size_t i = firstLock; i < lastLock; i++) {
state.locks[STREAM_VERTEX][i] = lovrGpuLock(); state.locks[STREAM_VERTEX][i] = lovrGpuLock();
if (!instanced) { if (!instanced) {
state.locks[STREAM_DRAW_ID][i] = lovrGpuLock(); state.locks[STREAM_DRAW_ID][i] = lovrGpuLock();
@ -833,18 +832,18 @@ void lovrGraphicsFlush() {
if (batch->indexCount > 0) { if (batch->indexCount > 0) {
size_t lockSize = BUFFER_COUNTS[STREAM_INDEX] / MAX_LOCKS + 1; size_t lockSize = BUFFER_COUNTS[STREAM_INDEX] / MAX_LOCKS + 1;
int firstLock = batch->indexStart / lockSize; size_t firstLock = batch->indexStart / lockSize;
int lastLock = (batch->indexStart + batch->indexCount) / lockSize; size_t lastLock = (batch->indexStart + batch->indexCount) / lockSize;
for (int i = firstLock; i < lastLock; i++) { for (size_t i = firstLock; i < lastLock; i++) {
state.locks[STREAM_INDEX][i] = lovrGpuLock(); state.locks[STREAM_INDEX][i] = lovrGpuLock();
} }
} }
if (batch->drawCount > 0) { if (batch->drawCount > 0) {
size_t lockSize = BUFFER_COUNTS[STREAM_DRAW_DATA] / MAX_LOCKS; size_t lockSize = BUFFER_COUNTS[STREAM_DRAW_DATA] / MAX_LOCKS;
int firstLock = batch->drawStart / lockSize; size_t firstLock = batch->drawStart / lockSize;
int lastLock = MIN(batch->drawStart + state.maxDraws, BUFFER_COUNTS[STREAM_DRAW_DATA] - 1) / lockSize; size_t lastLock = MIN(batch->drawStart + state.maxDraws, BUFFER_COUNTS[STREAM_DRAW_DATA] - 1) / lockSize;
for (int i = firstLock; i < lastLock; i++) { for (size_t i = firstLock; i < lastLock; i++) {
state.locks[STREAM_DRAW_DATA][i] = lovrGpuLock(); state.locks[STREAM_DRAW_DATA][i] = lovrGpuLock();
} }
} }

View File

@ -185,7 +185,7 @@ typedef struct {
Mesh* instancedMesh; Mesh* instancedMesh;
Buffer* identityBuffer; Buffer* identityBuffer;
Buffer* buffers[MAX_BUFFER_ROLES]; Buffer* buffers[MAX_BUFFER_ROLES];
size_t cursors[MAX_BUFFER_ROLES]; uint32_t cursors[MAX_BUFFER_ROLES];
void* locks[MAX_BUFFER_ROLES][MAX_LOCKS]; void* locks[MAX_BUFFER_ROLES][MAX_LOCKS];
Batch cachedGeometry; Batch cachedGeometry;
Batch batches[MAX_BATCHES]; Batch batches[MAX_BATCHES];

View File

@ -163,7 +163,7 @@ size_t lovrShaderComputeUniformLayout(vec_uniform_t* uniforms) {
size_t size = 0; size_t size = 0;
Uniform* uniform; int i; Uniform* uniform; int i;
vec_foreach_ptr(uniforms, uniform, i) { vec_foreach_ptr(uniforms, uniform, i) {
size_t align; int align;
if (uniform->count > 1 || uniform->type == UNIFORM_MATRIX) { if (uniform->count > 1 || uniform->type == UNIFORM_MATRIX) {
align = 16 * (uniform->type == UNIFORM_MATRIX ? uniform->components : 1); align = 16 * (uniform->type == UNIFORM_MATRIX ? uniform->components : 1);
uniform->size = align * uniform->count; uniform->size = align * uniform->count;

View File

@ -2,7 +2,6 @@
#include "graphics/graphics.h" #include "graphics/graphics.h"
#include "lib/math.h" #include "lib/math.h"
#include "platform.h" #include "platform.h"
#define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@ -58,7 +57,7 @@ static bool desktopInit(float offset, int msaa) {
return true; return true;
} }
static void desktopDestroy() { static void desktopDestroy(void) {
Controller *controller; int i; Controller *controller; int i;
vec_foreach(&state.controllers, controller, i) { vec_foreach(&state.controllers, controller, i) {
lovrRelease(controller); lovrRelease(controller);
@ -67,15 +66,15 @@ static void desktopDestroy() {
memset(&state, 0, sizeof(state)); memset(&state, 0, sizeof(state));
} }
static HeadsetType desktopGetType() { static HeadsetType desktopGetType(void) {
return HEADSET_UNKNOWN; return HEADSET_UNKNOWN;
} }
static HeadsetOrigin desktopGetOriginType() { static HeadsetOrigin desktopGetOriginType(void) {
return ORIGIN_HEAD; return ORIGIN_HEAD;
} }
static bool desktopIsMounted() { static bool desktopIsMounted(void) {
return true; return true;
} }
@ -181,7 +180,7 @@ static void desktopRenderTo(void (*callback)(void*), void* userdata) {
uint32_t width, height; uint32_t width, height;
desktopGetDisplayDimensions(&width, &height); desktopGetDisplayDimensions(&width, &height);
Camera camera = { .canvas = NULL, .viewMatrix = { MAT4_IDENTITY }, .stereo = true }; 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_multiply(camera.viewMatrix[0], state.transform);
mat4_invertPose(camera.viewMatrix[0]); mat4_invertPose(camera.viewMatrix[0]);
mat4_set(camera.projection[1], camera.projection[0]); mat4_set(camera.projection[1], camera.projection[0]);

View File

@ -10,6 +10,8 @@
#include <stdint.h> #include <stdint.h>
#ifndef WIN32 #ifndef WIN32
#pragma pack(push, 4) #pragma pack(push, 4)
#else
#undef EXTERN_C
#endif #endif
#include <openvr_capi.h> #include <openvr_capi.h>
#ifndef WIN32 #ifndef WIN32
@ -177,7 +179,7 @@ static bool openvrInit(float offset, int msaa) {
return true; return true;
} }
static void openvrDestroy() { static void openvrDestroy(void) {
lovrRelease(state.canvas); lovrRelease(state.canvas);
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
if (state.deviceModels[i]) { if (state.deviceModels[i]) {
@ -199,11 +201,11 @@ static void openvrDestroy() {
memset(&state, 0, sizeof(HeadsetState)); memset(&state, 0, sizeof(HeadsetState));
} }
static HeadsetType openvrGetType() { static HeadsetType openvrGetType(void) {
return state.type; return state.type;
} }
static HeadsetOrigin openvrGetOriginType() { static HeadsetOrigin openvrGetOriginType(void) {
switch (state.compositor->GetTrackingSpace()) { switch (state.compositor->GetTrackingSpace()) {
case ETrackingUniverseOrigin_TrackingUniverseSeated: return ORIGIN_HEAD; case ETrackingUniverseOrigin_TrackingUniverseSeated: return ORIGIN_HEAD;
case ETrackingUniverseOrigin_TrackingUniverseStanding: return ORIGIN_FLOOR; case ETrackingUniverseOrigin_TrackingUniverseStanding: return ORIGIN_FLOOR;
@ -211,7 +213,7 @@ static HeadsetOrigin openvrGetOriginType() {
} }
} }
static bool openvrIsMounted() { static bool openvrIsMounted(void) {
VRControllerState_t input; VRControllerState_t input;
state.system->GetControllerState(HEADSET_INDEX, &input, sizeof(input)); state.system->GetControllerState(HEADSET_INDEX, &input, sizeof(input));
return (input.ulButtonPressed >> EVRButtonId_k_EButton_ProximitySensor) & 1; 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; return lovrCanvasGetAttachments(state.canvas, NULL)[0].texture;
} }

View File

@ -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 * This buffer is reused constantly for small strings
* If there are any excess pages, they won't be hit anyway. * If there are any excess pages, they won't be hit anyway.
* This gains ~5% speedup. */ * 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, '\"'); strbuf_append_char_unsafe(json, '\"');
for (i = 0; i < len; i++) { 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. /* Ensure the temporary buffer can hold the entire string.
* This means we no longer need to do length checks since the decoded * This means we no longer need to do length checks since the decoded
* string must be smaller than the entire json string */ * 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_next_token(&json, &token);
json_process_value(l, &json, &token); json_process_value(l, &json, &token);

View File

@ -94,8 +94,8 @@ void strbuf_set_increment(strbuf_t *s, int increment)
static inline void debug_stats(strbuf_t *s) static inline void debug_stats(strbuf_t *s)
{ {
if (s->debug) { if (s->debug) {
fprintf(stderr, "strbuf(%lx) reallocs: %d, length: %d, size: %d\n", fprintf(stderr, "strbuf(%p) reallocs: %d, length: %d, size: %d\n",
(long)s, s->reallocs, s->length, s->size); 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); newsize = calculate_new_size(s, len);
if (s->debug > 1) { if (s->debug > 1) {
fprintf(stderr, "strbuf(%lx) resize: %d => %d\n", fprintf(stderr, "strbuf(%p) resize: %d => %d\n",
(long)s, s->size, newsize); s, s->size, newsize);
} }
s->size = newsize; s->size = newsize;

View File

@ -29,7 +29,7 @@ static unsigned map_hash(const char *str) {
static map_node_t *map_newnode(const char *key, void *value, int vsize) { static map_node_t *map_newnode(const char *key, void *value, int vsize) {
map_node_t *node; map_node_t *node;
int ksize = strlen(key) + 1; int ksize = (int) strlen(key) + 1;
int voffset = ksize + ((sizeof(void*) - ksize) % sizeof(void*)); int voffset = ksize + ((sizeof(void*) - ksize) % sizeof(void*));
node = malloc(sizeof(*node) + voffset + vsize); node = malloc(sizeof(*node) + voffset + vsize);
if (!node) return NULL; if (!node) return NULL;

View File

@ -1,5 +1,4 @@
#include "math.h" #include "math.h"
#define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#ifdef LOVR_USE_SSE #ifdef LOVR_USE_SSE

View File

@ -107,34 +107,34 @@ sds sdsnewlen(const void *init, size_t initlen) {
fp = ((unsigned char*)s)-1; fp = ((unsigned char*)s)-1;
switch(type) { switch(type) {
case SDS_TYPE_5: { case SDS_TYPE_5: {
*fp = type | (initlen << SDS_TYPE_BITS); *fp = (unsigned char) (type | (initlen << SDS_TYPE_BITS));
break; break;
} }
case SDS_TYPE_8: { case SDS_TYPE_8: {
SDS_HDR_VAR(8,s); SDS_HDR_VAR(8,s);
sh->len = initlen; sh->len = (uint8_t) initlen;
sh->alloc = initlen; sh->alloc = (uint8_t) initlen;
*fp = type; *fp = type;
break; break;
} }
case SDS_TYPE_16: { case SDS_TYPE_16: {
SDS_HDR_VAR(16,s); SDS_HDR_VAR(16,s);
sh->len = initlen; sh->len = (uint16_t) initlen;
sh->alloc = initlen; sh->alloc = (uint16_t) initlen;
*fp = type; *fp = type;
break; break;
} }
case SDS_TYPE_32: { case SDS_TYPE_32: {
SDS_HDR_VAR(32,s); SDS_HDR_VAR(32,s);
sh->len = initlen; sh->len = (uint32_t) initlen;
sh->alloc = initlen; sh->alloc = (uint32_t) initlen;
*fp = type; *fp = type;
break; break;
} }
case SDS_TYPE_64: { case SDS_TYPE_64: {
SDS_HDR_VAR(64,s); SDS_HDR_VAR(64,s);
sh->len = initlen; sh->len = (uint64_t) initlen;
sh->alloc = initlen; sh->alloc = (uint64_t) initlen;
*fp = type; *fp = type;
break; break;
} }
@ -472,7 +472,7 @@ int sdsll2str(char *s, long long value) {
s++; s++;
p--; p--;
} }
return l; return (int) l;
} }
/* Identical sdsll2str(), but for unsigned long long type. */ /* Identical sdsll2str(), but for unsigned long long type. */
@ -501,7 +501,7 @@ int sdsull2str(char *s, unsigned long long v) {
s++; s++;
p--; p--;
} }
return l; return (int) l;
} }
/* Create an sds string from a long long value. It is much faster than: /* 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); va_start(ap,fmt);
f = fmt; /* Next format specifier byte to process. */ 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) { while(*f) {
char next, *str; char next, *str;
size_t l; size_t l;
@ -628,7 +628,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
} }
memcpy(s+i,str,l); memcpy(s+i,str,l);
sdsinclen(s,l); sdsinclen(s,l);
i += l; i += (long) l;
break; break;
case 'i': case 'i':
case 'I': case 'I':
@ -644,7 +644,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
} }
memcpy(s+i,buf,l); memcpy(s+i,buf,l);
sdsinclen(s,l); sdsinclen(s,l);
i += l; i += (long) l;
} }
break; break;
case 'u': case 'u':
@ -661,7 +661,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
} }
memcpy(s+i,buf,l); memcpy(s+i,buf,l);
sdsinclen(s,l); sdsinclen(s,l);
i += l; i += (long) l;
} }
break; break;
default: /* Handle %% and generally %<unknown>. */ default: /* Handle %% and generally %<unknown>. */

View File

@ -149,20 +149,20 @@ static inline void sdssetlen(sds s, size_t newlen) {
case SDS_TYPE_5: case SDS_TYPE_5:
{ {
unsigned char *fp = ((unsigned char*)s)-1; 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; break;
case SDS_TYPE_8: case SDS_TYPE_8:
SDS_HDR(8,s)->len = newlen; SDS_HDR(8,s)->len = (uint8_t) newlen;
break; break;
case SDS_TYPE_16: case SDS_TYPE_16:
SDS_HDR(16,s)->len = newlen; SDS_HDR(16,s)->len = (uint16_t) newlen;
break; break;
case SDS_TYPE_32: case SDS_TYPE_32:
SDS_HDR(32,s)->len = newlen; SDS_HDR(32,s)->len = (uint32_t) newlen;
break; break;
case SDS_TYPE_64: case SDS_TYPE_64:
SDS_HDR(64,s)->len = newlen; SDS_HDR(64,s)->len = (uint64_t) newlen;
break; break;
} }
} }
@ -173,21 +173,21 @@ static inline void sdsinclen(sds s, size_t inc) {
case SDS_TYPE_5: case SDS_TYPE_5:
{ {
unsigned char *fp = ((unsigned char*)s)-1; unsigned char *fp = ((unsigned char*)s)-1;
unsigned char newlen = SDS_TYPE_5_LEN(flags)+inc; unsigned char newlen = (unsigned char) (SDS_TYPE_5_LEN(flags)+inc);
*fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS); *fp = (unsigned char) (SDS_TYPE_5 | (newlen << SDS_TYPE_BITS));
} }
break; break;
case SDS_TYPE_8: case SDS_TYPE_8:
SDS_HDR(8,s)->len += inc; SDS_HDR(8,s)->len += (uint8_t) inc;
break; break;
case SDS_TYPE_16: case SDS_TYPE_16:
SDS_HDR(16,s)->len += inc; SDS_HDR(16,s)->len += (uint16_t) inc;
break; break;
case SDS_TYPE_32: case SDS_TYPE_32:
SDS_HDR(32,s)->len += inc; SDS_HDR(32,s)->len += (uint32_t) inc;
break; break;
case SDS_TYPE_64: case SDS_TYPE_64:
SDS_HDR(64,s)->len += inc; SDS_HDR(64,s)->len += (uint64_t) inc;
break; break;
} }
} }
@ -217,16 +217,16 @@ static inline void sdssetalloc(sds s, size_t newlen) {
/* Nothing to do, this type has no total allocation info. */ /* Nothing to do, this type has no total allocation info. */
break; break;
case SDS_TYPE_8: case SDS_TYPE_8:
SDS_HDR(8,s)->alloc = newlen; SDS_HDR(8,s)->alloc = (uint8_t) newlen;
break; break;
case SDS_TYPE_16: case SDS_TYPE_16:
SDS_HDR(16,s)->alloc = newlen; SDS_HDR(16,s)->alloc = (uint16_t) newlen;
break; break;
case SDS_TYPE_32: case SDS_TYPE_32:
SDS_HDR(32,s)->alloc = newlen; SDS_HDR(32,s)->alloc = (uint32_t) newlen;
break; break;
case SDS_TYPE_64: case SDS_TYPE_64:
SDS_HDR(64,s)->alloc = newlen; SDS_HDR(64,s)->alloc = (uint64_t) newlen;
break; break;
} }
} }

View File

@ -18,7 +18,7 @@ static int luax_meta__gc(lua_State* L) {
static int luax_module__gc(lua_State* L) { static int luax_module__gc(lua_State* L) {
lua_getfield(L, LUA_REGISTRYINDEX, "_lovrmodules"); 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); lua_rawgeti(L, 2, i);
luax_destructor destructor = (luax_destructor) lua_touserdata(L, -1); luax_destructor destructor = (luax_destructor) lua_touserdata(L, -1);
destructor(); destructor();
@ -80,7 +80,7 @@ void luax_atexit(lua_State* L, luax_destructor destructor) {
lua_setfield(L, LUA_REGISTRYINDEX, "_lovrmodules"); lua_setfield(L, LUA_REGISTRYINDEX, "_lovrmodules");
} }
int length = lua_objlen(L, -1); int length = luax_len(L, -1);
lua_pushlightuserdata(L, (void*) destructor); lua_pushlightuserdata(L, (void*) destructor);
lua_rawseti(L, -2, length + 1); lua_rawseti(L, -2, length + 1);
lua_pop(L, 1); lua_pop(L, 1);

View File

@ -10,6 +10,7 @@
#define LUA_RIDX_MAINTHREAD 1 #define LUA_RIDX_MAINTHREAD 1
#endif #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_totype(L, i, T) ((T*) _luax_totype(L, i, #T))
#define luax_checktype(L, i, T) ((T*) _luax_checktype(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) #define luax_checkfloat(L, i) (float) luaL_checknumber(L, i)

View File

@ -1,5 +1,4 @@
#include "math/randomGenerator.h" #include "math/randomGenerator.h"
#define _USE_MATH_DEFINES
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -38,6 +38,7 @@ static int convertMouseButton(MouseButton button) {
switch (button) { switch (button) {
case MOUSE_LEFT: return GLFW_MOUSE_BUTTON_LEFT; case MOUSE_LEFT: return GLFW_MOUSE_BUTTON_LEFT;
case MOUSE_RIGHT: return GLFW_MOUSE_BUTTON_RIGHT; 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_DOWN: return GLFW_KEY_DOWN;
case KEY_LEFT: return GLFW_KEY_LEFT; case KEY_LEFT: return GLFW_KEY_LEFT;
case KEY_RIGHT: return GLFW_KEY_RIGHT; case KEY_RIGHT: return GLFW_KEY_RIGHT;
default: lovrThrow("Unreachable");
} }
} }

View File

@ -36,6 +36,10 @@
#define CLAMP(x, min, max) MAX(min, MIN(max, x)) #define CLAMP(x, min, max) MAX(min, MIN(max, x))
#define ALIGN(p, n) ((uintptr_t) p & -n) #define ALIGN(p, n) ((uintptr_t) p & -n)
#ifndef M_PI
#define M_PI 3.14159265358979323846264f
#endif
typedef struct ref { typedef struct ref {
void (*destructor)(void*); void (*destructor)(void*);
const char* type; const char* type;