Update refcounting (again);

- Ref struct only stores refcount now and is more general.
- Proxy stores a hash of its type name instead of an enum.
- Variants store additional information instead of using a vtable.
- Remove the concept of superclasses from the API.
- Clean up some miscellaneous includes.
This commit is contained in:
bjorn 2019-06-02 00:20:10 -07:00
parent d2bff7d239
commit 22fe333150
65 changed files with 434 additions and 448 deletions

View File

@ -31,7 +31,6 @@ extern const luaL_Reg lovrCylinderShape[];
extern const luaL_Reg lovrDistanceJoint[];
extern const luaL_Reg lovrFont[];
extern const luaL_Reg lovrHingeJoint[];
extern const luaL_Reg lovrJoint[];
extern const luaL_Reg lovrMat4[];
extern const luaL_Reg lovrMaterial[];
extern const luaL_Reg lovrMesh[];
@ -44,7 +43,6 @@ extern const luaL_Reg lovrRandomGenerator[];
extern const luaL_Reg lovrRasterizer[];
extern const luaL_Reg lovrShader[];
extern const luaL_Reg lovrShaderBlock[];
extern const luaL_Reg lovrShape[];
extern const luaL_Reg lovrSliderJoint[];
extern const luaL_Reg lovrSoundData[];
extern const luaL_Reg lovrSource[];
@ -124,3 +122,12 @@ int luax_readquat(lua_State* L, int index, float* q, const char* expected);
int luax_readmat4(lua_State* L, int index, float* m, int scaleComponents);
Seed luax_checkrandomseed(lua_State* L, int index);
#endif
#ifdef LOVR_ENABLE_PHYSICS
struct Joint;
struct Shape;
void luax_pushjoint(lua_State* L, struct Joint* joint);
void luax_pushshape(lua_State* L, struct Shape* shape);
struct Joint* luax_checkjoint(lua_State* L, int index);
struct Shape* luax_checkshape(lua_State* L, int index);
#endif

View File

@ -6,6 +6,7 @@
#include "data/audioStream.h"
#include "data/soundData.h"
#include "core/maf.h"
#include "core/ref.h"
#include <stdlib.h>
struct Blob* luax_readblob(lua_State* L, int index, const char* debug);
@ -116,7 +117,7 @@ static int l_lovrAudioNewMicrophone(lua_State* L) {
int bitDepth = luaL_optinteger(L, 4, 16);
int channelCount = luaL_optinteger(L, 5, 1);
Microphone* microphone = lovrMicrophoneCreate(name, samples, sampleRate, bitDepth, channelCount);
luax_pushobject(L, microphone);
luax_pushtype(L, Microphone, microphone);
lovrRelease(Microphone, microphone);
return 1;
}
@ -156,7 +157,7 @@ static int l_lovrAudioNewSource(lua_State* L) {
}
}
luax_pushobject(L, source);
luax_pushtype(L, Source, source);
lovrRelease(Source, source);
return 1;
}

View File

