From b327a803e0aa2ac46754e175ef2e6e88c886bf47 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sun, 31 Aug 2014 16:21:52 +0200 Subject: [PATCH] C89 fixes. --- spine-c/spine-c.vcxproj | 4 ++++ spine-c/spine-c.vcxproj.filters | 12 ++++++++++++ spine-c/src/spine/Animation.c | 11 ++++++----- spine-c/src/spine/Bone.c | 3 ++- spine-c/src/spine/IkConstraint.c | 30 +++++++++++++++++------------- spine-c/src/spine/SkeletonJson.c | 4 +++- 6 files changed, 44 insertions(+), 20 deletions(-) diff --git a/spine-c/spine-c.vcxproj b/spine-c/spine-c.vcxproj index 2a54d9a5c..5219ad301 100644 --- a/spine-c/spine-c.vcxproj +++ b/spine-c/spine-c.vcxproj @@ -84,6 +84,8 @@ + + @@ -111,6 +113,8 @@ + + diff --git a/spine-c/spine-c.vcxproj.filters b/spine-c/spine-c.vcxproj.filters index 580b17c30..7dc493ef9 100644 --- a/spine-c/spine-c.vcxproj.filters +++ b/spine-c/spine-c.vcxproj.filters @@ -90,6 +90,12 @@ Header Files + + Header Files + + + Header Files + @@ -164,5 +170,11 @@ Source Files + + Source Files + + + Source Files + \ No newline at end of file diff --git a/spine-c/src/spine/Animation.c b/spine-c/src/spine/Animation.c index 2a719214c..b246e8c07 100644 --- a/spine-c/src/spine/Animation.c +++ b/spine-c/src/spine/Animation.c @@ -752,6 +752,7 @@ static const int IKCONSTRAINT_FRAME_BEND_DIRECTION = 2; void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, int* eventsCount, float alpha) { int frameIndex; + float prevFrameMix, frameTime, percent, mix; spIkConstraint* ikConstraint; spIkConstraintTimeline* self = (spIkConstraintTimeline*)timeline; @@ -767,12 +768,12 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel /* Interpolate between the previous frame and the current frame. */ frameIndex = binarySearch(self->frames, self->framesCount, time, 3); - float prevFrameMix = self->frames[frameIndex - 2]; - float frameTime = self->frames[frameIndex]; - float percent = 1 - (time - frameTime) / (self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_TIME] - frameTime); + prevFrameMix = self->frames[frameIndex - 2]; + frameTime = self->frames[frameIndex]; + percent = 1 - (time - frameTime) / (self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_TIME] - frameTime); percent = spCurveTimeline_getCurvePercent(SUPER(self), frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent)); - float mix = prevFrameMix + (self->frames[frameIndex + IKCONSTRAINT_FRAME_MIX] - prevFrameMix) * percent; + mix = prevFrameMix + (self->frames[frameIndex + IKCONSTRAINT_FRAME_MIX] - prevFrameMix) * percent; ikConstraint->mix += (mix - ikConstraint->mix) * alpha; ikConstraint->bendDirection = (int)self->frames[frameIndex + IKCONSTRAINT_FRAME_BEND_DIRECTION]; } @@ -785,5 +786,5 @@ void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameInd frameIndex *= 3; self->frames[frameIndex] = time; self->frames[frameIndex + 1] = mix; - self->frames[frameIndex + 2] = bendDirection; + self->frames[frameIndex + 2] = (float)bendDirection; } diff --git a/spine-c/src/spine/Bone.c b/spine-c/src/spine/Bone.c index 1b2f8c495..107a0cb3c 100644 --- a/spine-c/src/spine/Bone.c +++ b/spine-c/src/spine/Bone.c @@ -100,13 +100,14 @@ void spBone_setToSetupPose (spBone* self) { } void spBone_worldToLocal (spBone* self, float worldX, float worldY, float* localX, float* localY) { + float invDet; float dx = worldX - self->worldX, dy = worldY - self->worldY; float m00 = self->m00, m11 = self->m11; if (self->flipX != (self->flipY != yDown)) { m00 *= -1; m11 *= -1; } - float invDet = 1 / (m00 * m11 - self->m01 * self->m10); + invDet = 1 / (m00 * m11 - self->m01 * self->m10); *localX = (dx * m00 * invDet - dy * self->m01 * invDet); *localY = (dy * m11 * invDet - dx * self->m10 * invDet); } diff --git a/spine-c/src/spine/IkConstraint.c b/spine-c/src/spine/IkConstraint.c index c7db55c3c..d23ada807 100644 --- a/spine-c/src/spine/IkConstraint.c +++ b/spine-c/src/spine/IkConstraint.c @@ -74,14 +74,15 @@ void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, float al } void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDirection, float alpha) { + float positionX, positionY, childX, childY, offset, len1, len2, cosDenom, cos, childAngle, adjacent, opposite, parentAngle, rotation; + spBone* parentParent; float childRotation = child->rotation, parentRotation = parent->rotation; if (alpha == 0) { child->rotationIK = childRotation; parent->rotationIK = parentRotation; return; } - float positionX, positionY; - spBone* parentParent = parent->parent; + parentParent = parent->parent; if (parentParent) { spBone_worldToLocal(parentParent, targetX, targetY, &positionX, &positionY); targetX = (positionX - parent->x) * parentParent->worldScaleX; @@ -97,24 +98,27 @@ void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float spBone_localToWorld(child->parent, child->x, child->y, &positionX, &positionY); spBone_worldToLocal(parent, positionX, positionY, &positionX, &positionY); } - float childX = positionX * parent->worldScaleX, childY = positionY * parent->worldScaleY; - float offset = ATAN2(childY, childX); - float len1 = SQRT(childX * childX + childY * childY); - float len2 = child->data->length * child->worldScaleX; + childX = positionX * parent->worldScaleX; + childY = positionY * parent->worldScaleY; + offset = ATAN2(childY, childX); + len1 = SQRT(childX * childX + childY * childY); + len2 = child->data->length * child->worldScaleX; /* Based on code by Ryan Juckett with permission: Copyright (c) 2008-2009 Ryan Juckett, http://www.ryanjuckett.com/ */ - float cosDenom = 2 * len1 * len2; + cosDenom = 2 * len1 * len2; if (cosDenom < 0.0001f) { child->rotationIK = childRotation + (ATAN2(targetY, targetX) * RAD_DEG - parentRotation - childRotation) * alpha; return; } - float cos = (targetX * targetX + targetY * targetY - len1 * len1 - len2 * len2) / cosDenom; + cos = (targetX * targetX + targetY * targetY - len1 * len1 - len2 * len2) / cosDenom; if (cos < -1) cos = -1; - else if (cos > 1) cos = 1; - float childAngle = ACOS(cos) * bendDirection; - float adjacent = len1 + len2 * cos, opposite = len2 * SIN(childAngle); - float parentAngle = ATAN2(targetY * adjacent - targetX * opposite, targetX * adjacent + targetY * opposite); - float rotation = (parentAngle - offset) * RAD_DEG - parentRotation; + else if (cos > 1) /**/ + cos = 1; + childAngle = ACOS(cos) * bendDirection; + adjacent = len1 + len2 * cos; + opposite = len2 * SIN(childAngle); + parentAngle = ATAN2(targetY * adjacent - targetX * opposite, targetX * adjacent + targetY * opposite); + rotation = (parentAngle - offset) * RAD_DEG - parentRotation; if (rotation > 180) rotation -= 360; else if (rotation < -180) /**/ diff --git a/spine-c/src/spine/SkeletonJson.c b/spine-c/src/spine/SkeletonJson.c index 80382907b..fd3bd44ec 100644 --- a/spine-c/src/spine/SkeletonJson.c +++ b/spine-c/src/spine/SkeletonJson.c @@ -462,6 +462,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha skeletonData->ikConstraintsCount = ik->size; skeletonData->ikConstraints = MALLOC(spIkConstraintData*, ik->size); for (ikMap = ik->child, i = 0; ikMap; ikMap = ikMap->next, ++i) { + const char* targetName; + spIkConstraintData* ikConstraintData = spIkConstraintData_create(Json_getString(ikMap, "name", 0)); boneMap = Json_getItem(ikMap, "bones"); ikConstraintData->bonesCount = boneMap->size; @@ -475,7 +477,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha } } - const char* targetName = Json_getString(ikMap, "target", 0); + targetName = Json_getString(ikMap, "target", 0); ikConstraintData->target = spSkeletonData_findBone(skeletonData, targetName); if (!ikConstraintData->target) { spSkeletonData_dispose(skeletonData);