Skip to content

Commit

Permalink
[c][cpp] Fix all warnings on Clang, more physics constraints porting
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Jan 3, 2024
1 parent a190bc8 commit 8c79c7c
Show file tree
Hide file tree
Showing 49 changed files with 637 additions and 386 deletions.
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/AnimationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ SP_API float spTrackEntry_getTrackComplete(spTrackEntry *entry);
SP_API void spAnimationState_clearNext(spAnimationState *self, spTrackEntry *entry);

/** Use this to dispose static memory before your app exits to appease your memory leak detector*/
SP_API void spAnimationState_disposeStatics();
SP_API void spAnimationState_disposeStatics(void);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/Atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct spAtlasRegion {
spAtlasRegion *next;
};

SP_API spAtlasRegion *spAtlasRegion_create();
SP_API spAtlasRegion *spAtlasRegion_create(void);

SP_API void spAtlasRegion_dispose(spAtlasRegion *self);

Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/Bone.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct spBone {

SP_API void spBone_setYDown(int/*bool*/yDown);

SP_API int/*bool*/spBone_isYDown();
SP_API int/*bool*/spBone_isYDown(void);

/* @param parent May be 0. */
SP_API spBone *spBone_create(spBoneData *data, struct spSkeleton *skeleton, spBone *parent);
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef struct spColor {
} spColor;

/* @param attachmentName May be 0 for no setup pose attachment. */
SP_API spColor *spColor_create();
SP_API spColor *spColor_create(void);

SP_API void spColor_dispose(spColor *self);

Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/SkeletonBounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef struct spSkeletonBounds {
float minX, minY, maxX, maxY;
} spSkeletonBounds;

SP_API spSkeletonBounds *spSkeletonBounds_create();
SP_API spSkeletonBounds *spSkeletonBounds_create(void);

SP_API void spSkeletonBounds_dispose(spSkeletonBounds *self);

Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/SkeletonClipping.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef struct spSkeletonClipping {
spArrayFloatArray *clippingPolygons;
} spSkeletonClipping;

SP_API spSkeletonClipping *spSkeletonClipping_create();
SP_API spSkeletonClipping *spSkeletonClipping_create(void);

SP_API int spSkeletonClipping_clipStart(spSkeletonClipping *self, spSlot *slot, spClippingAttachment *clip);

Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/SkeletonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef struct spSkeletonData {
spPathConstraintData **pathConstraints;
} spSkeletonData;

SP_API spSkeletonData *spSkeletonData_create();
SP_API spSkeletonData *spSkeletonData_create(void);

SP_API void spSkeletonData_dispose(spSkeletonData *self);

Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/include/spine/Triangulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef struct spTriangulator {
spArrayShortArray *polygonIndicesPool;
} spTriangulator;

SP_API spTriangulator *spTriangulator_create();
SP_API spTriangulator *spTriangulator_create(void);

SP_API spShortArray *spTriangulator_triangulate(spTriangulator *self, spFloatArray *verticesArray);

Expand Down
4 changes: 2 additions & 2 deletions spine-c/spine-c/include/spine/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void *_spRealloc(void *ptr, size_t size);

void _spFree(void *ptr);

float _spRandom();
float _spRandom(void);

SP_API void _spSetMalloc(void *(*_malloc)(size_t size));

Expand All @@ -185,7 +185,7 @@ SP_API void _spSetRealloc(void *(*_realloc)(void *ptr, size_t size));

SP_API void _spSetFree(void (*_free)(void *ptr));

SP_API void _spSetRandom(float (*_random)());
SP_API void _spSetRandom(float (*_random)(void));

char *_spReadFile(const char *path, int *length);

Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/AnimationState.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ _SP_ARRAY_IMPLEMENT_TYPE(spTrackEntryArray, spTrackEntry *)

static spAnimation *SP_EMPTY_ANIMATION = 0;

void spAnimationState_disposeStatics() {
void spAnimationState_disposeStatics(void) {
if (SP_EMPTY_ANIMATION) spAnimation_dispose(SP_EMPTY_ANIMATION);
SP_EMPTY_ANIMATION = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/Atlas.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void spAtlasPage_dispose(spAtlasPage *self) {

/**/

spAtlasRegion *spAtlasRegion_create() {
spAtlasRegion *spAtlasRegion_create(void) {
spAtlasRegion *region = NEW(spAtlasRegion);
region->keyValues = spKeyValueArray_create(2);
return region;
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/AttachmentLoader.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ void _spAttachmentLoader_setError(spAttachmentLoader *self, const char *error1,

void _spAttachmentLoader_setUnknownTypeError(spAttachmentLoader *self, spAttachmentType type) {
char buffer[16];
sprintf(buffer, "%d", type);
snprintf(buffer, 16,"%d", type);
_spAttachmentLoader_setError(self, "Unknown attachment type: ", buffer);
}
47 changes: 26 additions & 21 deletions spine-c/spine-c/src/spine/Bone.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void spBone_setYDown(int value) {
yDown = value;
}

int spBone_isYDown() {
int spBone_isYDown(void) {
return yDown;
}

Expand Down Expand Up @@ -261,26 +261,31 @@ void spBone_updateAppliedTransform(spBone *self) {
break;
}
case SP_TRANSFORMMODE_NOSCALE:
case SP_TRANSFORMMODE_NOSCALEORREFLECTION:
cosine = COS_DEG(self->rotation), sine = SIN_DEG(self->rotation);
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY;
s = SQRT(pa * pa + pc * pc);
if (s > 0.00001f) s = 1 / s;
pa *= s;
pc *= s;
s = SQRT(pa * pa + pc * pc);
if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE &&
pid < 0 != (self->skeleton->scaleX < 0 != self->skeleton->scaleY < 0))
s = -s;
r = PI / 2 + ATAN2(pc, pa);
pb = COS(r) * s;
pd = SIN(r) * s;
pid = 1 / (pa * pd - pb * pc);
ia = pd * pid;
ib = pb * pid;
ic = pc * pid;
id = pa * pid;
case SP_TRANSFORMMODE_NOSCALEORREFLECTION: {
cosine = COS_DEG(self->rotation), sine = SIN_DEG(self->rotation);
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY;
s = SQRT(pa * pa + pc * pc);
if (s > 0.00001f) s = 1 / s;
pa *= s;
pc *= s;
s = SQRT(pa * pa + pc * pc);
if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE &&
pid < 0 != (self->skeleton->scaleX < 0 != self->skeleton->scaleY < 0))
s = -s;
r = PI / 2 + ATAN2(pc, pa);
pb = COS(r) * s;
pd = SIN(r) * s;
pid = 1 / (pa * pd - pb * pc);
ia = pd * pid;
ib = pb * pid;
ic = pc * pid;
id = pa * pid;
break;
}
case SP_TRANSFORMMODE_ONLYTRANSLATION:
case SP_TRANSFORMMODE_NORMAL:
break;
}
ra = ia * self->a - ib * self->c;
rb = ia * self->b - ib * self->d;
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/Color.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <spine/Color.h>
#include <spine/extension.h>

spColor *spColor_create() {
spColor *spColor_create(void) {
return MALLOC(spColor, 1);
}

Expand Down
2 changes: 0 additions & 2 deletions spine-c/spine-c/src/spine/Json.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ static const char *parse_number(Json *item, const char *num) {
if (*ptr == 'e' || *ptr == 'E') {
double exponent = 0;
int expNegative = 0;
int n = 0;
++ptr;

if (*ptr == '-') {
Expand All @@ -135,7 +134,6 @@ static const char *parse_number(Json *item, const char *num) {
while (*ptr >= '0' && *ptr <= '9') {
exponent = (exponent * 10.0) + (*ptr - '0');
++ptr;
++n;
}

if (expNegative)
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/Sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static char *string_append(char *str, const char *b) {

static char *string_append_int(char *str, int value) {
char intStr[20];
sprintf(intStr, "%i", value);
snprintf(intStr, 20, "%i", value);
return string_append(str, intStr);
}

Expand Down
4 changes: 2 additions & 2 deletions spine-c/spine-c/src/spine/SkeletonBinary.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
skeletonData = spSkeletonData_create();
lowHash = readInt(input);
highHash = readInt(input);
sprintf(buffer, "%x%x", highHash, lowHash);
snprintf(buffer, 32, "%x%x", highHash, lowHash);
buffer[31] = 0;
MALLOC_STR(skeletonData->hash, buffer);

Expand All @@ -1336,7 +1336,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
} else {
if (!string_starts_with(skeletonData->version, SPINE_VERSION_STRING)) {
char errorMsg[255];
sprintf(errorMsg, "Skeleton version %s does not match runtime version %s", skeletonData->version, SPINE_VERSION_STRING);
snprintf(errorMsg, 255, "Skeleton version %s does not match runtime version %s", skeletonData->version, SPINE_VERSION_STRING);
_spSkeletonBinary_setError(self, errorMsg, NULL);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/SkeletonBounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ typedef struct {
int capacity;
} _spSkeletonBounds;

spSkeletonBounds *spSkeletonBounds_create() {
spSkeletonBounds *spSkeletonBounds_create(void) {
return SUPER(NEW(_spSkeletonBounds));
}

Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/SkeletonClipping.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <spine/SkeletonClipping.h>
#include <spine/extension.h>

spSkeletonClipping *spSkeletonClipping_create() {
spSkeletonClipping *spSkeletonClipping_create(void) {
spSkeletonClipping *clipping = CALLOC(spSkeletonClipping, 1);

clipping->triangulator = spTriangulator_create();
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/SkeletonData.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <spine/extension.h>
#include <string.h>

spSkeletonData *spSkeletonData_create() {
spSkeletonData *spSkeletonData_create(void) {
return NEW(spSkeletonData);
}

Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/SkeletonJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
MALLOC_STR(skeletonData->version, Json_getString(skeleton, "spine", "0"));
if (!string_starts_with(skeletonData->version, SPINE_VERSION_STRING)) {
char errorMsg[255];
sprintf(errorMsg, "Skeleton version %s does not match runtime version %s", skeletonData->version, SPINE_VERSION_STRING);
snprintf(errorMsg, 255, "Skeleton version %s does not match runtime version %s", skeletonData->version, SPINE_VERSION_STRING);
_spSkeletonJson_setError(self, 0, errorMsg, NULL);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion spine-c/spine-c/src/spine/Triangulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <spine/extension.h>
#include <stdio.h>

spTriangulator *spTriangulator_create() {
spTriangulator *spTriangulator_create(void) {
spTriangulator *triangulator = CALLOC(spTriangulator, 1);

triangulator->convexPolygons = spArrayFloatArray_create(16);
Expand Down
8 changes: 4 additions & 4 deletions spine-c/spine-c/src/spine/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <spine/extension.h>
#include <stdio.h>

float _spInternalRandom() {
float _spInternalRandom(void) {
return rand() / (float) RAND_MAX;
}

Expand All @@ -42,7 +42,7 @@ static void *(*debugMallocFunc)(size_t size, const char *file, int line) = NULL;

static void (*freeFunc)(void *ptr) = free;

static float (*randomFunc)() = _spInternalRandom;
static float (*randomFunc)(void) = _spInternalRandom;

void *_spMalloc(size_t size, const char *file, int line) {
if (debugMallocFunc)
Expand All @@ -65,7 +65,7 @@ void _spFree(void *ptr) {
freeFunc(ptr);
}

float _spRandom() {
float _spRandom(void) {
return randomFunc();
}

Expand All @@ -85,7 +85,7 @@ void _spSetFree(void (*free)(void *ptr)) {
freeFunc = free;
}

void _spSetRandom(float (*random)()) {
void _spSetRandom(float (*random)(void)) {
randomFunc = random;
}

Expand Down
8 changes: 8 additions & 0 deletions spine-cpp/spine-cpp/include/spine/CurveTimeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ namespace spine {

float getCurveValue(float time);

float getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup);

float getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup);

float getAbsoluteValue (float time, float alpha, MixBlend blend, float current, float setup, float value);

float getScaleValue (float time, float alpha, MixBlend blend, MixDirection direction, float current, float setup);

protected:
static const int ENTRIES = 2;
static const int VALUE = 1;
Expand Down
6 changes: 3 additions & 3 deletions spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ namespace spine {
/// Sets the time, mix and bend direction of the specified keyframe.
void setFrame(int frame, float time, float mix, float softness, int bendDirection, bool compress, bool stretch);

int getIkConstraintIndex() { return _ikConstraintIndex; }
int getIkConstraintIndex() { return _constraintIndex; }

void setIkConstraintIndex(int inValue) { _ikConstraintIndex = inValue; }
void setIkConstraintIndex(int inValue) { _constraintIndex = inValue; }

private:
int _ikConstraintIndex;
int _constraintIndex;

static const int ENTRIES = 6;
static const int MIX = 1;
Expand Down
7 changes: 3 additions & 4 deletions spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <spine/CurveTimeline.h>

namespace spine {
#define SP_PATHCONSTRAINTMIXTIMELINE_ENTRIES 5

class SP_API PathConstraintMixTimeline : public CurveTimeline {
friend class SkeletonBinary;
Expand All @@ -52,12 +51,12 @@ namespace spine {
/// Sets the time and mixes of the specified keyframe.
void setFrame(int frameIndex, float time, float mixRotate, float mixX, float mixY);

int getPathConstraintIndex() { return _pathConstraintIndex; }
int getPathConstraintIndex() { return _constraintIndex; }

void setPathConstraintIndex(int inValue) { _pathConstraintIndex = inValue; }
void setPathConstraintIndex(int inValue) { _constraintIndex = inValue; }

private:
int _pathConstraintIndex;
int _constraintIndex;

static const int ENTRIES = 4;
static const int ROTATE = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ namespace spine {
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction);

int getPathConstraintIndex() { return _pathConstraintIndex; }
int getPathConstraintIndex() { return _constraintIndex; }

void setPathConstraintIndex(int inValue) { _pathConstraintIndex = inValue; }
void setPathConstraintIndex(int inValue) { _constraintIndex = inValue; }

protected:
int _pathConstraintIndex;
int _constraintIndex;
};
}

Expand Down
Loading

0 comments on commit 8c79c7c

Please sign in to comment.