From 9803e9916ffcc8d5e1379501a2b55d374a31ffe5 Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 19 Dec 2018 00:25:20 -0800 Subject: [PATCH] Use naming convention for destructor; --- src/audio/microphone.h | 2 +- src/audio/source.h | 4 ++-- src/data/audioStream.h | 2 +- src/data/blob.h | 2 +- src/data/modelData.h | 2 +- src/data/rasterizer.h | 2 +- src/data/soundData.h | 6 +++--- src/data/textureData.h | 4 ++-- src/data/vertexData.h | 2 +- src/filesystem/file.h | 2 +- src/graphics/animator.h | 2 +- src/graphics/buffer.h | 2 +- src/graphics/canvas.h | 4 ++-- src/graphics/font.h | 2 +- src/graphics/material.h | 2 +- src/graphics/mesh.h | 2 +- src/graphics/model.h | 2 +- src/graphics/shader.h | 8 ++++---- src/graphics/texture.h | 4 ++-- src/headset/fake.c | 2 +- src/headset/headset.h | 1 + src/headset/oculus.c | 2 +- src/headset/oculus_mobile.c | 2 +- src/headset/openvr.c | 8 +++----- src/headset/webvr.c | 2 +- src/math/curve.h | 2 +- src/math/pool.h | 2 +- src/math/randomGenerator.h | 2 +- src/physics/physics.h | 28 ++++++++++++++++++---------- src/thread/channel.h | 2 +- src/thread/thread.h | 2 +- src/util.h | 2 +- 32 files changed, 60 insertions(+), 53 deletions(-) diff --git a/src/audio/microphone.h b/src/audio/microphone.h index 18b070d9..ec1c5430 100644 --- a/src/audio/microphone.h +++ b/src/audio/microphone.h @@ -17,7 +17,7 @@ typedef struct { } Microphone; Microphone* lovrMicrophoneInit(Microphone* microphone, const char* name, int samples, int sampleRate, int bitDepth, int channelCount); -#define lovrMicrophoneCreate(...) lovrMicrophoneInit(lovrAlloc(Microphone, lovrMicrophoneDestroy), __VA_ARGS__) +#define lovrMicrophoneCreate(...) lovrMicrophoneInit(lovrAlloc(Microphone), __VA_ARGS__) void lovrMicrophoneDestroy(void* ref); int lovrMicrophoneGetBitDepth(Microphone* microphone); int lovrMicrophoneGetChannelCount(Microphone* microphone); diff --git a/src/audio/source.h b/src/audio/source.h index 90cb6909..85e10ea1 100644 --- a/src/audio/source.h +++ b/src/audio/source.h @@ -31,8 +31,8 @@ typedef struct { Source* lovrSourceInitStatic(Source* source, SoundData* soundData); Source* lovrSourceInitStream(Source* source, AudioStream* stream); -#define lovrSourceCreateStatic(...) lovrSourceInitStatic(lovrAlloc(Source, lovrSourceDestroy), __VA_ARGS__) -#define lovrSourceCreateStream(...) lovrSourceInitStream(lovrAlloc(Source, lovrSourceDestroy), __VA_ARGS__) +#define lovrSourceCreateStatic(...) lovrSourceInitStatic(lovrAlloc(Source), __VA_ARGS__) +#define lovrSourceCreateStream(...) lovrSourceInitStream(lovrAlloc(Source), __VA_ARGS__) void lovrSourceDestroy(void* ref); SourceType lovrSourceGetType(Source* source); int lovrSourceGetBitDepth(Source* source); diff --git a/src/data/audioStream.h b/src/data/audioStream.h index d8e65e45..42e7d6aa 100644 --- a/src/data/audioStream.h +++ b/src/data/audioStream.h @@ -16,7 +16,7 @@ typedef struct { } AudioStream; AudioStream* lovrAudioStreamInit(AudioStream* stream, Blob* blob, size_t bufferSize); -#define lovrAudioStreamCreate(...) lovrAudioStreamInit(lovrAlloc(AudioStream, lovrAudioStreamDestroy), __VA_ARGS__) +#define lovrAudioStreamCreate(...) lovrAudioStreamInit(lovrAlloc(AudioStream), __VA_ARGS__) void lovrAudioStreamDestroy(void* ref); int lovrAudioStreamDecode(AudioStream* stream, short* destination, size_t size); void lovrAudioStreamRewind(AudioStream* stream); diff --git a/src/data/blob.h b/src/data/blob.h index f9b03360..4a896229 100644 --- a/src/data/blob.h +++ b/src/data/blob.h @@ -12,5 +12,5 @@ typedef struct { } Blob; Blob* lovrBlobInit(Blob* blob, void* data, size_t size, const char* name); -#define lovrBlobCreate(...) lovrBlobInit(lovrAlloc(Blob, lovrBlobDestroy), __VA_ARGS__) +#define lovrBlobCreate(...) lovrBlobInit(lovrAlloc(Blob), __VA_ARGS__) void lovrBlobDestroy(void* ref); diff --git a/src/data/modelData.h b/src/data/modelData.h index 6cf71e11..a81a3526 100644 --- a/src/data/modelData.h +++ b/src/data/modelData.h @@ -90,6 +90,6 @@ typedef struct { } ModelData; ModelData* lovrModelDataInit(ModelData* modelData, Blob* blob); -#define lovrModelDataCreate(...) lovrModelDataInit(lovrAlloc(ModelData, lovrModelDataDestroy), __VA_ARGS__) +#define lovrModelDataCreate(...) lovrModelDataInit(lovrAlloc(ModelData), __VA_ARGS__) void lovrModelDataDestroy(void* ref); void lovrModelDataGetAABB(ModelData* modelData, float aabb[6]); diff --git a/src/data/rasterizer.h b/src/data/rasterizer.h index 41acfed7..39e36944 100644 --- a/src/data/rasterizer.h +++ b/src/data/rasterizer.h @@ -39,7 +39,7 @@ typedef struct { typedef map_t(Glyph) map_glyph_t; Rasterizer* lovrRasterizerInit(Rasterizer* rasterizer, Blob* blob, int size); -#define lovrRasterizerCreate(...) lovrRasterizerInit(lovrAlloc(Rasterizer, lovrRasterizerDestroy), __VA_ARGS__) +#define lovrRasterizerCreate(...) lovrRasterizerInit(lovrAlloc(Rasterizer), __VA_ARGS__) void lovrRasterizerDestroy(void* ref); bool lovrRasterizerHasGlyph(Rasterizer* fontData, uint32_t character); bool lovrRasterizerHasGlyphs(Rasterizer* fontData, const char* str); diff --git a/src/data/soundData.h b/src/data/soundData.h index 6ab37ae7..bd173eaa 100644 --- a/src/data/soundData.h +++ b/src/data/soundData.h @@ -14,9 +14,9 @@ typedef struct { SoundData* lovrSoundDataInit(SoundData* soundData, int samples, int sampleRate, int bitDepth, int channels); SoundData* lovrSoundDataInitFromAudioStream(SoundData* soundData, AudioStream* audioStream); SoundData* lovrSoundDataInitFromBlob(SoundData* soundData, Blob* blob); -#define lovrSoundDataCreate(...) lovrSoundDataInit(lovrAlloc(SoundData, lovrSoundDataDestroy), __VA_ARGS__) -#define lovrSoundDataCreateFromAudioStream(...) lovrSoundDataInitFromAudioStream(lovrAlloc(SoundData, lovrSoundDataDestroy), __VA_ARGS__) -#define lovrSoundDataCreateFromBlob(...) lovrSoundDataInitFromBlob(lovrAlloc(SoundData, lovrSoundDataDestroy), __VA_ARGS__) +#define lovrSoundDataCreate(...) lovrSoundDataInit(lovrAlloc(SoundData), __VA_ARGS__) +#define lovrSoundDataCreateFromAudioStream(...) lovrSoundDataInitFromAudioStream(lovrAlloc(SoundData), __VA_ARGS__) +#define lovrSoundDataCreateFromBlob(...) lovrSoundDataInitFromBlob(lovrAlloc(SoundData), __VA_ARGS__) float lovrSoundDataGetSample(SoundData* soundData, int index); void lovrSoundDataSetSample(SoundData* soundData, int index, float value); void lovrSoundDataDestroy(void* ref); diff --git a/src/data/textureData.h b/src/data/textureData.h index 3ea5f55c..62c596c7 100644 --- a/src/data/textureData.h +++ b/src/data/textureData.h @@ -47,8 +47,8 @@ typedef struct { TextureData* lovrTextureDataInit(TextureData* textureData, int width, int height, uint8_t value, TextureFormat format); TextureData* lovrTextureDataInitFromBlob(TextureData* textureData, Blob* blob, bool flip); -#define lovrTextureDataCreate(...) lovrTextureDataInit(lovrAlloc(TextureData, lovrTextureDataDestroy), __VA_ARGS__) -#define lovrTextureDataCreateFromBlob(...) lovrTextureDataInitFromBlob(lovrAlloc(TextureData, lovrTextureDataDestroy), __VA_ARGS__) +#define lovrTextureDataCreate(...) lovrTextureDataInit(lovrAlloc(TextureData), __VA_ARGS__) +#define lovrTextureDataCreateFromBlob(...) lovrTextureDataInitFromBlob(lovrAlloc(TextureData), __VA_ARGS__) Color lovrTextureDataGetPixel(TextureData* textureData, int x, int y); void lovrTextureDataSetPixel(TextureData* textureData, int x, int y, Color color); bool lovrTextureDataEncode(TextureData* textureData, const char* filename); diff --git a/src/data/vertexData.h b/src/data/vertexData.h index 60d9a935..7f960ea6 100644 --- a/src/data/vertexData.h +++ b/src/data/vertexData.h @@ -47,5 +47,5 @@ void vertexFormatInit(VertexFormat* format); void vertexFormatAppend(VertexFormat* format, const char* name, AttributeType type, int count); VertexData* lovrVertexDataInit(VertexData* vertexData, uint32_t count, VertexFormat* format); -#define lovrVertexDataCreate(...) lovrVertexDataInit(lovrAlloc(VertexData, lovrVertexDataDestroy), __VA_ARGS__) +#define lovrVertexDataCreate(...) lovrVertexDataInit(lovrAlloc(VertexData), __VA_ARGS__) #define lovrVertexDataDestroy lovrBlobDestroy diff --git a/src/filesystem/file.h b/src/filesystem/file.h index dbc9eaf6..3b5a2d2b 100644 --- a/src/filesystem/file.h +++ b/src/filesystem/file.h @@ -16,7 +16,7 @@ typedef struct { } File; File* lovrFileInit(File* file, const char* filename); -#define lovrFileCreate(...) lovrFileInit(lovrAlloc(File, lovrFileDestroy), __VA_ARGS__) +#define lovrFileCreate(...) lovrFileInit(lovrAlloc(File), __VA_ARGS__) void lovrFileDestroy(void* ref); int lovrFileOpen(File* file, FileMode mode); void lovrFileClose(File* file); diff --git a/src/graphics/animator.h b/src/graphics/animator.h index b3c371c9..e99008db 100644 --- a/src/graphics/animator.h +++ b/src/graphics/animator.h @@ -28,7 +28,7 @@ typedef struct { } Animator; Animator* lovrAnimatorInit(Animator* animator, ModelData* modelData); -#define lovrAnimatorCreate(...) lovrAnimatorInit(lovrAlloc(Animator, lovrAnimatorDestroy), __VA_ARGS__) +#define lovrAnimatorCreate(...) lovrAnimatorInit(lovrAlloc(Animator), __VA_ARGS__) void lovrAnimatorDestroy(void* ref); void lovrAnimatorReset(Animator* animator); void lovrAnimatorUpdate(Animator* animator, float dt); diff --git a/src/graphics/buffer.h b/src/graphics/buffer.h index 6bd8be40..f85f9ee8 100644 --- a/src/graphics/buffer.h +++ b/src/graphics/buffer.h @@ -18,7 +18,7 @@ typedef struct { } Buffer; Buffer* lovrBufferInit(Buffer* buffer, size_t size, void* data, BufferUsage usage, bool readable); -#define lovrBufferCreate(...) lovrBufferInit(lovrAlloc(Buffer, lovrBufferDestroy), __VA_ARGS__) +#define lovrBufferCreate(...) lovrBufferInit(lovrAlloc(Buffer), __VA_ARGS__) void lovrBufferDestroy(void* ref); size_t lovrBufferGetSize(Buffer* buffer); BufferUsage lovrBufferGetUsage(Buffer* buffer); diff --git a/src/graphics/canvas.h b/src/graphics/canvas.h index ccc46156..a20ece3b 100644 --- a/src/graphics/canvas.h +++ b/src/graphics/canvas.h @@ -37,8 +37,8 @@ typedef struct { Canvas* lovrCanvasInit(Canvas* canvas, int width, int height, CanvasFlags flags); Canvas* lovrCanvasInitFromHandle(Canvas* canvas, int width, int height, CanvasFlags flags, uint32_t framebuffer, uint32_t depthBuffer, uint32_t resolveBuffer, int attachmentCount, bool immortal); -#define lovrCanvasCreate(...) lovrCanvasInit(lovrAlloc(Canvas, lovrCanvasDestroy), __VA_ARGS__) -#define lovrCanvasCreateFromHandle(...) lovrCanvasInitFromHandle(lovrAlloc(Canvas, lovrCanvasDestroy), __VA_ARGS__) +#define lovrCanvasCreate(...) lovrCanvasInit(lovrAlloc(Canvas), __VA_ARGS__) +#define lovrCanvasCreateFromHandle(...) lovrCanvasInitFromHandle(lovrAlloc(Canvas), __VA_ARGS__) void lovrCanvasDestroy(void* ref); const Attachment* lovrCanvasGetAttachments(Canvas* canvas, int* count); void lovrCanvasSetAttachments(Canvas* canvas, Attachment* attachments, int count); diff --git a/src/graphics/font.h b/src/graphics/font.h index 6e24a1c2..103a6525 100644 --- a/src/graphics/font.h +++ b/src/graphics/font.h @@ -39,7 +39,7 @@ typedef struct { } Font; Font* lovrFontInit(Font* font, Rasterizer* rasterizer); -#define lovrFontCreate(...) lovrFontInit(lovrAlloc(Font, lovrFontDestroy), __VA_ARGS__) +#define lovrFontCreate(...) lovrFontInit(lovrAlloc(Font), __VA_ARGS__) void lovrFontDestroy(void* ref); Rasterizer* lovrFontGetRasterizer(Font* font); void lovrFontRender(Font* font, const char* str, float wrap, HorizontalAlign halign, VerticalAlign valign, float* vertices, float* offsety, uint32_t* vertexCount); diff --git a/src/graphics/material.h b/src/graphics/material.h index f5e45dcf..06130048 100644 --- a/src/graphics/material.h +++ b/src/graphics/material.h @@ -38,7 +38,7 @@ typedef struct { } Material; Material* lovrMaterialInit(Material* material); -#define lovrMaterialCreate() lovrMaterialInit(lovrAlloc(Material, lovrMaterialDestroy)) +#define lovrMaterialCreate() lovrMaterialInit(lovrAlloc(Material)) void lovrMaterialDestroy(void* ref); void lovrMaterialBind(Material* material, Shader* shader); bool lovrMaterialIsDirty(Material* material); diff --git a/src/graphics/mesh.h b/src/graphics/mesh.h index 30d829f2..4587033b 100644 --- a/src/graphics/mesh.h +++ b/src/graphics/mesh.h @@ -54,7 +54,7 @@ typedef struct { } Mesh; Mesh* lovrMeshInit(Mesh* mesh, uint32_t count, VertexFormat format, DrawMode drawMode, BufferUsage usage, bool readable); -#define lovrMeshCreate(...) lovrMeshInit(lovrAlloc(Mesh, lovrMeshDestroy), __VA_ARGS__) +#define lovrMeshCreate(...) lovrMeshInit(lovrAlloc(Mesh), __VA_ARGS__) void lovrMeshDestroy(void* ref); void lovrMeshAttachAttribute(Mesh* mesh, const char* name, MeshAttribute* attribute); void lovrMeshDetachAttribute(Mesh* mesh, const char* name); diff --git a/src/graphics/model.h b/src/graphics/model.h index 39c26d12..ddd97207 100644 --- a/src/graphics/model.h +++ b/src/graphics/model.h @@ -24,7 +24,7 @@ typedef struct { } Model; Model* lovrModelInit(Model* model, ModelData* modelData); -#define lovrModelCreate(...) lovrModelInit(lovrAlloc(Model, lovrModelDestroy), __VA_ARGS__) +#define lovrModelCreate(...) lovrModelInit(lovrAlloc(Model), __VA_ARGS__) void lovrModelDestroy(void* ref); void lovrModelDraw(Model* model, mat4 transform, int instances); Animator* lovrModelGetAnimator(Model* model); diff --git a/src/graphics/shader.h b/src/graphics/shader.h index ecfe6717..9247ebb9 100644 --- a/src/graphics/shader.h +++ b/src/graphics/shader.h @@ -107,9 +107,9 @@ typedef struct { Shader* lovrShaderInitGraphics(Shader* shader, const char* vertexSource, const char* fragmentSource); Shader* lovrShaderInitCompute(Shader* shader, const char* source); Shader* lovrShaderInitDefault(Shader* shader, DefaultShader type); -#define lovrShaderCreateGraphics(...) lovrShaderInitGraphics(lovrAlloc(Shader, lovrShaderDestroy), __VA_ARGS__) -#define lovrShaderCreateCompute(...) lovrShaderInitCompute(lovrAlloc(Shader, lovrShaderDestroy), __VA_ARGS__) -#define lovrShaderCreateDefault(...) lovrShaderInitDefault(lovrAlloc(Shader, lovrShaderDestroy), __VA_ARGS__) +#define lovrShaderCreateGraphics(...) lovrShaderInitGraphics(lovrAlloc(Shader), __VA_ARGS__) +#define lovrShaderCreateCompute(...) lovrShaderInitCompute(lovrAlloc(Shader), __VA_ARGS__) +#define lovrShaderCreateDefault(...) lovrShaderInitDefault(lovrAlloc(Shader), __VA_ARGS__) void lovrShaderDestroy(void* ref); ShaderType lovrShaderGetType(Shader* shader); void lovrShaderBind(Shader* shader); @@ -126,7 +126,7 @@ void lovrShaderSetColor(Shader* shader, const char* name, Color color); void lovrShaderSetBlock(Shader* shader, const char* name, ShaderBlock* block, UniformAccess access); ShaderBlock* lovrShaderBlockInit(ShaderBlock* block, vec_uniform_t* uniforms, BlockType type, BufferUsage usage); -#define lovrShaderBlockCreate(...) lovrShaderBlockInit(lovrAlloc(ShaderBlock, lovrShaderBlockDestroy), __VA_ARGS__) +#define lovrShaderBlockCreate(...) lovrShaderBlockInit(lovrAlloc(ShaderBlock), __VA_ARGS__) void lovrShaderBlockDestroy(void* ref); BlockType lovrShaderBlockGetType(ShaderBlock* block); char* lovrShaderBlockGetShaderCode(ShaderBlock* block, const char* blockName, size_t* length); diff --git a/src/graphics/texture.h b/src/graphics/texture.h index bb147159..f2dff2fb 100644 --- a/src/graphics/texture.h +++ b/src/graphics/texture.h @@ -54,8 +54,8 @@ typedef struct { Texture* lovrTextureInit(Texture* texture, TextureType type, TextureData** slices, int sliceCount, bool srgb, bool mipmaps, int msaa); Texture* lovrTextureInitFromHandle(Texture* texture, uint32_t handle, TextureType type); -#define lovrTextureCreate(...) lovrTextureInit(lovrAlloc(Texture, lovrTextureDestroy), __VA_ARGS__) -#define lovrTextureCreateFromHandle(...) lovrTextureInitFromHandle(lovrAlloc(Texture, lovrTextureDestroy), __VA_ARGS__) +#define lovrTextureCreate(...) lovrTextureInit(lovrAlloc(Texture), __VA_ARGS__) +#define lovrTextureCreateFromHandle(...) lovrTextureInitFromHandle(lovrAlloc(Texture), __VA_ARGS__) void lovrTextureDestroy(void* ref); void lovrTextureAllocate(Texture* texture, int width, int height, int depth, TextureFormat format); void lovrTextureReplacePixels(Texture* texture, TextureData* data, int x, int y, int slice, int mipmap); diff --git a/src/headset/fake.c b/src/headset/fake.c index 1ebf4aae..f06dd7b0 100644 --- a/src/headset/fake.c +++ b/src/headset/fake.c @@ -54,7 +54,7 @@ static bool fakeInit(float offset, int msaa) { mat4_identity(state.transform); vec_init(&state.controllers); - Controller* controller = lovrAlloc(Controller, free); + Controller* controller = lovrAlloc(Controller); controller->id = 0; vec_push(&state.controllers, controller); diff --git a/src/headset/headset.h b/src/headset/headset.h index 5ef24ed1..c98646c0 100644 --- a/src/headset/headset.h +++ b/src/headset/headset.h @@ -111,3 +111,4 @@ extern HeadsetInterface* lovrHeadsetDriver; bool lovrHeadsetInit(HeadsetDriver* drivers, int count, float offset, int msaa); void lovrHeadsetDestroy(); +#define lovrControllerDestroy free diff --git a/src/headset/oculus.c b/src/headset/oculus.c index f19e44a0..3d311cca 100644 --- a/src/headset/oculus.c +++ b/src/headset/oculus.c @@ -109,7 +109,7 @@ static bool oculusInit(float offset, int msaa) { vec_init(&state.controllers); for (ovrHandType hand = ovrHand_Left; hand < ovrHand_Count; hand++) { - Controller* controller = lovrAlloc(Controller, free); + Controller* controller = lovrAlloc(Controller); controller->id = hand; vec_push(&state.controllers, controller); } diff --git a/src/headset/oculus_mobile.c b/src/headset/oculus_mobile.c index 41ea55d4..829e0c80 100644 --- a/src/headset/oculus_mobile.c +++ b/src/headset/oculus_mobile.c @@ -110,7 +110,7 @@ static Controller *controller; static Controller** oculusMobileGetControllers(uint8_t* count) { if (!controller) - controller = lovrAlloc(Controller, free); + controller = lovrAlloc(Controller); *count = bridgeLovrMobileData.updateData.goPresent; // TODO: Figure out what multi controller Oculus Mobile looks like and support it return &controller; } diff --git a/src/headset/openvr.c b/src/headset/openvr.c index db16f6c4..6bd36c6c 100644 --- a/src/headset/openvr.c +++ b/src/headset/openvr.c @@ -172,8 +172,7 @@ static bool openvrInit(float offset, int msaa) { vec_init(&state.controllers); for (uint32_t i = 0; i < k_unMaxTrackedDeviceCount; i++) { if (isController(i)) { - Controller* controller = lovrAlloc(Controller, free); - if (!controller) continue; + Controller* controller = lovrAlloc(Controller); controller->id = i; vec_push(&state.controllers, controller); } @@ -416,7 +415,7 @@ static ModelData* openvrControllerNewModelData(Controller* controller) { RenderModel_t* vrModel = state.deviceModels[id]; - ModelData* modelData = lovrAlloc(ModelData, lovrModelDataDestroy); + ModelData* modelData = lovrAlloc(ModelData); VertexFormat format; vertexFormatInit(&format); @@ -553,8 +552,7 @@ static void openvrUpdate(float dt) { case EVREventType_VREvent_TrackedDeviceActivated: { uint32_t id = vrEvent.trackedDeviceIndex; if (isController(id)) { - Controller* controller = lovrAlloc(Controller, free); - if (!controller) break; + Controller* controller = lovrAlloc(Controller); controller->id = id; vec_push(&state.controllers, controller); lovrRetain(controller); diff --git a/src/headset/webvr.c b/src/headset/webvr.c index 27f683c6..c7ff31f3 100644 --- a/src/headset/webvr.c +++ b/src/headset/webvr.c @@ -41,7 +41,7 @@ typedef struct { static HeadsetState state; static void onControllerAdded(uint32_t id) { - Controller* controller = lovrAlloc(Controller, free); + Controller* controller = lovrAlloc(Controller); controller->id = id; vec_push(&state.controllers, controller); lovrRetain(controller); diff --git a/src/math/curve.h b/src/math/curve.h index d5be1181..ffb3e70f 100644 --- a/src/math/curve.h +++ b/src/math/curve.h @@ -8,7 +8,7 @@ typedef struct { } Curve; Curve* lovrCurveInit(Curve* curve, int sizeHint); -#define lovrCurveCreate(...) lovrCurveInit(lovrAlloc(Curve, lovrCurveDestroy), __VA_ARGS__) +#define lovrCurveCreate(...) lovrCurveInit(lovrAlloc(Curve), __VA_ARGS__) void lovrCurveDestroy(void* ref); void lovrCurveEvaluate(Curve* curve, float t, vec3 point); void lovrCurveGetTangent(Curve* curve, float t, vec3 point); diff --git a/src/math/pool.h b/src/math/pool.h index 954b4439..4c26eece 100644 --- a/src/math/pool.h +++ b/src/math/pool.h @@ -21,7 +21,7 @@ typedef struct { } Pool; Pool* lovrPoolInit(Pool* pool, size_t size); -#define lovrPoolCreate(...) lovrPoolInit(lovrAlloc(Pool, lovrPoolDestroy), __VA_ARGS__) +#define lovrPoolCreate(...) lovrPoolInit(lovrAlloc(Pool), __VA_ARGS__) void lovrPoolDestroy(void* ref); float* lovrPoolAllocate(Pool* pool, MathType type); void lovrPoolDrain(Pool* pool); diff --git a/src/math/randomGenerator.h b/src/math/randomGenerator.h index 041b1eb9..82f18764 100644 --- a/src/math/randomGenerator.h +++ b/src/math/randomGenerator.h @@ -21,7 +21,7 @@ typedef struct { } RandomGenerator; RandomGenerator* lovrRandomGeneratorInit(RandomGenerator* generator); -#define lovrRandomGeneratorCreate() lovrRandomGeneratorInit(lovrAlloc(RandomGenerator, lovrRandomGeneratorDestroy)) +#define lovrRandomGeneratorCreate() lovrRandomGeneratorInit(lovrAlloc(RandomGenerator)) #define lovrRandomGeneratorDestroy free Seed lovrRandomGeneratorGetSeed(RandomGenerator* generator); void lovrRandomGeneratorSetSeed(RandomGenerator* generator, Seed seed); diff --git a/src/physics/physics.h b/src/physics/physics.h index 0ebff352..5869bf95 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -89,7 +89,7 @@ bool lovrPhysicsInit(); void lovrPhysicsDestroy(); World* lovrWorldInit(World* world, float xg, float yg, float zg, bool allowSleep, const char** tags, int tagCount); -#define lovrWorldCreate(...) lovrWorldInit(lovrAlloc(World, lovrWorldDestroy), __VA_ARGS__) +#define lovrWorldCreate(...) lovrWorldInit(lovrAlloc(World), __VA_ARGS__) void lovrWorldDestroy(void* ref); void lovrWorldDestroyData(World* world); void lovrWorldUpdate(World* world, float dt, CollisionResolver resolver, void* userdata); @@ -111,7 +111,7 @@ int lovrWorldEnableCollisionBetween(World* world, const char* tag1, const char* int lovrWorldIsCollisionEnabledBetween(World* world, const char* tag1, const char* tag); Collider* lovrColliderInit(Collider* collider, World* world, float x, float y, float z); -#define lovrColliderCreate(...) lovrColliderInit(lovrAlloc(Collider, lovrColliderDestroy), __VA_ARGS__) +#define lovrColliderCreate(...) lovrColliderInit(lovrAlloc(Collider), __VA_ARGS__) void lovrColliderDestroy(void* ref); void lovrColliderDestroyData(Collider* collider); World* lovrColliderGetWorld(Collider* collider); @@ -179,24 +179,28 @@ void lovrShapeGetMass(Shape* shape, float density, float* cx, float* cy, float* void lovrShapeGetAABB(Shape* shape, float aabb[6]); SphereShape* lovrSphereShapeInit(SphereShape* sphere, float radius); -#define lovrSphereShapeCreate(...) lovrSphereShapeInit(lovrAlloc(SphereShape, lovrShapeDestroy), __VA_ARGS__) +#define lovrSphereShapeCreate(...) lovrSphereShapeInit(lovrAlloc(SphereShape), __VA_ARGS__) +#define lovrSphereShapeDestroy lovrShapeDestroy float lovrSphereShapeGetRadius(SphereShape* sphere); void lovrSphereShapeSetRadius(SphereShape* sphere, float radius); BoxShape* lovrBoxShapeInit(BoxShape* box, float x, float y, float z); -#define lovrBoxShapeCreate(...) lovrBoxShapeInit(lovrAlloc(BoxShape, lovrShapeDestroy), __VA_ARGS__) +#define lovrBoxShapeCreate(...) lovrBoxShapeInit(lovrAlloc(BoxShape), __VA_ARGS__) +#define lovrBoxShapeDestroy lovrShapeDestroy void lovrBoxShapeGetDimensions(BoxShape* box, float* x, float* y, float* z); void lovrBoxShapeSetDimensions(BoxShape* box, float x, float y, float z); CapsuleShape* lovrCapsuleShapeInit(CapsuleShape* capsule, float radius, float length); -#define lovrCapsuleShapeCreate(...) lovrCapsuleShapeInit(lovrAlloc(CapsuleShape, lovrShapeDestroy), __VA_ARGS__) +#define lovrCapsuleShapeCreate(...) lovrCapsuleShapeInit(lovrAlloc(CapsuleShape), __VA_ARGS__) +#define lovrCapsuleShapeDestroy lovrShapeDestroy float lovrCapsuleShapeGetRadius(CapsuleShape* capsule); void lovrCapsuleShapeSetRadius(CapsuleShape* capsule, float radius); float lovrCapsuleShapeGetLength(CapsuleShape* capsule); void lovrCapsuleShapeSetLength(CapsuleShape* capsule, float length); CylinderShape* lovrCylinderShapeInit(CylinderShape* cylinder, float radius, float length); -#define lovrCylinderShapeCreate(...) lovrCylinderShapeInit(lovrAlloc(CylinderShape, lovrShapeDestroy), __VA_ARGS__) +#define lovrCylinderShapeCreate(...) lovrCylinderShapeInit(lovrAlloc(CylinderShape), __VA_ARGS__) +#define lovrCylinderShapeDestroy lovrShapeDestroy float lovrCylinderShapeGetRadius(CylinderShape* cylinder); void lovrCylinderShapeSetRadius(CylinderShape* cylinder, float radius); float lovrCylinderShapeGetLength(CylinderShape* cylinder); @@ -210,19 +214,22 @@ void* lovrJointGetUserData(Joint* joint); void lovrJointSetUserData(Joint* joint, void* data); BallJoint* lovrBallJointInit(BallJoint* joint, Collider* a, Collider* b, float x, float y, float z); -#define lovrBallJointCreate(...) lovrBallJointInit(lovrAlloc(BallJoint, lovrJointDestroy), __VA_ARGS__) +#define lovrBallJointCreate(...) lovrBallJointInit(lovrAlloc(BallJoint), __VA_ARGS__) +#define lovrBallJointDestroy lovrJointDestroy void lovrBallJointGetAnchors(BallJoint* joint, float* x1, float* y1, float* z1, float* x2, float* y2, float* z2); void lovrBallJointSetAnchor(BallJoint* joint, float x, float y, float z); DistanceJoint* lovrDistanceJointInit(DistanceJoint* joint, Collider* a, Collider* b, float x1, float y1, float z1, float x2, float y2, float z2); -#define lovrDistanceJointCreate(...) lovrDistanceJointInit(lovrAlloc(DistanceJoint, lovrJointDestroy), __VA_ARGS__) +#define lovrDistanceJointCreate(...) lovrDistanceJointInit(lovrAlloc(DistanceJoint), __VA_ARGS__) +#define lovrDistanceJointDestroy lovrJointDestroy void lovrDistanceJointGetAnchors(DistanceJoint* joint, float* x1, float* y1, float* z1, float* x2, float* y2, float* z2); void lovrDistanceJointSetAnchors(DistanceJoint* joint, float x1, float y1, float z1, float x2, float y2, float z2); float lovrDistanceJointGetDistance(DistanceJoint* joint); void lovrDistanceJointSetDistance(DistanceJoint* joint, float distance); HingeJoint* lovrHingeJointInit(HingeJoint* joint, Collider* a, Collider* b, float x, float y, float z, float ax, float ay, float az); -#define lovrHingeJointCreate(...) lovrHingeJointInit(lovrAlloc(HingeJoint, lovrJointDestroy), __VA_ARGS__) +#define lovrHingeJointCreate(...) lovrHingeJointInit(lovrAlloc(HingeJoint), __VA_ARGS__) +#define lovrHingeJointDestroy lovrJointDestroy void lovrHingeJointGetAnchors(HingeJoint* joint, float* x1, float* y1, float* z1, float* x2, float* y2, float* z2); void lovrHingeJointSetAnchor(HingeJoint* joint, float x, float y, float z); void lovrHingeJointGetAxis(HingeJoint* joint, float* x, float* y, float* z); @@ -234,7 +241,8 @@ float lovrHingeJointGetUpperLimit(HingeJoint* joint); void lovrHingeJointSetUpperLimit(HingeJoint* joint, float limit); SliderJoint* lovrSliderJointInit(SliderJoint* joint, Collider* a, Collider* b, float ax, float ay, float az); -#define lovrSliderJointCreate(...) lovrSliderJointInit(lovrAlloc(SliderJoint, lovrJointDestroy), __VA_ARGS__) +#define lovrSliderJointCreate(...) lovrSliderJointInit(lovrAlloc(SliderJoint), __VA_ARGS__) +#define lovrSliderJointDestroy lovrJointDestroy void lovrSliderJointGetAxis(SliderJoint* joint, float* x, float* y, float* z); void lovrSliderJointSetAxis(SliderJoint* joint, float x, float y, float z); float lovrSliderJointGetPosition(SliderJoint* joint); diff --git a/src/thread/channel.h b/src/thread/channel.h index 9cf4b77e..05e95e3f 100644 --- a/src/thread/channel.h +++ b/src/thread/channel.h @@ -17,7 +17,7 @@ struct Channel { }; Channel* lovrChannelInit(Channel* channel); -#define lovrChannelCreate() lovrChannelInit(lovrAlloc(Channel, lovrChannelDestroy)) +#define lovrChannelCreate() lovrChannelInit(lovrAlloc(Channel)) void lovrChannelDestroy(void* ref); bool lovrChannelPush(Channel* channel, Variant variant, double timeout, uint64_t* id); bool lovrChannelPop(Channel* channel, Variant* variant, double timeout); diff --git a/src/thread/thread.h b/src/thread/thread.h index e8460528..7ee99fe9 100644 --- a/src/thread/thread.h +++ b/src/thread/thread.h @@ -27,7 +27,7 @@ void lovrThreadModuleDestroy(); struct Channel* lovrThreadGetChannel(const char* name); Thread* lovrThreadInit(Thread* thread, int (*runner)(void*), const char* body); -#define lovrThreadCreate(...) lovrThreadInit(lovrAlloc(Thread, lovrThreadDestroy), __VA_ARGS__) +#define lovrThreadCreate(...) lovrThreadInit(lovrAlloc(Thread), __VA_ARGS__) void lovrThreadDestroy(void* ref); void lovrThreadStart(Thread* thread); void lovrThreadWait(Thread* thread); diff --git a/src/util.h b/src/util.h index ddf4f36e..ded9fed0 100644 --- a/src/util.h +++ b/src/util.h @@ -23,7 +23,7 @@ #define CHECK_SIZEOF(T) int(*_o)[sizeof(T)]=1 #define lovrAssert(c, ...) if (!(c)) { lovrThrow(__VA_ARGS__); } -#define lovrAlloc(T, destructor) (T*) _lovrAlloc(#T, sizeof(T), destructor) +#define lovrAlloc(T) (T*) _lovrAlloc(#T, sizeof(T), lovr ## T ## Destroy) #define MAX(a, b) (a > b ? a : b) #define MIN(a, b) (a < b ? a : b)