@ -1,6 +1,7 @@
#include "api.h"
#include "data/audioStream.h"
#include "data/soundData.h"
#include "core/ref.h"
#include <string.h>
#include <stdlib.h>
@ -10,7 +11,7 @@ static int l_lovrAudioStreamDecode(lua_State* L) {
if (samples > 0) {
SoundData* soundData = lovrSoundDataCreate(samples / stream->channelCount, stream->sampleRate, stream->bitDepth, stream->channelCount);
memcpy(soundData->blob.data, stream->buffer, samples * (stream->bitDepth / 8));
luax_pushobject(L, soundData);
luax_pushtype(L, SoundData, soundData);
lovrRelease(SoundData, soundData);
} else {
lua_pushnil(L);

View File

@ -1,6 +1,8 @@
#include "api.h"
#include "graphics/canvas.h"
#include "graphics/graphics.h"
#include "core/ref.h"
#include <stdlib.h>
static int luax_checkattachment(lua_State* L, int index, Attachment* attachment) {
if (lua_istable(L, index)) {
@ -55,7 +57,7 @@ static int l_lovrCanvasNewTextureData(lua_State* L) {
lovrCanvasGetAttachments(canvas, &count);
lovrAssert(index >= 0 && index < count, "Can not create a TextureData from Texture #%d of Canvas (it only has %d textures)", index, count);
TextureData* textureData = lovrCanvasNewTextureData(canvas, index);
luax_pushobject(L, textureData);
luax_pushtype(L, TextureData, textureData);
lovrRelease(TextureData, textureData);
return 1;
}
@ -76,7 +78,7 @@ static int l_lovrCanvasGetTexture(lua_State* L) {
uint32_t count;
const Attachment* attachments = lovrCanvasGetAttachments(canvas, &count);
for (uint32_t i = 0; i < count; i++) {
luax_pushobject(L, attachments[i].texture);
luax_pushtype(L, Texture, attachments[i].texture);
}
return count;
}
@ -112,7 +114,7 @@ static int l_lovrCanvasGetDimensions(lua_State* L) {
static int l_lovrCanvasGetDepthTexture(lua_State* L) {
Canvas* canvas = luax_checktype(L, 1, Canvas);
Texture* texture = lovrCanvasGetDepthTexture(canvas);
luax_pushobject(L, texture);
luax_pushtype(L, Texture, texture);
return 1;
}

View File

@ -11,7 +11,7 @@ static int l_lovrColliderDestroy(lua_State* L) {
static int l_lovrColliderGetWorld(lua_State* L) {
Collider* collider = luax_checktype(L, 1, Collider);
World* world = lovrColliderGetWorld(collider);
luax_pushobject(L, world);
luax_pushtype(L, World, world);
return 1;
}
@ -34,7 +34,7 @@ static int l_lovrColliderGetShapes(lua_State* L) {
lua_newtable(L);
vec_void_t* shapes = lovrColliderGetShapes(collider);
for (int i = 0; i < shapes->length; i++) {
luax_pushobject(L, shapes->data[i]);
luax_pushshape(L, shapes->data[i]);
lua_rawseti(L, -2, i + 1);
}
return 1;
@ -45,7 +45,7 @@ static int l_lovrColliderGetJoints(lua_State* L) {
lua_newtable(L);
vec_void_t* joints = lovrColliderGetJoints(collider);
for (int i = 0; i < joints->length; i++) {
luax_pushobject(L, joints->data[i]);
luax_pushjoint(L, joints->data[i]);
lua_rawseti(L, -2, i + 1);
}
return 1;

View File

@ -1,5 +1,6 @@
#include "api.h"
#include "math/curve.h"
#include <stdlib.h>
static int l_lovrCurveEvaluate(lua_State* L) {
Curve* curve = luax_checktype(L, 1, Curve);
@ -45,7 +46,7 @@ static int l_lovrCurveSlice(lua_State* L) {
float t1 = luax_checkfloat(L, 2);
float t2 = luax_checkfloat(L, 3);
Curve* subcurve = lovrCurveSlice(curve, t1, t2);
luax_pushobject(L, subcurve);
luax_pushtype(L, Curve, subcurve);
return 1;
}

View File

@ -5,6 +5,8 @@
#include "data/rasterizer.h"
#include "data/soundData.h"
#include "data/textureData.h"
#include "core/ref.h"
#include <stdlib.h>
static int l_lovrDataNewBlob(lua_State* L) {
size_t size;
@ -30,7 +32,7 @@ static int l_lovrDataNewBlob(lua_State* L) {
}
const char* name = luaL_optstring(L, 2, "");
Blob* blob = lovrBlobCreate(data, size, name);
luax_pushobject(L, blob);
luax_pushtype(L, Blob, blob);
lovrRelease(Blob, blob);
return 1;
}
@ -39,7 +41,7 @@ static int l_lovrDataNewAudioStream(lua_State* L) {
Blob* blob = luax_readblob(L, 1, "AudioStream");
int bufferSize = luaL_optinteger(L, 2, 4096);
AudioStream* stream = lovrAudioStreamCreate(blob, bufferSize);
luax_pushobject(L, stream);
luax_pushtype(L, AudioStream, stream);
lovrRelease(Blob, blob);
lovrRelease(AudioStream, stream);
return 1;
@ -48,7 +50,7 @@ static int l_lovrDataNewAudioStream(lua_State* L) {
static int l_lovrDataNewModelData(lua_State* L) {
Blob* blob = luax_readblob(L, 1, "Model");
ModelData* modelData = lovrModelDataCreate(blob);
luax_pushobject(L, modelData);
luax_pushtype(L, ModelData, modelData);
lovrRelease(Blob, blob);
lovrRelease(ModelData, modelData);
return 1;
@ -66,7 +68,7 @@ static int l_lovrDataNewRasterizer(lua_State* L) {
}
Rasterizer* rasterizer = lovrRasterizerCreate(blob, size);
luax_pushobject(L, rasterizer);
luax_pushtype(L, Rasterizer, rasterizer);
lovrRelease(Blob, blob);
lovrRelease(Rasterizer, rasterizer);
return 1;
@ -79,7 +81,7 @@ static int l_lovrDataNewSoundData(lua_State* L) {
int bitDepth = luaL_optinteger(L, 3, 16);
int channelCount = luaL_optinteger(L, 4, 2);
SoundData* soundData = lovrSoundDataCreate(samples, sampleRate, bitDepth, channelCount);
luax_pushobject(L, soundData);
luax_pushtype(L, SoundData, soundData);
lovrRelease(SoundData, soundData);
return 1;
}
@ -87,14 +89,14 @@ static int l_lovrDataNewSoundData(lua_State* L) {
AudioStream* audioStream = luax_totype(L, 1, AudioStream);
if (audioStream) {
SoundData* soundData = lovrSoundDataCreateFromAudioStream(audioStream);
luax_pushobject(L, soundData);
luax_pushtype(L, SoundData, soundData);
lovrRelease(SoundData, soundData);
return 1;
}
Blob* blob = luax_readblob(L, 1, "SoundData");
SoundData* soundData = lovrSoundDataCreateFromBlob(blob);
luax_pushobject(L, soundData);
luax_pushtype(L, SoundData, soundData);
lovrRelease(Blob, blob);
lovrRelease(SoundData, soundData);
return 1;
@ -114,7 +116,7 @@ static int l_lovrDataNewTextureData(lua_State* L) {
lovrRelease(Blob, blob);
}
luax_pushobject(L, textureData);
luax_pushtype(L, TextureData, textureData);
lovrRelease(TextureData, textureData);
return 1;
}
@ -136,7 +138,7 @@ int luaopen_lovr_data(lua_State* L) {
luax_registertype(L, AudioStream);
luax_registertype(L, ModelData);
luax_registertype(L, Rasterizer);
luax_extendtype(L, Blob, SoundData);
luax_extendtype(L, Blob, TextureData);
luax_registertype(L, SoundData);
luax_registertype(L, TextureData);
return 1;
}

View File

@ -1,5 +1,6 @@
#include "api.h"
#include "event/event.h"
#include "core/ref.h"
#include <stdlib.h>
#include <string.h>
@ -40,8 +41,21 @@ void luax_checkvariant(lua_State* L, int index, Variant* variant) {
case LUA_TUSERDATA:
variant->type = TYPE_OBJECT;
variant->value.object = ((Proxy*) lua_touserdata(L, index))->object;
lovrRetain(variant->value.object);
Proxy* proxy = lua_touserdata(L, index);
lua_getmetatable(L, index);
lua_pushliteral(L, "__name");
lua_rawget(L, -2);
variant->value.object.type = (const char*) lua_touserdata(L, -1);
lua_pop(L, 1);
lua_pushliteral(L, "__destructor");
lua_rawget(L, -2);
variant->value.object.destructor = (destructorFn*) lua_tocfunction(L, -1);
lua_pop(L, 1);
variant->value.object.pointer = proxy->object;
lovrRetain(proxy->object);
break;
default:
@ -56,7 +70,7 @@ int luax_pushvariant(lua_State* L, Variant* variant) {
case TYPE_BOOLEAN: lua_pushboolean(L, variant->value.boolean); return 1;
case TYPE_NUMBER: lua_pushnumber(L, variant->value.number); return 1;
case TYPE_STRING: lua_pushstring(L, variant->value.string); return 1;
case TYPE_OBJECT: luax_pushobject(L, variant->value.object); return 1;
case TYPE_OBJECT: _luax_pushtype(L, variant->value.object.type, hash(variant->value.object.type), variant->value.object.pointer); return 1;
default: return 0;
}
}
@ -88,7 +102,7 @@ static int nextEvent(lua_State* L) {
return 2;
case EVENT_THREAD_ERROR:
luax_pushobject(L, event.data.thread.thread);
luax_pushtype(L, Thread, event.data.thread.thread);
lua_pushstring(L, event.data.thread.error);
free(event.data.thread.error);
return 3;

View File

@ -1,6 +1,7 @@
#include "api.h"
#include "filesystem/filesystem.h"
#include "data/blob.h"
#include "core/ref.h"
#include <stdlib.h>
#include "platform.h"
@ -279,7 +280,7 @@ static int l_lovrFilesystemNewBlob(lua_State* L) {
uint8_t* data = lovrFilesystemRead(path, -1, &size);
lovrAssert(data, "Could not load file '%s'", path);
Blob* blob = lovrBlobCreate(data, size, path);
luax_pushobject(L, blob);
luax_pushtype(L, Blob, blob);
lovrRelease(Blob, blob);
return 1;
}

View File

@ -83,7 +83,7 @@ static int l_lovrFontSetPixelDensity(lua_State* L) {
static int l_lovrFontGetRasterizer(lua_State* L) {
Font* font = luax_checktype(L, 1, Font);
luax_pushobject(L, lovrFontGetRasterizer(font));
luax_pushtype(L, Rasterizer, lovrFontGetRasterizer(font));
return 1;
}

View File

@ -11,9 +11,11 @@
#include "data/rasterizer.h"
#include "data/textureData.h"
#include "filesystem/filesystem.h"
#include "core/ref.h"
#include "util.h"
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
const char* ArcModes[] = {
[ARC_MODE_PIE] = "pie",
@ -483,7 +485,7 @@ static int l_lovrGraphicsSetBlendMode(lua_State* L) {
static int l_lovrGraphicsGetCanvas(lua_State* L) {
Canvas* canvas = lovrGraphicsGetCanvas();
luax_pushobject(L, canvas);
luax_pushtype(L, Canvas, canvas);
return 1;
}
@ -554,7 +556,7 @@ static int l_lovrGraphicsSetDepthTest(lua_State* L) {
static int l_lovrGraphicsGetFont(lua_State* L) {
Font* font = lovrGraphicsGetFont();
luax_pushobject(L, font);
luax_pushtype(L, Font, font);
return 1;
}
@ -588,7 +590,7 @@ static int l_lovrGraphicsSetPointSize(lua_State* L) {
static int l_lovrGraphicsGetShader(lua_State* L) {
Shader* shader = lovrGraphicsGetShader();
luax_pushobject(L, shader);
luax_pushtype(L, Shader, shader);
return 1;
}
@ -955,7 +957,7 @@ static int l_lovrGraphicsCompute(lua_State* L) {
static int l_lovrGraphicsNewAnimator(lua_State* L) {
Model* model = luax_checktype(L, 1, Model);
Animator* animator = lovrAnimatorCreate(model->data);
luax_pushobject(L, animator);
luax_pushtype(L, Animator, animator);
lovrRelease(Animator, animator);
return 1;
}
@ -1042,7 +1044,7 @@ static int l_lovrGraphicsNewShaderBlock(lua_State* L) {
size_t size = lovrShaderComputeUniformLayout(&uniforms);
Buffer* buffer = lovrBufferCreate(size, NULL, type == BLOCK_COMPUTE ? BUFFER_SHADER_STORAGE : BUFFER_UNIFORM, usage, readable);
ShaderBlock* block = lovrShaderBlockCreate(type, buffer, &uniforms);
luax_pushobject(L, block);
luax_pushtype(L, ShaderBlock, block);
vec_deinit(&uniforms);
lovrRelease(Buffer, buffer);
lovrRelease(ShaderBlock, block);
@ -1142,7 +1144,7 @@ static int l_lovrGraphicsNewCanvas(lua_State* L) {
}
}
luax_pushobject(L, canvas);
luax_pushtype(L, Canvas, canvas);
lovrRelease(Canvas, canvas);
return 1;
}
@ -1166,7 +1168,7 @@ static int l_lovrGraphicsNewFont(lua_State* L) {
}
Font* font = lovrFontCreate(rasterizer);
luax_pushobject(L, font);
luax_pushtype(L, Font, font);
lovrRelease(Rasterizer, rasterizer);
lovrRelease(Font, font);
return 1;
@ -1197,7 +1199,7 @@ static int l_lovrGraphicsNewMaterial(lua_State* L) {
lovrMaterialSetColor(material, COLOR_DIFFUSE, color);
}
luax_pushobject(L, material);
luax_pushtype(L, Material, material);
lovrRelease(Material, material);
return 1;
}
@ -1340,7 +1342,7 @@ static int l_lovrGraphicsNewMesh(lua_State* L) {
lovrBufferUnmap(vertexBuffer);
lovrRelease(Buffer, vertexBuffer);
luax_pushobject(L, mesh);
luax_pushtype(L, Mesh, mesh);
lovrRelease(Mesh, mesh);
return 1;
}
@ -1355,7 +1357,7 @@ static int l_lovrGraphicsNewModel(lua_State* L) {
}
Model* model = lovrModelCreate(modelData);
luax_pushobject(L, model);
luax_pushtype(L, Model, model);
lovrRelease(ModelData, modelData);
lovrRelease(Model, model);
return 1;
@ -1455,7 +1457,7 @@ static int l_lovrGraphicsNewShader(lua_State* L) {
shader = lovrShaderCreateGraphics(vertexSource, fragmentSource, flags, flagCount);
}
luax_pushobject(L, shader);
luax_pushtype(L, Shader, shader);
lovrRelease(Shader, shader);
return 1;
}
@ -1473,7 +1475,7 @@ static int l_lovrGraphicsNewComputeShader(lua_State* L) {
}
Shader* shader = lovrShaderCreateCompute(source, flags, flagCount);
luax_pushobject(L, shader);
luax_pushtype(L, Shader, shader);
lovrRelease(Shader, shader);
return 1;
}
@ -1559,7 +1561,7 @@ static int l_lovrGraphicsNewTexture(lua_State* L) {
}
}
luax_pushobject(L, texture);
luax_pushtype(L, Texture, texture);
lovrRelease(Texture, texture);
return 1;
}

View File

@ -4,6 +4,8 @@
#include "graphics/model.h"
#include "graphics/texture.h"
#include "core/maf.h"
#include "core/ref.h"
#include <stdlib.h>
#if defined(EMSCRIPTEN) || defined(LOVR_USE_OCULUS_MOBILE)
#define LOVR_HEADSET_HELPER_USES_REGISTRY
@ -463,7 +465,7 @@ int l_lovrHeadsetNewModel(lua_State* L) {
if (modelData) {
Model* model = lovrModelCreate(modelData);
luax_pushobject(L, model);
luax_pushtype(L, Model, model);
lovrRelease(ModelData, modelData);
lovrRelease(Model, model);
return 1;
@ -512,7 +514,7 @@ static int l_lovrHeadsetGetMirrorTexture(lua_State* L) {
Texture *texture = NULL;
if (lovrHeadsetDriver->getMirrorTexture)
texture = lovrHeadsetDriver->getMirrorTexture();
luax_pushobject(L, texture);
luax_pushtype(L, Texture, texture);
return 1;
}

View File

@ -1,37 +1,55 @@
#include "api.h"
#include "physics/physics.h"
void luax_pushjoint(lua_State* L, Joint* joint) {
switch (joint->type) {
case JOINT_BALL: luax_pushtype(L, BallJoint, joint); break;
case JOINT_DISTANCE: luax_pushtype(L, DistanceJoint, joint); break;
case JOINT_HINGE: luax_pushtype(L, HingeJoint, joint); break;
case JOINT_SLIDER: luax_pushtype(L, SliderJoint, joint); break;
}
}
Joint* luax_checkjoint(lua_State* L, int index) {
Proxy* p = lua_touserdata(L, index);
if (!p || (p->hash != hash("BallJoint") && p->hash != hash("DistanceJoint") && p->hash != hash("HingeJoint") && p->hash != hash("SliderJoint"))) {
luaL_typerror(L, index, "Joint");
return NULL;
}
return p->object;
}
static int l_lovrJointDestroy(lua_State* L) {
Joint* joint = luax_checktype(L, 1, Joint);
Joint* joint = luax_checkjoint(L, 1);
lovrJointDestroyData(joint);
return 0;
}
static int l_lovrJointGetType(lua_State* L) {
Joint* joint = luax_checktype(L, 1, Joint);
Joint* joint = luax_checkjoint(L, 1);
lua_pushstring(L, JointTypes[lovrJointGetType(joint)]);
return 1;
}
static int l_lovrJointGetColliders(lua_State* L) {
Joint* joint = luax_checktype(L, 1, Joint);
Joint* joint = luax_checkjoint(L, 1);
Collider* a;
Collider* b;
lovrJointGetColliders(joint, &a, &b);
luax_pushobject(L, a);
luax_pushobject(L, b);
luax_pushtype(L, Collider, a);
luax_pushtype(L, Collider, b);
return 2;
}
static int l_lovrJointGetUserData(lua_State* L) {
Joint* joint = luax_checktype(L, 1, Joint);
Joint* joint = luax_checkjoint(L, 1);
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);
Joint* joint = luax_checkjoint(L, 1);
union { int i; void* p; } ref = { .p = lovrJointGetUserData(joint) };
if (ref.i) {
luaL_unref(L, LUA_REGISTRYINDEX, ref.i);
@ -47,14 +65,12 @@ static int l_lovrJointSetUserData(lua_State* L) {
return 0;
}
const luaL_Reg lovrJoint[] = {
{ "destroy", l_lovrJointDestroy },
{ "getType", l_lovrJointGetType },
{ "getColliders", l_lovrJointGetColliders },
{ "getUserData", l_lovrJointGetUserData },
{ "setUserData", l_lovrJointSetUserData },
{ NULL, NULL }
};
#define lovrJoint \
{ "destroy", l_lovrJointDestroy }, \
{ "getType", l_lovrJointGetType }, \
{ "getColliders", l_lovrJointGetColliders }, \
{ "getUserData", l_lovrJointGetUserData }, \
{ "setUserData", l_lovrJointSetUserData }
static int l_lovrBallJointGetAnchors(lua_State* L) {
BallJoint* joint = luax_checktype(L, 1, BallJoint);
@ -79,6 +95,7 @@ static int l_lovrBallJointSetAnchor(lua_State* L) {
}
const luaL_Reg lovrBallJoint[] = {
lovrJoint,
{ "getAnchors", l_lovrBallJointGetAnchors },
{ "setAnchor", l_lovrBallJointSetAnchor },
{ NULL, NULL }
@ -123,6 +140,7 @@ static int l_lovrDistanceJointSetDistance(lua_State* L) {
}
const luaL_Reg lovrDistanceJoint[] = {
lovrJoint,
{ "getAnchors", l_lovrDistanceJointGetAnchors },
{ "setAnchors", l_lovrDistanceJointSetAnchors },
{ "getDistance", l_lovrDistanceJointGetDistance },
@ -220,6 +238,7 @@ static int l_lovrHingeJointSetLimits(lua_State* L) {
}
const luaL_Reg lovrHingeJoint[] = {
lovrJoint,
{ "getAnchors", l_lovrHingeJointGetAnchors },
{ "setAnchor", l_lovrHingeJointSetAnchor },
{ "getAxis", l_lovrHingeJointGetAxis },
@ -302,6 +321,7 @@ static int l_lovrSliderJointSetLimits(lua_State* L) {
}
const luaL_Reg lovrSliderJoint[] = {
lovrJoint,
{ "getAxis", l_lovrSliderJointGetAxis },
{ "setAxis", l_lovrSliderJointSetAxis },
{ "getPosition", l_lovrSliderJointGetPosition },

View File

@ -47,7 +47,7 @@ static int l_lovrMaterialGetTexture(lua_State* L) {
Material* material = luax_checktype(L, 1, Material);
MaterialTexture textureType = luaL_checkoption(L, 2, "diffuse", MaterialTextures);
Texture* texture = lovrMaterialGetTexture(material, textureType);
luax_pushobject(L, texture);
luax_pushtype(L, Texture, texture);
return 1;
}

View File

@ -4,6 +4,8 @@
#include "math/pool.h"
#include "math/randomGenerator.h"
#include "resources/math.lua.h"
#include "core/ref.h"
#include <stdlib.h>
int l_lovrRandomGeneratorRandom(lua_State* L);
int l_lovrRandomGeneratorRandomNormal(lua_State* L);
@ -81,7 +83,7 @@ static int l_lovrMathNewCurve(lua_State* L) {
if (top == 1 && lua_type(L, 1) == LUA_TNUMBER) {
Curve* curve = lovrCurveCreate(luaL_checkinteger(L, 1));
luax_pushobject(L, curve);
luax_pushtype(L, Curve, curve);
return 1;
}
@ -109,7 +111,7 @@ static int l_lovrMathNewCurve(lua_State* L) {
}
}
luax_pushobject(L, curve);
luax_pushtype(L, Curve, curve);
lovrRelease(Curve, curve);
return 1;
}
@ -117,7 +119,7 @@ static int l_lovrMathNewCurve(lua_State* L) {
static int l_lovrMathNewPool(lua_State* L) {
size_t size = luaL_optinteger(L, 1, DEFAULT_POOL_SIZE);
Pool* pool = lovrPoolCreate(size);
luax_pushobject(L, pool);
luax_pushtype(L, Pool, pool);
lovrRelease(Pool, pool);
return 1;
}
@ -128,7 +130,7 @@ static int l_lovrMathNewRandomGenerator(lua_State* L) {
Seed seed = luax_checkrandomseed(L, 1);
lovrRandomGeneratorSetSeed(generator, seed);
}
luax_pushobject(L, generator);
luax_pushtype(L, RandomGenerator, generator);
lovrRelease(RandomGenerator, generator);
return 1;
}
@ -175,25 +177,25 @@ static int l_lovrMathNoise(lua_State* L) {
}
static int l_lovrMathRandom(lua_State* L) {
luax_pushobject(L, lovrMathGetRandomGenerator());
luax_pushtype(L, RandomGenerator, lovrMathGetRandomGenerator());
lua_insert(L, 1);
return l_lovrRandomGeneratorRandom(L);
}
static int l_lovrMathRandomNormal(lua_State* L) {
luax_pushobject(L, lovrMathGetRandomGenerator());
luax_pushtype(L, RandomGenerator, lovrMathGetRandomGenerator());
lua_insert(L, 1);
return l_lovrRandomGeneratorRandomNormal(L);
}
static int l_lovrMathGetRandomSeed(lua_State* L) {
luax_pushobject(L, lovrMathGetRandomGenerator());
luax_pushtype(L, RandomGenerator, lovrMathGetRandomGenerator());
lua_insert(L, 1);
return l_lovrRandomGeneratorGetSeed(L);
}
static int l_lovrMathSetRandomSeed(lua_State* L) {
luax_pushobject(L, lovrMathGetRandomGenerator());
luax_pushtype(L, RandomGenerator, lovrMathGetRandomGenerator());
lua_insert(L, 1);
return l_lovrRandomGeneratorSetSeed(L);
}

View File

@ -4,6 +4,7 @@
#include "graphics/material.h"
#include "graphics/mesh.h"
#include "data/blob.h"
#include "core/ref.h"
#include <limits.h>
static int l_lovrMeshAttachAttributes(lua_State* L) {
@ -485,7 +486,7 @@ static int l_lovrMeshSetDrawRange(lua_State* L) {
static int l_lovrMeshGetMaterial(lua_State* L) {
Mesh* mesh = luax_checktype(L, 1, Mesh);
Material* material = lovrMeshGetMaterial(mesh);
luax_pushobject(L, material);
luax_pushtype(L, Material, material);
return 1;
}

View File

@ -1,6 +1,7 @@
#include "api.h"
#include "audio/microphone.h"
#include "data/soundData.h"
#include "core/ref.h"
#include <stdlib.h>
static int l_lovrMicrophoneGetBitDepth(lua_State* L) {
@ -18,7 +19,7 @@ static int l_lovrMicrophoneGetChannelCount(lua_State* L) {
static int l_lovrMicrophoneGetData(lua_State* L) {
Microphone* microphone = luax_checktype(L, 1, Microphone);
SoundData* soundData = lovrMicrophoneGetData(microphone);
luax_pushobject(L, soundData);
luax_pushtype(L, SoundData, soundData);
lovrRelease(SoundData, soundData);
return 1;
}

View File

@ -14,7 +14,7 @@ static int l_lovrModelDraw(lua_State* L) {
static int l_lovrModelGetAnimator(lua_State* L) {
Model* model = luax_checktype(L, 1, Model);
luax_pushobject(L, lovrModelGetAnimator(model));
luax_pushtype(L, Aniamtor, lovrModelGetAnimator(model));
return 1;
}
@ -32,7 +32,7 @@ static int l_lovrModelSetAnimator(lua_State* L) {
static int l_lovrModelGetMaterial(lua_State* L) {
Model* model = luax_checktype(L, 1, Model);
Material* material = lovrModelGetMaterial(model);
luax_pushobject(L, material);
luax_pushtype(L, Material, material);
return 1;
}

View File

@ -1,5 +1,6 @@
#include "api.h"
#include "physics/physics.h"
#include "core/ref.h"
const char* ShapeTypes[] = {
[SHAPE_SPHERE] = "sphere",
@ -39,7 +40,7 @@ static int l_lovrPhysicsNewWorld(lua_State* L) {
tagCount = 0;
}
World* world = lovrWorldCreate(xg, yg, zg, allowSleep, tags, tagCount);
luax_pushobject(L, world);
luax_pushtype(L, World, world);
lovrRelease(World, world);
return 1;
}
@ -51,7 +52,7 @@ static int l_lovrPhysicsNewBallJoint(lua_State* L) {
float y = luax_checkfloat(L, 4);
float z = luax_checkfloat(L, 5);
BallJoint* joint = lovrBallJointCreate(a, b, x, y, z);
luax_pushobject(L, joint);
luax_pushtype(L, BallJoint, joint);
lovrRelease(Joint, joint);
return 1;
}
@ -61,7 +62,7 @@ static int l_lovrPhysicsNewBoxShape(lua_State* L) {
float y = luax_optfloat(L, 2, x);
float z = luax_optfloat(L, 3, x);
BoxShape* box = lovrBoxShapeCreate(x, y, z);
luax_pushobject(L, box);
luax_pushtype(L, BoxShape, box);
lovrRelease(Shape, box);
return 1;
}
@ -70,7 +71,7 @@ static int l_lovrPhysicsNewCapsuleShape(lua_State* L) {
float radius = luax_optfloat(L, 1, 1.f);
float length = luax_optfloat(L, 2, 1.f);
CapsuleShape* capsule = lovrCapsuleShapeCreate(radius, length);
luax_pushobject(L, capsule);
luax_pushtype(L, CapsuleShape, capsule);
lovrRelease(Shape, capsule);
return 1;
}
@ -79,7 +80,7 @@ static int l_lovrPhysicsNewCylinderShape(lua_State* L) {
float radius = luax_optfloat(L, 1, 1.f);
float length = luax_optfloat(L, 2, 1.f);
CylinderShape* cylinder = lovrCylinderShapeCreate(radius, length);
luax_pushobject(L, cylinder);
luax_pushtype(L, CylinderShape, cylinder);
lovrRelease(Shape, cylinder);
return 1;
}
@ -94,7 +95,7 @@ static int l_lovrPhysicsNewDistanceJoint(lua_State* L) {
float y2 = luax_checkfloat(L, 7);
float z2 = luax_checkfloat(L, 8);
DistanceJoint* joint = lovrDistanceJointCreate(a, b, x1, y1, z1, x2, y2, z2);
luax_pushobject(L, joint);
luax_pushtype(L, DistanceJoint, joint);
lovrRelease(Joint, joint);
return 1;
}
@ -109,7 +110,7 @@ static int l_lovrPhysicsNewHingeJoint(lua_State* L) {
float ay = luax_checkfloat(L, 7);
float az = luax_checkfloat(L, 8);
HingeJoint* joint = lovrHingeJointCreate(a, b, x, y, z, ax, ay, az);
luax_pushobject(L, joint);
luax_pushtype(L, HingeJoint, joint);
lovrRelease(Joint, joint);
return 1;
}
@ -121,7 +122,7 @@ static int l_lovrPhysicsNewSliderJoint(lua_State* L) {
float ay = luax_checkfloat(L, 4);
float az = luax_checkfloat(L, 5);
SliderJoint* joint = lovrSliderJointCreate(a, b, ax, ay, az);
luax_pushobject(L, joint);
luax_pushtype(L, SliderJoint, joint);
lovrRelease(Joint, joint);
return 1;
}
@ -129,7 +130,7 @@ static int l_lovrPhysicsNewSliderJoint(lua_State* L) {
static int l_lovrPhysicsNewSphereShape(lua_State* L) {
float radius = luax_optfloat(L, 1, 1.f);
SphereShape* sphere = lovrSphereShapeCreate(radius);
luax_pushobject(L, sphere);
luax_pushtype(L, SphereShape, sphere);
lovrRelease(Shape, sphere);
return 1;
}
@ -152,14 +153,14 @@ int luaopen_lovr_physics(lua_State* L) {
luaL_register(L, NULL, lovrPhysics);
luax_registertype(L, World);
luax_registertype(L, Collider);
luax_extendtype(L, Joint, BallJoint);
luax_extendtype(L, Joint, DistanceJoint);
luax_extendtype(L, Joint, HingeJoint);
luax_extendtype(L, Joint, SliderJoint);
luax_extendtype(L, Shape, SphereShape);
luax_extendtype(L, Shape, BoxShape);
luax_extendtype(L, Shape, CapsuleShape);
luax_extendtype(L, Shape, CylinderShape);
luax_registertype(L, BallJoint);
luax_registertype(L, DistanceJoint);
luax_registertype(L, HingeJoint);
luax_registertype(L, SliderJoint);
luax_registertype(L, SphereShape);
luax_registertype(L, BoxShape);
luax_registertype(L, CapsuleShape);
luax_registertype(L, CylinderShape);
if (lovrPhysicsInit()) {
luax_atexit(L, lovrPhysicsDestroy);
}

View File

@ -2,6 +2,7 @@
#include "graphics/buffer.h"
#include "graphics/shader.h"
#include "core/maf.h"
#include <stdlib.h>
struct TempData {
void* data;

View File

@ -1,6 +1,7 @@
#include "api.h"
#include "graphics/buffer.h"
#include "graphics/shader.h"
#include <stdlib.h>
static int l_lovrShaderBlockGetType(lua_State* L) {
ShaderBlock* block = luax_checktype(L, 1, ShaderBlock);

View File

@ -1,46 +1,64 @@
#include "api.h"
#include "physics/physics.h"
void luax_pushshape(lua_State* L, Shape* shape) {
switch (shape->type) {
case SHAPE_SPHERE: luax_pushtype(L, SphereShape, shape); break;
case SHAPE_BOX: luax_pushtype(L, BoxShape, shape); break;
case SHAPE_CAPSULE: luax_pushtype(L, CapsuleShape, shape); break;
case SHAPE_CYLINDER: luax_pushtype(L, CylinderShape, shape); break;
}
}
Shape* luax_checkshape(lua_State* L, int index) {
Proxy* p = lua_touserdata(L, index);
if (!p || (p->hash != hash("SphereShape") && p->hash != hash("BoxShape") && p->hash != hash("CapsuleShape") && p->hash != hash("CylinderShape"))) {
luaL_typerror(L, index, "Shape");
return NULL;
}
return p->object;
}
static int l_lovrShapeDestroy(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
lovrShapeDestroyData(shape);
return 0;
}
static int l_lovrShapeGetType(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
lua_pushstring(L, ShapeTypes[lovrShapeGetType(shape)]);
return 1;
}
static int l_lovrShapeGetCollider(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
luax_pushobject(L, lovrShapeGetCollider(shape));
Shape* shape = luax_checkshape(L, 1);
luax_pushtype(L, Collider, lovrShapeGetCollider(shape));
return 1;
}
static int l_lovrShapeIsEnabled(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
lua_pushboolean(L, lovrShapeIsEnabled(shape));
return 1;
}
static int l_lovrShapeSetEnabled(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
bool enabled = lua_toboolean(L, 2);
lovrShapeSetEnabled(shape, enabled);
return 0;
}
static int l_lovrShapeGetUserData(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
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);
Shape* shape = luax_checkshape(L, 1);
union { int i; void* p; } ref = { .p = lovrShapeGetUserData(shape) };
if (ref.i) {
luaL_unref(L, LUA_REGISTRYINDEX, ref.i);
@ -57,7 +75,7 @@ static int l_lovrShapeSetUserData(lua_State* L) {
}
static int l_lovrShapeGetPosition(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
float x, y, z;
lovrShapeGetPosition(shape, &x, &y, &z);
lua_pushnumber(L, x);
@ -67,7 +85,7 @@ static int l_lovrShapeGetPosition(lua_State* L) {
}
static int l_lovrShapeSetPosition(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
float x = luax_checkfloat(L, 2);
float y = luax_checkfloat(L, 3);
float z = luax_checkfloat(L, 4);
@ -76,7 +94,7 @@ static int l_lovrShapeSetPosition(lua_State* L) {
}
static int l_lovrShapeGetOrientation(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
float angle, x, y, z;
lovrShapeGetOrientation(shape, &angle, &x, &y, &z);
lua_pushnumber(L, angle);
@ -87,7 +105,7 @@ static int l_lovrShapeGetOrientation(lua_State* L) {
}
static int l_lovrShapeSetOrientation(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
float angle = luax_checkfloat(L, 2);
float x = luax_checkfloat(L, 3);
float y = luax_checkfloat(L, 4);
@ -97,7 +115,7 @@ static int l_lovrShapeSetOrientation(lua_State* L) {
}
static int l_lovrShapeGetMass(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
float density = luax_checkfloat(L, 2);
float cx, cy, cz, mass;
float inertia[6];
@ -115,7 +133,7 @@ static int l_lovrShapeGetMass(lua_State* L) {
}
static int l_lovrShapeGetAABB(lua_State* L) {
Shape* shape = luax_checktype(L, 1, Shape);
Shape* shape = luax_checkshape(L, 1);
float aabb[6];
lovrShapeGetAABB(shape, aabb);
for (int i = 0; i < 6; i++) {
@ -124,22 +142,20 @@ static int l_lovrShapeGetAABB(lua_State* L) {
return 6;
}
const luaL_Reg lovrShape[] = {
{ "destroy", l_lovrShapeDestroy },
{ "getType", l_lovrShapeGetType },
{ "getCollider", l_lovrShapeGetCollider },
{ "isEnabled", l_lovrShapeIsEnabled },
{ "setEnabled", l_lovrShapeSetEnabled },
{ "getUserData", l_lovrShapeGetUserData },
{ "setUserData", l_lovrShapeSetUserData },
{ "getPosition", l_lovrShapeGetPosition },
{ "setPosition", l_lovrShapeSetPosition },
{ "getOrientation", l_lovrShapeGetOrientation },
{ "setOrientation", l_lovrShapeSetOrientation },
{ "getMass", l_lovrShapeGetMass },
{ "getAABB", l_lovrShapeGetAABB },
{ NULL, NULL }
};
#define lovrShape \
{ "destroy", l_lovrShapeDestroy }, \
{ "getType", l_lovrShapeGetType }, \
{ "getCollider", l_lovrShapeGetCollider }, \
{ "isEnabled", l_lovrShapeIsEnabled }, \
{ "setEnabled", l_lovrShapeSetEnabled }, \
{ "getUserData", l_lovrShapeGetUserData }, \
{ "setUserData", l_lovrShapeSetUserData }, \
{ "getPosition", l_lovrShapeGetPosition }, \
{ "setPosition", l_lovrShapeSetPosition }, \
{ "getOrientation", l_lovrShapeGetOrientation }, \
{ "setOrientation", l_lovrShapeSetOrientation }, \
{ "getMass", l_lovrShapeGetMass }, \
{ "getAABB", l_lovrShapeGetAABB }
static int l_lovrSphereShapeGetRadius(lua_State* L) {
SphereShape* sphere = luax_checktype(L, 1, SphereShape);
@ -155,6 +171,7 @@ static int l_lovrSphereShapeSetRadius(lua_State* L) {
}
const luaL_Reg lovrSphereShape[] = {
lovrShape,
{ "getRadius", l_lovrSphereShapeGetRadius },
{ "setRadius", l_lovrSphereShapeSetRadius },
{ NULL, NULL }
@ -180,6 +197,7 @@ static int l_lovrBoxShapeSetDimensions(lua_State* L) {
}
const luaL_Reg lovrBoxShape[] = {
lovrShape,
{ "getDimensions", l_lovrBoxShapeGetDimensions },
{ "setDimensions", l_lovrBoxShapeSetDimensions },
{ NULL, NULL }
@ -212,6 +230,7 @@ static int l_lovrCapsuleShapeSetLength(lua_State* L) {
}
const luaL_Reg lovrCapsuleShape[] = {
lovrShape,
{ "getRadius", l_lovrCapsuleShapeGetRadius },
{ "setRadius", l_lovrCapsuleShapeSetRadius },
{ "getLength", l_lovrCapsuleShapeGetLength },
@ -246,6 +265,7 @@ static int l_lovrCylinderShapeSetLength(lua_State* L) {
}
const luaL_Reg lovrCylinderShape[] = {
lovrShape,
{ "getRadius", l_lovrCylinderShapeGetRadius },
{ "setRadius", l_lovrCylinderShapeSetRadius },
{ "getLength", l_lovrCylinderShapeGetLength },

View File

@ -46,6 +46,12 @@ static int l_lovrSoundDataSetSample(lua_State* L) {
return 0;
}
static int l_lovrSoundDataGetPointer(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
lua_pushlightuserdata(L, soundData->blob.data);
return 1;
}
const luaL_Reg lovrSoundData[] = {
{ "getBitDepth", l_lovrSoundDataGetBitDepth },
{ "getChannelCount", l_lovrSoundDataGetChannelCount },
@ -54,5 +60,6 @@ const luaL_Reg lovrSoundData[] = {
{ "getSampleCount", l_lovrSoundDataGetSampleCount },
{ "getSampleRate", l_lovrSoundDataGetSampleRate },
{ "setSample", l_lovrSoundDataSetSample },
{ "getPointer", l_lovrSoundDataGetPointer },
{ NULL, NULL }
};

View File

@ -60,6 +60,12 @@ static int l_lovrTextureDataSetPixel(lua_State* L) {
return 0;
}
static int l_lovrTextureDataGetPointer(lua_State* L) {
TextureData* textureData = luax_checktype(L, 1, TextureData);
lua_pushlightuserdata(L, textureData->blob.data);
return 1;
}
const luaL_Reg lovrTextureData[] = {
{ "encode", l_lovrTextureDataEncode },
{ "getWidth", l_lovrTextureDataGetWidth },
@ -68,5 +74,6 @@ const luaL_Reg lovrTextureData[] = {
{ "getFormat", l_lovrTextureDataGetFormat },
{ "getPixel", l_lovrTextureDataGetPixel },
{ "setPixel", l_lovrTextureDataSetPixel },
{ "getPointer", l_lovrTextureDataGetPointer },
{ NULL, NULL }
};

View File

@ -3,6 +3,8 @@
#include "filesystem/filesystem.h"
#include "thread/thread.h"
#include "thread/channel.h"
#include "core/ref.h"
#include <stdlib.h>
static int threadRunner(void* data) {
Thread* thread = (Thread*) data;
@ -16,7 +18,7 @@ static int threadRunner(void* data) {
// Lua state
lua_State* L = luaL_newstate();
luaL_openlibs(L);
lovrSetErrorCallback((lovrErrorHandler) luax_vthrow, L);
lovrSetErrorCallback((errorFn*) luax_vthrow, L);
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
@ -61,7 +63,7 @@ static int l_lovrThreadNewThread(lua_State* L) {
lovrRetain(blob);
}
Thread* thread = lovrThreadCreate(threadRunner, blob);
luax_pushobject(L, thread);
luax_pushtype(L, Thread, thread);
lovrRelease(Thread, thread);
lovrRelease(Blob, blob);
return 1;
@ -70,7 +72,7 @@ static int l_lovrThreadNewThread(lua_State* L) {
static int l_lovrThreadGetChannel(lua_State* L) {
const char* name = luaL_checkstring(L, 1);
Channel* channel = lovrThreadGetChannel(name);
luax_pushobject(L, channel);
luax_pushtype(L, Channel, channel);
return 1;
}

View File

@ -1,11 +1,12 @@
#include "api.h"
#include "physics/physics.h"
#include "core/ref.h"
#include <stdbool.h>
static void collisionResolver(World* world, void* userdata) {
lua_State* L = userdata;
luaL_checktype(L, -1, LUA_TFUNCTION);
luax_pushobject(L, world);
luax_pushtype(L, World, world);
lua_call(L, 1, 0);
}
@ -14,8 +15,8 @@ static int nextOverlap(lua_State* L) {
Shape* a;
Shape* b;
if (lovrWorldGetNextOverlap(world, &a, &b)) {
luax_pushobject(L, a);
luax_pushobject(L, b);
luax_pushshape(L, a);
luax_pushshape(L, b);
return 2;
} else {
lua_pushnil(L);
@ -27,7 +28,7 @@ static void raycastCallback(Shape* shape, float x, float y, float z, float nx, f
lua_State* L = userdata;
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, -1);
luax_pushobject(L, shape);
luax_pushshape(L, shape);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, z);
@ -43,7 +44,7 @@ static int l_lovrWorldNewCollider(lua_State* L) {
float y = luax_optfloat(L, 3, 0.f);
float z = luax_optfloat(L, 4, 0.f);
Collider* collider = lovrColliderCreate(world, x, y, z);
luax_pushobject(L, collider);
luax_pushtype(L, Collider, collider);
lovrRelease(Collider, collider);
return 1;
}
@ -59,7 +60,7 @@ static int l_lovrWorldNewBoxCollider(lua_State* L) {
Collider* collider = lovrColliderCreate(world, x, y, z);
BoxShape* shape = lovrBoxShapeCreate(sx, sy, sz);
lovrColliderAddShape(collider, shape);
luax_pushobject(L, collider);
luax_pushtype(L, Collider, collider);
lovrRelease(Collider, collider);
lovrRelease(Shape, shape);
return 1;
@ -75,7 +76,7 @@ static int l_lovrWorldNewCapsuleCollider(lua_State* L) {
Collider* collider = lovrColliderCreate(world, x, y, z);
CapsuleShape* shape = lovrCapsuleShapeCreate(radius, length);
lovrColliderAddShape(collider, shape);
luax_pushobject(L, collider);
luax_pushtype(L, Collider, collider);
lovrRelease(Collider, collider);
lovrRelease(Shape, shape);
return 1;
@ -91,7 +92,7 @@ static int l_lovrWorldNewCylinderCollider(lua_State* L) {
Collider* collider = lovrColliderCreate(world, x, y, z);
CylinderShape* shape = lovrCylinderShapeCreate(radius, length);
lovrColliderAddShape(collider, shape);
luax_pushobject(L, collider);
luax_pushtype(L, Collider, collider);
lovrRelease(Collider, collider);
lovrRelease(Shape, shape);
return 1;
@ -106,7 +107,7 @@ static int l_lovrWorldNewSphereCollider(lua_State* L) {
Collider* collider = lovrColliderCreate(world, x, y, z);
SphereShape* shape = lovrSphereShapeCreate(radius);
lovrColliderAddShape(collider, shape);
luax_pushobject(L, collider);
luax_pushtype(L, Collider, collider);
lovrRelease(Collider, collider);
lovrRelease(Shape, shape);
return 1;

View File

@ -1,4 +1,5 @@
#include "luax.h"
#include "core/ref.h"
#include "platform.h"
#include "util.h"
#include "lib/sds/sds.h"
@ -8,6 +9,7 @@
static int luax_meta__tostring(lua_State* L) {
lua_getfield(L, -1, "name");
lua_pushstring(L, (const char*) lua_touserdata(L, -1));
return 1;
}
@ -16,9 +18,9 @@ static int luax_meta__gc(lua_State* L) {
if (p) {
lua_getmetatable(L, 1);
lua_getfield(L, -1, "__destructor");
lovrDestructor* destructor = (lovrDestructor*) lua_tocfunction(L, -1);
destructorFn* destructor = (destructorFn*) lua_tocfunction(L, -1);
if (destructor) {
_lovrRelease(destructor, p->object);
_lovrRelease(p->object, destructor);
}
}
return 0;
@ -28,87 +30,14 @@ static int luax_module__gc(lua_State* L) {
lua_getfield(L, LUA_REGISTRYINDEX, "_lovrmodules");
for (int i = luax_len(L, 2); i >= 1; i--) {
lua_rawgeti(L, 2, i);
luax_destructor destructor = (luax_destructor) lua_tocfunction(L, -1);
voidFn* destructor = (voidFn*) lua_tocfunction(L, -1);
destructor();
lua_pop(L, 1);
}
return 0;
}
// A version of print that uses lovrLog, for platforms that need it (Android)
int luax_print(lua_State* L) {
sds str = sdsempty();
int n = lua_gettop(L); /* number of arguments */
int i;
lua_getglobal(L, "tostring");
for (i=1; i<=n; i++) {
const char *s;
lua_pushvalue(L, -1); /* function to be called */
lua_pushvalue(L, i); /* value to print */
lua_call(L, 1, 1);
s = lua_tostring(L, -1); /* get result */
if (s == NULL)
return luaL_error(L, LUA_QL("tostring") " must return a string to "
LUA_QL("print"));
if (i>1) str = sdscat(str, "\t");
str = sdscat(str, s);
lua_pop(L, 1); /* pop result */
}
lovrLog("%s", str);
sdsfree(str);
return 0;
}
void luax_setmainthread(lua_State *L) {
#if LUA_VERSION_NUM < 502
lua_pushthread(L);
lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD);
#endif
}
void luax_atexit(lua_State* L, luax_destructor destructor) {
lua_getfield(L, LUA_REGISTRYINDEX, "_lovrmodules");
if (lua_isnil(L, -1)) {
lua_newtable(L);
lua_replace(L, -2);
// Userdata sentinel since tables don't have __gc (yet)
lua_newuserdata(L, sizeof(void*));
lua_createtable(L, 0, 1);
lua_pushcfunction(L, luax_module__gc);
lua_setfield(L, -2, "__gc");
lua_setmetatable(L, -2);
lua_setfield(L, -2, "");
// Write to the registry
lua_pushvalue(L, -1);
lua_setfield(L, LUA_REGISTRYINDEX, "_lovrmodules");
}
int length = luax_len(L, -1);
lua_pushcfunction(L, (lua_CFunction) destructor);
lua_rawseti(L, -2, length + 1);
lua_pop(L, 1);
}
void luax_registerloader(lua_State* L, lua_CFunction loader, int index) {
lua_getglobal(L, "table");
lua_getfield(L, -1, "insert");
lua_getglobal(L, "package");
lua_getfield(L, -1, "loaders");
lua_remove(L, -2);
if (lua_istable(L, -1)) {
lua_pushinteger(L, index);
lua_pushcfunction(L, loader);
lua_call(L, 3, 0);
}
lua_pop(L, 1);
}
void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions, lovrDestructor* destructor) {
void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions, destructorFn* destructor) {
// Push metatable
luaL_newmetatable(L, name);
@ -126,9 +55,9 @@ void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* function
lua_pushcfunction(L, (lua_CFunction) destructor);
lua_setfield(L, -2, "__destructor");
// m.name = name
lua_pushstring(L, name);
lua_setfield(L, -2, "name");
// m.__name = name
lua_pushlightuserdata(L, (void*) name);
lua_setfield(L, -2, "__name");
// m.__tostring
lua_pushcfunction(L, luax_meta__tostring);
@ -143,25 +72,18 @@ void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* function
lua_pop(L, 1);
}
void _luax_extendtype(lua_State* L, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions, lovrDestructor* destructor) {
_luax_registertype(L, name, functions, destructor);
luaL_getmetatable(L, name);
luaL_register(L, NULL, baseFunctions);
lua_pop(L, 1);
}
void* _luax_totype(lua_State* L, int index, Type type) {
void* _luax_totype(lua_State* L, int index, uint32_t hash) {
Proxy* p = lua_touserdata(L, index);
if (p && (p->type == type || lovrTypeInfo[p->type].super == type)) {
if (p && p->hash == hash) {
return p->object;
}
return NULL;
}
void* _luax_checktype(lua_State* L, int index, Type type, const char* debug) {
void* object = _luax_totype(L, index, type);
void* _luax_checktype(lua_State* L, int index, uint32_t hash, const char* debug) {
void* object = _luax_totype(L, index, hash);
if (!object) {
luaL_typerror(L, index, debug);
@ -171,7 +93,7 @@ void* _luax_checktype(lua_State* L, int index, Type type, const char* debug) {
}
// Registers the userdata on the top of the stack in the registry.
void luax_pushobject(lua_State* L, void* object) {
void _luax_pushtype(lua_State* L, const char* type, uint32_t hash, void* object) {
if (!object) {
lua_pushnil(L);
return;
@ -210,13 +132,12 @@ void luax_pushobject(lua_State* L, void* object) {
}
// Allocate userdata
Ref* ref = _ref(object);
Proxy* p = (Proxy*) lua_newuserdata(L, sizeof(Proxy));
luaL_getmetatable(L, lovrTypeInfo[ref->type].name);
luaL_getmetatable(L, type);
lua_setmetatable(L, -2);
lovrRetain(object);
p->type = ref->type;
p->object = object;
p->hash = hash;
// Write to registry and remove registry, leaving userdata on stack
lua_pushlightuserdata(L, object);
@ -225,6 +146,20 @@ void luax_pushobject(lua_State* L, void* object) {
lua_remove(L, -2);
}
void luax_registerloader(lua_State* L, lua_CFunction loader, int index) {
lua_getglobal(L, "table");
lua_getfield(L, -1, "insert");
lua_getglobal(L, "package");
lua_getfield(L, -1, "loaders");
lua_remove(L, -2);
if (lua_istable(L, -1)) {
lua_pushinteger(L, index);
lua_pushcfunction(L, loader);
lua_call(L, 3, 0);
}
lua_pop(L, 1);
}
void luax_vthrow(lua_State* L, const char* format, va_list args) {
lua_pushvfstring(L, format, args);
lua_error(L);
@ -257,6 +192,32 @@ int luax_getstack(lua_State *L) {
return 1;
}
// A version of print that uses lovrLog, for platforms that need it (Android)
int luax_print(lua_State* L) {
sds str = sdsempty();
int n = lua_gettop(L); /* number of arguments */
int i;
lua_getglobal(L, "tostring");
for (i=1; i<=n; i++) {
const char *s;
lua_pushvalue(L, -1); /* function to be called */
lua_pushvalue(L, i); /* value to print */
lua_call(L, 1, 1);
s = lua_tostring(L, -1); /* get result */
if (s == NULL)
return luaL_error(L, LUA_QL("tostring") " must return a string to "
LUA_QL("print"));
if (i>1) str = sdscat(str, "\t");
str = sdscat(str, s);
lua_pop(L, 1); /* pop result */
}
lovrLog("%s", str);
sdsfree(str);
return 0;
}
void luax_pushconf(lua_State* L) {
lua_getfield(L, LUA_REGISTRYINDEX, "_lovrconf");
}
@ -269,6 +230,39 @@ int luax_setconf(lua_State* L) {
return 0;
}
void luax_setmainthread(lua_State *L) {
#if LUA_VERSION_NUM < 502
lua_pushthread(L);
lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD);
#endif
}
void luax_atexit(lua_State* L, voidFn* destructor) {
lua_getfield(L, LUA_REGISTRYINDEX, "_lovrmodules");
if (lua_isnil(L, -1)) {
lua_newtable(L);
lua_replace(L, -2);
// Userdata sentinel since tables don't have __gc (yet)
lua_newuserdata(L, sizeof(void*));
lua_createtable(L, 0, 1);
lua_pushcfunction(L, luax_module__gc);
lua_setfield(L, -2, "__gc");
lua_setmetatable(L, -2);
lua_setfield(L, -2, "");
// Write to the registry
lua_pushvalue(L, -1);
lua_setfield(L, LUA_REGISTRYINDEX, "_lovrmodules");
}
int length = luax_len(L, -1);
lua_pushcfunction(L, (lua_CFunction) destructor);
lua_rawseti(L, -2, length + 1);
lua_pop(L, 1);
}
void luax_readcolor(lua_State* L, int index, Color* color) {
color->r = color->g = color->b = color->a = 1.f;

View File

@ -1,14 +1,14 @@
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "types.h"
#include "util.h"
#pragma once
struct Color;
typedef struct {
Type type;
uint32_t hash;
void* object;
} Proxy;
@ -18,29 +18,26 @@ typedef struct {
#define luax_len(L, i) (int) lua_objlen(L, i)
#define luax_registertype(L, T) _luax_registertype(L, #T, lovr ## T, lovr ## T ## Destroy)
#define luax_extendtype(L, S, T) _luax_extendtype(L, #T, lovr ## S, lovr ## T, lovr ## T ## Destroy)
#define luax_totype(L, i, T) ((T*) _luax_totype(L, i, T_ ## T))
#define luax_checktype(L, i, T) ((T*) _luax_checktype(L, i, T_ ## T, #T))
#define luax_totype(L, i, T) (T*) _luax_totype(L, i, hash(#T))
#define luax_checktype(L, i, T) (T*) _luax_checktype(L, i, hash(#T), #T)
#define luax_pushtype(L, T, o) _luax_pushtype(L, #T, hash(#T), o)
#define luax_checkfloat(L, i) (float) luaL_checknumber(L, i)
#define luax_optfloat(L, i, x) (float) luaL_optnumber(L, i, x)
#define luax_geterror(L) lua_getfield(L, LUA_REGISTRYINDEX, "_lovrerror")
#define luax_seterror(L) lua_setfield(L, LUA_REGISTRYINDEX, "_lovrerror")
#define luax_clearerror(L) lua_pushnil(L), luax_seterror(L)
typedef void (*luax_destructor)(void);
int luax_print(lua_State* L);
void luax_setmainthread(lua_State* L);
void luax_atexit(lua_State* L, luax_destructor destructor);
void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions, destructorFn* destructor);
void* _luax_totype(lua_State* L, int index, uint32_t hash);
void* _luax_checktype(lua_State* L, int index, uint32_t hash, const char* debug);
void _luax_pushtype(lua_State* L, const char* name, uint32_t hash, void* object);
void luax_registerloader(lua_State* L, lua_CFunction loader, int index);
void _luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions, lovrDestructor* destructor);
void _luax_extendtype(lua_State* L, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions, lovrDestructor* destructor);
void* _luax_totype(lua_State* L, int index, Type type);
void* _luax_checktype(lua_State* L, int index, Type type, const char* debug);
void luax_pushobject(lua_State* L, void* object);
void luax_vthrow(lua_State* L, const char* format, va_list args);
void luax_traceback(lua_State* L, lua_State* T, const char* message, int level);
int luax_getstack(lua_State* L);
int luax_getstack_panic(lua_State *L);
int luax_print(lua_State* L);
void luax_pushconf(lua_State* L);
int luax_setconf(lua_State* L);
void luax_setmainthread(lua_State* L);
void luax_atexit(lua_State* L, voidFn* destructor);
void luax_readcolor(lua_State* L, int index, struct Color* color);

View File

@ -1,5 +1,3 @@
#include "util.h"
#pragma once
#ifdef _WIN32

9
src/core/ref.c Normal file
View File

@ -0,0 +1,9 @@
#include "ref.h"
#include "util.h"
#include <stdlib.h>
void* _lovrAlloc(size_t size) {
Ref* ref = calloc(1, sizeof(Ref) + size);
lovrAssert(ref, "Out of memory");
return *ref = 1, ref + 1;
}

33
src/core/ref.h Normal file
View File

@ -0,0 +1,33 @@
#include <stdint.h>
#include <stddef.h>
#pragma once
#if defined(LOVR_ENABLE_THREAD) && defined(_WIN32)
#include <intrin.h>
typedef uint32_t Ref;
static inline uint32_t ref_inc(Ref* ref) { return _InterlockedIncrement(ref); }
static inline uint32_t ref_dec(Ref* ref) { return _InterlockedDecrement(ref); }
#elif defined(LOVR_ENABLE_THREAD)
#include <stdatomic.h>
typedef _Atomic(uint32_t) Ref;
static inline uint32_t ref_inc(Ref* ref) { return atomic_fetch_add(ref, 1) + 1; }
static inline uint32_t ref_dec(Ref* ref) { return atomic_fetch_sub(ref, 1) - 1; }
#else
typedef uint32_t Ref;
static inline uint32_t ref_inc(Ref* ref) { return ++ref; }
static inline uint32_t ref_dec(Ref* ref) { return --ref; }
#endif
void* _lovrAlloc(size_t size);
#define toRef(o) (Ref*) (o) - 1
#define lovrAlloc(T) (T*) _lovrAlloc(sizeof(T))
#define lovrRetain(o) o && !ref_inc(toRef(o))
#define lovrRelease(T, o) if (o && !ref_dec(toRef(o))) lovr ## T ## Destroy(o), free(toRef(o));
#define _lovrRelease(o, f) if (o && !ref_dec(toRef(o))) f(o), free(toRef(o));

View File

@ -1,90 +0,0 @@
#include "types.h"
#include "util.h"
#include <stdlib.h>
void lovrAnimatorDestroy(void*);
void lovrAudioStreamDestroy(void*);
void lovrBlobDestroy(void*);
void lovrBufferDestroy(void*);
void lovrCanvasDestroy(void*);
#ifdef LOVR_ENABLE_THREAD
void lovrChannelDestroy(void*);
#endif
void lovrColliderDestroy(void*);
void lovrCurveDestroy(void*);
void lovrFileDestroy(void*);
void lovrFontDestroy(void*);
void lovrJointDestroy(void*);
void lovrMaterialDestroy(void*);
void lovrMeshDestroy(void*);
void lovrMicrophoneDestroy(void*);
void lovrModelDestroy(void*);
void lovrModelDataDestroy(void*);
void lovrPoolDestroy(void*);
void lovrRandomGeneratorDestroy(void*);
void lovrRasterizerDestroy(void*);
void lovrShaderDestroy(void*);
void lovrShaderBlockDestroy(void*);
void lovrShapeDestroy(void*);
void lovrSoundDataDestroy(void*);
void lovrSourceDestroy(void*);
void lovrTextureDestroy(void*);
void lovrTextureDataDestroy(void*);
#ifdef LOVR_ENABLE_THREAD
void lovrThreadDestroy(void*);
#endif
void lovrWorldDestroy(void*);
#define INFO(T) [T_ ## T] = { #T, lovr ## T ## Destroy, T_NONE }
#define SUPERINFO(T, S) [T_ ## T] = { #T, lovr ## S ## Destroy, T_ ## S }
const TypeInfo lovrTypeInfo[T_MAX] = {
INFO(Animator),
INFO(AudioStream),
SUPERINFO(BallJoint, Joint),
INFO(Blob),
SUPERINFO(BoxShape, Shape),
INFO(Buffer),
INFO(Canvas),
SUPERINFO(CapsuleShape, Shape),
#ifdef LOVR_ENABLE_THREAD
INFO(Channel),
#endif
INFO(Collider),
INFO(Curve),
SUPERINFO(CylinderShape, Shape),
SUPERINFO(DistanceJoint, Joint),
INFO(File),
INFO(Font),
SUPERINFO(HingeJoint, Joint),
INFO(Joint),
INFO(Material),
INFO(Mesh),
INFO(Microphone),
INFO(Model),
INFO(ModelData),
INFO(Pool),
INFO(RandomGenerator),
INFO(Rasterizer),
INFO(Shader),
INFO(ShaderBlock),
INFO(Shape),
SUPERINFO(SliderJoint, Joint),
INFO(SoundData),
INFO(Source),
SUPERINFO(SphereShape, Shape),
INFO(Texture),
INFO(TextureData),
#ifdef LOVR_ENABLE_THREAD
INFO(Thread),
#endif
INFO(World)
};
#undef INFO
#undef SUPERINFO
void* _lovrAlloc(size_t size, Type type) {
Ref* ref = calloc(1, sizeof(Ref) + size);
lovrAssert(ref, "Out of memory");
ref->type = type;
ref->count = 1;
return ref + 1;
}

View File

@ -1,89 +0,0 @@
#include <stddef.h>
#pragma once
typedef enum {
T_NONE = 0,
T_vec3,
T_quat,
T_mat4,
T_Animator,
T_AudioStream,
T_BallJoint,
T_Blob,
T_BoxShape,
T_Buffer,
T_Canvas,
T_CapsuleShape,
T_Channel,
T_Collider,
T_Curve,
T_CylinderShape,
T_DistanceJoint,
T_File,
T_Font,
T_HingeJoint,
T_Joint,
T_Material,
T_Mesh,
T_Microphone,
T_Model,
T_ModelData,
T_Pool,
T_RandomGenerator,
T_Rasterizer,
T_Shader,
T_ShaderBlock,
T_Shape,
T_SliderJoint,
T_SoundData,
T_Source,
T_SphereShape,
T_Texture,
T_TextureData,
T_Thread,
T_World,
T_MAX
} Type;
typedef void lovrDestructor(void*);
typedef struct {
const char* name;
lovrDestructor* destructor;
Type super;
} TypeInfo;
extern const TypeInfo lovrTypeInfo[T_MAX];
// If the thread module is enabled, we have to use atomic operations when modifying refcounts, which
// are a bit slower and vary depending on the platform.
#ifdef LOVR_ENABLE_THREAD
#ifdef _WIN32
#include <intrin.h>
#define Refcount int
#define refcount_increment(c) _InterlockedIncrement(&c)
#define refcount_decrement(c) _InterlockedDecrement(&c)
#else
#include <stdatomic.h>
#define Refcount _Atomic int
#define refcount_increment(c) (atomic_fetch_add(&c, 1) + 1)
#define refcount_decrement(c) (atomic_fetch_sub(&c, 1) - 1)
#endif
#else
#define Refcount int
#define refcount_increment(c) ++c
#define refcount_decrement(c) --c
#endif
typedef struct Ref {
Type type;
Refcount count;
} Ref;
void* _lovrAlloc(size_t size, Type type);
#define _ref(o) ((Ref*) o - 1)
#define lovrAlloc(T) (T*) _lovrAlloc(sizeof(T), T_ ## T)
#define lovrRetain(o) if (o && refcount_increment(_ref(o)->count) >= 0xff) lovrThrow("Ref count overflow")
#define lovrRelease(T, o) if (o && refcount_decrement(_ref(o)->count) == 0) lovr ## T ## Destroy(o), free(_ref(o))
#define lovrGenericRelease(o) if (o && refcount_decrement(_ref(o)->count) == 0) lovrTypeInfo[_ref(o)->type].destructor(o), free(_ref(o))
#define _lovrRelease(f, o) if (o && refcount_decrement(_ref(o)->count) == 0) f(o), free(_ref(o))

View File

@ -2,10 +2,10 @@
#include "platform.h"
#include <stdlib.h>
LOVR_THREAD_LOCAL lovrErrorHandler lovrErrorCallback = NULL;
LOVR_THREAD_LOCAL errorFn* lovrErrorCallback = NULL;
LOVR_THREAD_LOCAL void* lovrErrorUserdata = NULL;
void lovrSetErrorCallback(lovrErrorHandler callback, void* userdata) {
void lovrSetErrorCallback(errorFn* callback, void* userdata) {
lovrErrorCallback = callback;
lovrErrorUserdata = userdata;
}
@ -28,3 +28,10 @@ void lovrThrow(const char* format, ...) {
}
}
uint32_t hash(const char* str) {
uint32_t x = 0;
while (*str) {
x = (x * 65599) + *str++;
}
return x;
}

View File

@ -1,4 +1,6 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#pragma once
@ -25,11 +27,16 @@
typedef struct Color { float r, g, b, a; } Color;
typedef void (*lovrErrorHandler)(void* userdata, const char* format, va_list args);
extern LOVR_THREAD_LOCAL lovrErrorHandler lovrErrorCallback;
typedef void voidFn(void);
typedef void destructorFn(void*);
typedef void errorFn(void*, const char*, va_list);
extern LOVR_THREAD_LOCAL errorFn* lovrErrorCallback;
extern LOVR_THREAD_LOCAL void* lovrErrorUserdata;
void lovrSetErrorCallback(lovrErrorHandler callback, void* context);
void lovrSetErrorCallback(errorFn* callback, void* context);
void LOVR_NORETURN lovrThrow(const char* format, ...);
#define lovrAssert(c, ...) if (!(c)) { lovrThrow(__VA_ARGS__); }
uint32_t hash(const char* str);

View File

@ -73,7 +73,7 @@ int main(int argc, char** argv) {
return 1;
}
lovrSetErrorCallback((lovrErrorHandler) luax_vthrow, T);
lovrSetErrorCallback((errorFn*) luax_vthrow, T);
#ifdef EMSCRIPTEN
lovrEmscriptenContext context = { L, T, argc, argv };

View File

@ -2,9 +2,9 @@
#include "audio/source.h"
#include "data/audioStream.h"
#include "core/maf.h"
#include "lib/vec/vec.h"
#include "types.h"
#include "core/ref.h"
#include "util.h"
#include "lib/vec/vec.h"
#include <stdlib.h>
#include <AL/al.h>
#include <AL/alc.h>

View File

@ -1,7 +1,7 @@
#include "audio/microphone.h"
#include "audio/audio.h"
#include "data/soundData.h"
#include "types.h"
#include "core/ref.h"
#include "util.h"
#include <AL/al.h>
#include <AL/alc.h>

View File

@ -3,7 +3,8 @@
#include "data/audioStream.h"
#include "data/soundData.h"
#include "core/maf.h"
#include "types.h"
#include "core/ref.h"
#include "core/util.h"
#include <math.h>
#include <stdlib.h>
#include <AL/al.h>

View File

@ -1,7 +1,7 @@
#include "data/audioStream.h"
#include "data/blob.h"
#include "core/ref.h"
#include "lib/stb/stb_vorbis.h"
#include "types.h"
#include "util.h"
#include <stdlib.h>

View File

@ -1,6 +1,8 @@
#include "data/modelData.h"
#include "data/blob.h"
#include "data/textureData.h"
#include "core/ref.h"
#include <stdlib.h>
ModelData* lovrModelDataInit(ModelData* model, Blob* source) {
if (lovrModelDataInitGltf(model, source)) {

View File

@ -3,10 +3,10 @@
#include "data/textureData.h"
#include "filesystem/filesystem.h"
#include "core/maf.h"
#include "core/ref.h"
#include "lib/jsmn/jsmn.h"
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

View File

@ -3,9 +3,11 @@
#include "data/textureData.h"
#include "filesystem/filesystem.h"
#include "core/maf.h"
#include "core/ref.h"
#include "lib/map/map.h"
#include "lib/vec/vec.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
typedef vec_t(ModelMaterial) vec_material_t;

View File

@ -2,6 +2,7 @@
#include "data/blob.h"
#include "data/textureData.h"
#include "resources/VarelaRound.ttf.h"
#include "core/ref.h"
#include "core/utf.h"
#include "lib/stb/stb_truetype.h"
#include "msdfgen-c.h"

View File

@ -1,5 +1,6 @@
#include "data/textureData.h"
#include "filesystem/file.h"
#include "core/ref.h"
#include "lib/stb/stb_image.h"
#include "lib/stb/stb_image_write.h"
#include <stdlib.h>

View File

@ -1,5 +1,4 @@
#include "data/blob.h"
#include "types.h"
#include "util.h"
#include "lib/vec/vec.h"
#include <stdint.h>

View File

@ -1,6 +1,6 @@
#include "event/event.h"
#include "platform.h"
#include "types.h"
#include "core/ref.h"
#include "lib/vec/vec.h"
#include <stdlib.h>
#include <string.h>
@ -14,7 +14,7 @@ static struct {
void lovrVariantDestroy(Variant* variant) {
switch (variant->type) {
case TYPE_STRING: free(variant->value.string); return;
case TYPE_OBJECT: lovrGenericRelease(variant->value.object); return;
case TYPE_OBJECT: _lovrRelease(variant->value.object.pointer, variant->value.object.destructor); return;
default: return;
}
}

View File

@ -26,7 +26,11 @@ typedef union {
bool boolean;
double number;
char* string;
void* object;
struct {
void* pointer;
const char* type;
void (*destructor)(void*);
} object;
} VariantValue;
typedef struct Variant {

View File

@ -1,7 +1,6 @@
#include "filesystem/file.h"
#include "util.h"
#include <physfs.h>
#include <stdlib.h>
File* lovrFileInit(File* file ,const char* path) {
file->path = path;

View File

@ -1,7 +1,7 @@
#include "graphics/animator.h"
#include "data/modelData.h"
#include "core/maf.h"
#include "types.h"
#include "core/ref.h"
#include <stdlib.h>
#include <math.h>

View File

@ -1,5 +1,7 @@
#include "graphics/canvas.h"
#include "graphics/graphics.h"
#include "core/ref.h"
#include <stdlib.h>
const Attachment* lovrCanvasGetAttachments(Canvas* canvas, uint32_t* count) {
if (count) *count = canvas->attachmentCount;

View File

@ -1,6 +1,7 @@
#include "graphics/font.h"
#include "graphics/texture.h"
#include "data/textureData.h"
#include "core/ref.h"
#include "core/utf.h"
#include <string.h>
#include <stdlib.h>

View File

@ -8,6 +8,7 @@
#include "event/event.h"
#include "math/math.h"
#include "core/maf.h"
#include "core/ref.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>

View File

@ -3,6 +3,7 @@
#include "graphics/shader.h"
#include "graphics/texture.h"
#include "resources/shaders.h"
#include "core/ref.h"
#include <stdlib.h>
#include <math.h>

View File

@ -2,6 +2,8 @@
#include "graphics/buffer.h"
#include "graphics/graphics.h"
#include "graphics/material.h"
#include "core/ref.h"
#include <stdlib.h>
Buffer* lovrMeshGetVertexBuffer(Mesh* mesh) {
return mesh->vertexBuffer;

View File

@ -5,6 +5,8 @@
#include "graphics/material.h"
#include "graphics/mesh.h"
#include "resources/shaders.h"
#include "core/ref.h"
#include <stdlib.h>
#include <float.h>
static void updateGlobalNodeTransform(Model* model, uint32_t nodeIndex, mat4 transform) {

View File

@ -8,6 +8,7 @@
#include "graphics/texture.h"
#include "resources/shaders.h"
#include "data/modelData.h"
#include "core/ref.h"
#include "lib/map/map.h"
#include "lib/vec/vec.h"
#include <math.h>

View File

@ -3,7 +3,8 @@
#include "graphics/buffer.h"
#include "math/math.h"
#include "resources/shaders.h"
#include "types.h"
#include "core/ref.h"
#include <stdlib.h>
#include <math.h>
static size_t getUniformTypeLength(const Uniform* uniform) {

View File

@ -3,7 +3,6 @@
#include "core/maf.h"
#include "platform.h"
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>

View File

@ -1,5 +1,6 @@
#include "math/curve.h"
#include "types.h"
#include "core/ref.h"
#include "core/util.h"
#include <math.h>
// Explicit curve evaluation, unroll simple cases to avoid pow overhead

View File

@ -1,7 +1,7 @@
#include "math.h"
#include "core/maf.h"
#include "core/ref.h"
#include "lib/noise1234/noise1234.h"
#include "types.h"
#include "util.h"
#include <math.h>
#include <string.h>

View File

@ -1,6 +1,7 @@
#include "physics.h"
#include "core/maf.h"
#include "types.h"
#include "core/ref.h"
#include "core/util.h"
#include <stdlib.h>
#include <stdbool.h>

View File

@ -49,7 +49,7 @@ struct Collider {
float restitution;
};
typedef struct {
typedef struct Shape {
ShapeType type;
dGeomID id;
Collider* collider;
@ -61,7 +61,7 @@ typedef Shape BoxShape;
typedef Shape CapsuleShape;
typedef Shape CylinderShape;
typedef struct {
typedef struct Joint {
JointType type;
dJointID id;
void* userdata;

View File

@ -1,6 +1,7 @@
#include "thread/channel.h"
#include "types.h"
#include "core/ref.h"
#include "util.h"
#include <stdlib.h>
#include <math.h>
Channel* lovrChannelInit(Channel* channel) {

View File

@ -1,8 +1,9 @@
#include "thread/thread.h"
#include "thread/channel.h"
#include "types.h"
#include "core/ref.h"
#include "util.h"
#include "lib/map/map.h"
#include <stdlib.h>
static struct {
bool initialized;