Formatting

This commit is contained in:
Mario Zechner 2024-04-16 17:21:36 +02:00
parent 0211519a66
commit de6b411007
24 changed files with 1380 additions and 1368 deletions

View File

@ -299,107 +299,107 @@ float spCurveTimeline1_getCurveValue(spCurveTimeline1 *self, float time) {
}
float spCurveTimeline1_getRelativeValue(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup) {
float *frames = self->super.frames->items;
if (time < frames[0]) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup;
case SP_MIX_BLEND_FIRST:
return current + (setup - current) * alpha;
default:
return current;
}
}
float value = spCurveTimeline1_getCurveValue(self, time);
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup + value * alpha;
case SP_MIX_BLEND_FIRST:
case SP_MIX_BLEND_REPLACE:
value += setup - current;
break;
case SP_MIX_BLEND_ADD:
break;
}
return current + value * alpha;
float *frames = self->super.frames->items;
if (time < frames[0]) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup;
case SP_MIX_BLEND_FIRST:
return current + (setup - current) * alpha;
default:
return current;
}
}
float value = spCurveTimeline1_getCurveValue(self, time);
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup + value * alpha;
case SP_MIX_BLEND_FIRST:
case SP_MIX_BLEND_REPLACE:
value += setup - current;
break;
case SP_MIX_BLEND_ADD:
break;
}
return current + value * alpha;
}
float spCurveTimeline1_getAbsoluteValue(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup) {
float *frames = self->super.frames->items;
if (time < frames[0]) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup;
case SP_MIX_BLEND_FIRST:
return current + (setup - current) * alpha;
default:
return current;
}
}
float value = spCurveTimeline1_getCurveValue(self, time);
if (blend == SP_MIX_BLEND_SETUP) return setup + (value - setup) * alpha;
return current + (value - current) * alpha;
float *frames = self->super.frames->items;
if (time < frames[0]) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup;
case SP_MIX_BLEND_FIRST:
return current + (setup - current) * alpha;
default:
return current;
}
}
float value = spCurveTimeline1_getCurveValue(self, time);
if (blend == SP_MIX_BLEND_SETUP) return setup + (value - setup) * alpha;
return current + (value - current) * alpha;
}
float spCurveTimeline1_getAbsoluteValue2(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, float current, float setup, float value) {
float *frames = self->super.frames->items;
if (time < frames[0]) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup;
case SP_MIX_BLEND_FIRST:
return current + (setup - current) * alpha;
default:
return current;
}
}
if (blend == SP_MIX_BLEND_SETUP) return setup + (value - setup) * alpha;
return current + (value - current) * alpha;
float *frames = self->super.frames->items;
if (time < frames[0]) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup;
case SP_MIX_BLEND_FIRST:
return current + (setup - current) * alpha;
default:
return current;
}
}
if (blend == SP_MIX_BLEND_SETUP) return setup + (value - setup) * alpha;
return current + (value - current) * alpha;
}
float spCurveTimeline1_getScaleValue (spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, spMixDirection direction, float current, float setup) {
float *frames = self->super.frames->items;
if (time < frames[0]) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup;
case SP_MIX_BLEND_FIRST:
return current + (setup - current) * alpha;
default:
return current;
}
}
float value = spCurveTimeline1_getCurveValue(self, time) * setup;
if (alpha == 1) {
if (blend == SP_MIX_BLEND_ADD) return current + value - setup;
return value;
}
// Mixing out uses sign of setup or current pose, else use sign of key.
if (direction == SP_MIX_DIRECTION_OUT) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup + (ABS(value) * SIGNUM(setup) - setup) * alpha;
case SP_MIX_BLEND_FIRST:
case SP_MIX_BLEND_REPLACE:
return current + (ABS(value) * SIGNUM(current) - current) * alpha;
default:
break;
}
} else {
float s;
switch (blend) {
case SP_MIX_BLEND_SETUP:
s = ABS(setup) * SIGNUM(value);
return s + (value - s) * alpha;
case SP_MIX_BLEND_FIRST:
case SP_MIX_BLEND_REPLACE:
s = ABS(current) * SIGNUM(value);
return s + (value - s) * alpha;
default:
break;
}
}
return current + (value - setup) * alpha;
float spCurveTimeline1_getScaleValue(spCurveTimeline1 *self, float time, float alpha, spMixBlend blend, spMixDirection direction, float current, float setup) {
float *frames = self->super.frames->items;
if (time < frames[0]) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup;
case SP_MIX_BLEND_FIRST:
return current + (setup - current) * alpha;
default:
return current;
}
}
float value = spCurveTimeline1_getCurveValue(self, time) * setup;
if (alpha == 1) {
if (blend == SP_MIX_BLEND_ADD) return current + value - setup;
return value;
}
// Mixing out uses sign of setup or current pose, else use sign of key.
if (direction == SP_MIX_DIRECTION_OUT) {
switch (blend) {
case SP_MIX_BLEND_SETUP:
return setup + (ABS(value) * SIGNUM(setup) - setup) * alpha;
case SP_MIX_BLEND_FIRST:
case SP_MIX_BLEND_REPLACE:
return current + (ABS(value) * SIGNUM(current) - current) * alpha;
default:
break;
}
} else {
float s;
switch (blend) {
case SP_MIX_BLEND_SETUP:
s = ABS(setup) * SIGNUM(value);
return s + (value - s) * alpha;
case SP_MIX_BLEND_FIRST:
case SP_MIX_BLEND_REPLACE:
s = ABS(current) * SIGNUM(value);
return s + (value - s) * alpha;
default:
break;
}
}
return current + (value - setup) * alpha;
}
#define CURVE2_ENTRIES 3
@ -420,9 +420,9 @@ void _spRotateTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
int *eventsCount, float alpha, spMixBlend blend, spMixDirection direction) {
spRotateTimeline *self = SUB_CAST(spRotateTimeline, timeline);
spBone *bone = skeleton->bones[self->boneIndex];
if (bone->active) bone->rotation = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->rotation, bone->data->rotation);
if (bone->active) bone->rotation = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->rotation, bone->data->rotation);
UNUSED(lastTime);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(direction);
@ -787,9 +787,9 @@ void _spScaleXTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
spScaleXTimeline *self = SUB_CAST(spScaleXTimeline, timeline);
spBone *bone = skeleton->bones[self->boneIndex];
if (bone->active) bone->scaleX = spCurveTimeline1_getScaleValue(SUPER(self), time, alpha, blend, direction, bone->scaleX, bone->data->scaleX);
if (bone->active) bone->scaleX = spCurveTimeline1_getScaleValue(SUPER(self), time, alpha, blend, direction, bone->scaleX, bone->data->scaleX);
UNUSED(lastTime);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
}
@ -816,9 +816,9 @@ void _spScaleYTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
spScaleYTimeline *self = SUB_CAST(spScaleYTimeline, timeline);
spBone *bone = skeleton->bones[self->boneIndex];
if (bone->active) bone->scaleY = spCurveTimeline1_getScaleValue(SUPER(self), time, alpha, blend, direction, bone->scaleX, bone->data->scaleY);
if (bone->active) bone->scaleY = spCurveTimeline1_getScaleValue(SUPER(self), time, alpha, blend, direction, bone->scaleX, bone->data->scaleY);
UNUSED(lastTime);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
}
@ -934,9 +934,9 @@ void _spShearXTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
spShearXTimeline *self = SUB_CAST(spShearXTimeline, timeline);
spBone *bone = skeleton->bones[self->boneIndex];
if (bone->active) bone->shearX = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->shearX, bone->data->shearX);
if (bone->active) bone->shearX = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->shearX, bone->data->shearX);
UNUSED(lastTime);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(direction);
@ -964,9 +964,9 @@ void _spShearYTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float l
spShearYTimeline *self = SUB_CAST(spShearYTimeline, timeline);
spBone *bone = skeleton->bones[self->boneIndex];
if (bone->active) bone->shearY = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->shearY, bone->data->shearY);
if (bone->active) bone->shearY = spCurveTimeline1_getRelativeValue(SUPER(self), time, alpha, blend, bone->shearY, bone->data->shearY);
UNUSED(lastTime);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(direction);
@ -2150,54 +2150,54 @@ void spDrawOrderTimeline_setFrame(spDrawOrderTimeline *self, int frame, float ti
self->drawOrders[frame] = 0;
else {
self->drawOrders[frame] = MALLOC(int, self->slotsCount);
memcpy( self->drawOrders[frame], drawOrder, self->slotsCount * sizeof(int));
memcpy(self->drawOrders[frame], drawOrder, self->slotsCount * sizeof(int));
}
}
/**/
void _spInheritTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
spMixDirection direction) {
spInheritTimeline *self = (spInheritTimeline *)timeline;
spBone *bone = skeleton->bones[self->boneIndex];
float *frames = self->super.frames->items;
if (!bone->active) return;
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
spMixDirection direction) {
spInheritTimeline *self = (spInheritTimeline *) timeline;
spBone *bone = skeleton->bones[self->boneIndex];
float *frames = self->super.frames->items;
if (!bone->active) return;
if (time < frames[0]) {
if (blend == SP_MIX_BLEND_SETUP || blend == SP_MIX_BLEND_FIRST) bone->inherit = bone->data->inherit;
return;
}
int idx = search2(self->super.frames, time, 2) + 1;
bone->inherit = (spInherit) frames[idx];
if (time < frames[0]) {
if (blend == SP_MIX_BLEND_SETUP || blend == SP_MIX_BLEND_FIRST) bone->inherit = bone->data->inherit;
return;
}
int idx = search2(self->super.frames, time, 2) + 1;
bone->inherit = (spInherit) frames[idx];
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(alpha);
UNUSED(direction);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(alpha);
UNUSED(direction);
}
void _spInheritTimeline_dispose(spTimeline *timeline) {
// no-op, spTimeline_dispose disposes frames.
UNUSED(timeline);
// no-op, spTimeline_dispose disposes frames.
UNUSED(timeline);
}
spInheritTimeline *spInheritTimeline_create(int framesCount, int boneIndex) {
spInheritTimeline *self = NEW(spInheritTimeline);
spPropertyId ids[1];
ids[0] = (spPropertyId) SP_PROPERTY_INHERIT << 32;
_spTimeline_init(SUPER(self), framesCount, 2, ids, 1, SP_TIMELINE_INHERIT, _spInheritTimeline_dispose,
_spInheritTimeline_apply, 0);
spInheritTimeline *self = NEW(spInheritTimeline);
spPropertyId ids[1];
ids[0] = (spPropertyId) SP_PROPERTY_INHERIT << 32;
_spTimeline_init(SUPER(self), framesCount, 2, ids, 1, SP_TIMELINE_INHERIT, _spInheritTimeline_dispose,
_spInheritTimeline_apply, 0);
self->boneIndex = boneIndex;
self->boneIndex = boneIndex;
return self;
return self;
}
void spInheritTimeline_setFrame(spInheritTimeline *self, int frame, float time, spInherit inherit) {
frame *= 2;
self->super.frames->items[frame] = time;
self->super.frames->items[frame + 1] = inherit;
frame *= 2;
self->super.frames->items[frame] = time;
self->super.frames->items[frame + 1] = inherit;
}
@ -2464,9 +2464,9 @@ static const int PATHCONSTRAINTPOSITION_VALUE = 1;
void _spPathConstraintPositionTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
spMixDirection direction) {
spPathConstraintPositionTimeline *self = (spPathConstraintPositionTimeline *) timeline;
spPathConstraint *constraint = skeleton->pathConstraints[self->pathConstraintIndex];
if (constraint->active) constraint->position = spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, constraint->position, constraint->data->position);
spPathConstraintPositionTimeline *self = (spPathConstraintPositionTimeline *) timeline;
spPathConstraint *constraint = skeleton->pathConstraints[self->pathConstraintIndex];
if (constraint->active) constraint->position = spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, constraint->position, constraint->data->position);
UNUSED(lastTime);
UNUSED(firedEvents);
@ -2500,14 +2500,14 @@ static const int PATHCONSTRAINTSPACING_VALUE = 1;
void _spPathConstraintSpacingTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
spMixDirection direction) {
spPathConstraintSpacingTimeline *self = (spPathConstraintSpacingTimeline *) timeline;
spPathConstraint *constraint = skeleton->pathConstraints[self->pathConstraintIndex];
if (constraint->active) constraint->spacing = spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, constraint->spacing, constraint->data->spacing);
spPathConstraintSpacingTimeline *self = (spPathConstraintSpacingTimeline *) timeline;
spPathConstraint *constraint = skeleton->pathConstraints[self->pathConstraintIndex];
if (constraint->active) constraint->spacing = spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, constraint->spacing, constraint->data->spacing);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(direction);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(direction);
}
spPathConstraintSpacingTimeline *
@ -2640,223 +2640,223 @@ void spPathConstraintMixTimeline_setFrame(spPathConstraintMixTimeline *self, int
/**/
int/*bool*/ _spPhysicsConstraintTimeline_global(spPhysicsConstraintData *data, spTimelineType type) {
switch(type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
return data->inertiaGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
return data->strengthGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
return data->dampingGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
return data->massGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
return data->windGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
return data->gravityGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
return data->mixGlobal;
default:
// should never happen
return 0;
}
int /*bool*/ _spPhysicsConstraintTimeline_global(spPhysicsConstraintData *data, spTimelineType type) {
switch (type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
return data->inertiaGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
return data->strengthGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
return data->dampingGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
return data->massGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
return data->windGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
return data->gravityGlobal;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
return data->mixGlobal;
default:
// should never happen
return 0;
}
}
void _spPhysicsConstraintTimeline_set(spPhysicsConstraint *constraint, spTimelineType type, float value) {
switch(type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
constraint->inertia = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
constraint->strength = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
constraint->damping = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
constraint->massInverse = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
constraint->wind = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
constraint->gravity = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
constraint->mix = value;
break;
default:
// should never happen
break;
}
switch (type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
constraint->inertia = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
constraint->strength = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
constraint->damping = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
constraint->massInverse = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
constraint->wind = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
constraint->gravity = value;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
constraint->mix = value;
break;
default:
// should never happen
break;
}
}
float _spPhysicsConstraintTimeline_get(spPhysicsConstraint *constraint, spTimelineType type) {
switch(type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
return constraint->inertia;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
return constraint->strength;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
return constraint->damping;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
return constraint->massInverse;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
return constraint->wind;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
return constraint->gravity;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
return constraint->mix;
default:
// should never happen
return 0;
}
switch (type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
return constraint->inertia;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
return constraint->strength;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
return constraint->damping;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
return constraint->massInverse;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
return constraint->wind;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
return constraint->gravity;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
return constraint->mix;
default:
// should never happen
return 0;
}
}
float _spPhysicsConstraintTimeline_setup(spPhysicsConstraint *constraint, spTimelineType type) {
switch(type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
return constraint->data->inertia;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
return constraint->data->strength;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
return constraint->data->damping;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
return constraint->data->massInverse;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
return constraint->data->wind;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
return constraint->data->gravity;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
return constraint->data->mix;
default:
// should never happen
return 0;
}
switch (type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
return constraint->data->inertia;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
return constraint->data->strength;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
return constraint->data->damping;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
return constraint->data->massInverse;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
return constraint->data->wind;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
return constraint->data->gravity;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
return constraint->data->mix;
default:
// should never happen
return 0;
}
}
void _spPhysicsConstraintTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
spMixDirection direction) {
spPhysicsConstraintTimeline *self = SUB_CAST(spPhysicsConstraintTimeline, timeline);
spTimelineType type = self->super.super.type;
float *frames = self->super.super.frames->items;
if (self->physicsConstraintIndex == -1) {
float value = time >= frames[0] ? spCurveTimeline1_getCurveValue(SUPER(self), time) : 0;
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
spMixDirection direction) {
spPhysicsConstraintTimeline *self = SUB_CAST(spPhysicsConstraintTimeline, timeline);
spTimelineType type = self->super.super.type;
float *frames = self->super.super.frames->items;
if (self->physicsConstraintIndex == -1) {
float value = time >= frames[0] ? spCurveTimeline1_getCurveValue(SUPER(self), time) : 0;
spPhysicsConstraint **physicsConstraints = skeleton->physicsConstraints;
for (int i = 0; i < skeleton->physicsConstraintsCount; i++) {
spPhysicsConstraint *constraint = physicsConstraints[i];
if (constraint->active && _spPhysicsConstraintTimeline_global(constraint->data, type))
_spPhysicsConstraintTimeline_set(constraint, type,spCurveTimeline1_getAbsoluteValue2(SUPER(self), time, alpha, blend, _spPhysicsConstraintTimeline_get(constraint, type), _spPhysicsConstraintTimeline_setup(constraint, type), value));
}
} else {
spPhysicsConstraint *constraint = skeleton->physicsConstraints[self->physicsConstraintIndex];
if (constraint->active) _spPhysicsConstraintTimeline_set(constraint, type, spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, _spPhysicsConstraintTimeline_get(constraint, type), _spPhysicsConstraintTimeline_setup(constraint, type)));
}
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(direction);
spPhysicsConstraint **physicsConstraints = skeleton->physicsConstraints;
for (int i = 0; i < skeleton->physicsConstraintsCount; i++) {
spPhysicsConstraint *constraint = physicsConstraints[i];
if (constraint->active && _spPhysicsConstraintTimeline_global(constraint->data, type))
_spPhysicsConstraintTimeline_set(constraint, type, spCurveTimeline1_getAbsoluteValue2(SUPER(self), time, alpha, blend, _spPhysicsConstraintTimeline_get(constraint, type), _spPhysicsConstraintTimeline_setup(constraint, type), value));
}
} else {
spPhysicsConstraint *constraint = skeleton->physicsConstraints[self->physicsConstraintIndex];
if (constraint->active) _spPhysicsConstraintTimeline_set(constraint, type, spCurveTimeline1_getAbsoluteValue(SUPER(self), time, alpha, blend, _spPhysicsConstraintTimeline_get(constraint, type), _spPhysicsConstraintTimeline_setup(constraint, type)));
}
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(direction);
}
spPhysicsConstraintTimeline *
spPhysicsConstraintTimeline_create(int frameCount, int bezierCount, int physicsConstraintIndex, spTimelineType type) {
spPhysicsConstraintTimeline *timeline = NEW(spPhysicsConstraintTimeline);
spPropertyId ids[1];
spPropertyId id;
switch(type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
id = SP_PROPERTY_PHYSICSCONSTRAINT_INERTIA;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
id = SP_PROPERTY_PHYSICSCONSTRAINT_STRENGTH;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
id = SP_PROPERTY_PHYSICSCONSTRAINT_DAMPING;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
id = SP_PROPERTY_PHYSICSCONSTRAINT_MASS;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
id = SP_PROPERTY_PHYSICSCONSTRAINT_WIND;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
id = SP_PROPERTY_PHYSICSCONSTRAINT_GRAVITY;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
id = SP_PROPERTY_PHYSICSCONSTRAINT_MIX;
break;
default:
// should never happen
id = SP_PROPERTY_PHYSICSCONSTRAINT_INERTIA;
}
ids[0] = ((spPropertyId) id << 32) | physicsConstraintIndex;
_spCurveTimeline_init(SUPER(timeline), frameCount, CURVE1_ENTRIES, bezierCount, ids, 1, type,
_spCurveTimeline_dispose, _spPhysicsConstraintTimeline_apply, _spCurveTimeline_setBezier);
timeline->physicsConstraintIndex = physicsConstraintIndex;
return timeline;
spPhysicsConstraintTimeline *timeline = NEW(spPhysicsConstraintTimeline);
spPropertyId ids[1];
spPropertyId id;
switch (type) {
case SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA:
id = SP_PROPERTY_PHYSICSCONSTRAINT_INERTIA;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH:
id = SP_PROPERTY_PHYSICSCONSTRAINT_STRENGTH;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING:
id = SP_PROPERTY_PHYSICSCONSTRAINT_DAMPING;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_MASS:
id = SP_PROPERTY_PHYSICSCONSTRAINT_MASS;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_WIND:
id = SP_PROPERTY_PHYSICSCONSTRAINT_WIND;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY:
id = SP_PROPERTY_PHYSICSCONSTRAINT_GRAVITY;
break;
case SP_TIMELINE_PHYSICSCONSTRAINT_MIX:
id = SP_PROPERTY_PHYSICSCONSTRAINT_MIX;
break;
default:
// should never happen
id = SP_PROPERTY_PHYSICSCONSTRAINT_INERTIA;
}
ids[0] = ((spPropertyId) id << 32) | physicsConstraintIndex;
_spCurveTimeline_init(SUPER(timeline), frameCount, CURVE1_ENTRIES, bezierCount, ids, 1, type,
_spCurveTimeline_dispose, _spPhysicsConstraintTimeline_apply, _spCurveTimeline_setBezier);
timeline->physicsConstraintIndex = physicsConstraintIndex;
return timeline;
}
void spPhysicsConstraintTimeline_setFrame(spPhysicsConstraintTimeline *self, int frame, float time, float value) {
spCurveTimeline1_setFrame(SUPER(self), frame, time, value);
spCurveTimeline1_setFrame(SUPER(self), frame, time, value);
}
/**/
void _spPhysicsConstraintResetTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float lastTime, float time,
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
spMixDirection direction) {
spPhysicsConstraintResetTimeline *self = (spPhysicsConstraintResetTimeline *)timeline;
spPhysicsConstraint *constraint = NULL;
if (self->physicsConstraintIndex != -1) {
constraint = skeleton->physicsConstraints[self->physicsConstraintIndex];
if (!constraint->active) return;
}
spEvent **firedEvents, int *eventsCount, float alpha, spMixBlend blend,
spMixDirection direction) {
spPhysicsConstraintResetTimeline *self = (spPhysicsConstraintResetTimeline *) timeline;
spPhysicsConstraint *constraint = NULL;
if (self->physicsConstraintIndex != -1) {
constraint = skeleton->physicsConstraints[self->physicsConstraintIndex];
if (!constraint->active) return;
}
float *frames = SUPER(self)->frames->items;
if (lastTime > time) {// Apply after lastTime for looped animations.
_spPhysicsConstraintResetTimeline_apply(SUPER(self), skeleton, lastTime, INT_MAX, NULL, 0, alpha, blend, direction);
lastTime = -1;
} else if (lastTime >= frames[SUPER(self)->frameCount - 1])// Last time is after last frame.
return;
if (time < frames[0]) return;
float *frames = SUPER(self)->frames->items;
if (lastTime > time) {// Apply after lastTime for looped animations.
_spPhysicsConstraintResetTimeline_apply(SUPER(self), skeleton, lastTime, INT_MAX, NULL, 0, alpha, blend, direction);
lastTime = -1;
} else if (lastTime >= frames[SUPER(self)->frameCount - 1])// Last time is after last frame.
return;
if (time < frames[0]) return;
if (lastTime < frames[0] || time >= frames[search(self->super.frames, lastTime) + 1]) {
if (constraint != NULL)
spPhysicsConstraint_reset(constraint);
else {
spPhysicsConstraint **physicsConstraints = skeleton->physicsConstraints;
for (int i = 0; i < skeleton->physicsConstraintsCount; i++) {
constraint = physicsConstraints[i];
if (constraint->active) spPhysicsConstraint_reset(constraint);
}
}
}
if (lastTime < frames[0] || time >= frames[search(self->super.frames, lastTime) + 1]) {
if (constraint != NULL)
spPhysicsConstraint_reset(constraint);
else {
spPhysicsConstraint **physicsConstraints = skeleton->physicsConstraints;
for (int i = 0; i < skeleton->physicsConstraintsCount; i++) {
constraint = physicsConstraints[i];
if (constraint->active) spPhysicsConstraint_reset(constraint);
}
}
}
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(alpha);
UNUSED(direction);
UNUSED(lastTime);
UNUSED(firedEvents);
UNUSED(eventsCount);
UNUSED(alpha);
UNUSED(direction);
}
void _spPhysicsConstraintResetTimeline_dispose(spTimeline *timeline) {
// no-op, spTimeline_dispose disposes frames.
UNUSED(timeline);
// no-op, spTimeline_dispose disposes frames.
UNUSED(timeline);
}
spPhysicsConstraintResetTimeline *spPhysicsConstraintResetTimeline_create(int framesCount, int physicsConstraintIndex) {
spPhysicsConstraintResetTimeline *self = NEW(spPhysicsConstraintResetTimeline);
spPropertyId ids[1];
ids[0] = (spPropertyId) SP_PROPERTY_PHYSICSCONSTRAINT_RESET << 32;
_spTimeline_init(SUPER(self), framesCount, 1, ids, 1, SP_TIMELINE_PHYSICSCONSTRAINT_RESET, _spPhysicsConstraintResetTimeline_dispose,
_spPhysicsConstraintResetTimeline_apply, 0);
spPhysicsConstraintResetTimeline *self = NEW(spPhysicsConstraintResetTimeline);
spPropertyId ids[1];
ids[0] = (spPropertyId) SP_PROPERTY_PHYSICSCONSTRAINT_RESET << 32;
_spTimeline_init(SUPER(self), framesCount, 1, ids, 1, SP_TIMELINE_PHYSICSCONSTRAINT_RESET, _spPhysicsConstraintResetTimeline_dispose,
_spPhysicsConstraintResetTimeline_apply, 0);
self->physicsConstraintIndex = physicsConstraintIndex;
self->physicsConstraintIndex = physicsConstraintIndex;
return self;
return self;
}
void spPhysicsConstraintResetTimeline_setFrame(spPhysicsConstraintResetTimeline *self, int frame, float time) {
self->super.frames->items[frame] = time;
self->super.frames->items[frame] = time;
}

View File

@ -399,10 +399,10 @@ int spAnimationState_apply(spAnimationState *self, spSkeleton *skeleton) {
/* Apply mixing from entries first. */
alpha = current->alpha;
if (current->mixingFrom)
alpha *= _spAnimationState_applyMixingFrom(self, current, skeleton, blend);
alpha *= _spAnimationState_applyMixingFrom(self, current, skeleton, blend);
else if (current->trackTime >= current->trackEnd && current->next == 0)
alpha = 0;
int/*bool*/ attachments = alpha >= current->alphaAttachmentThreshold;
alpha = 0;
int /*bool*/ attachments = alpha >= current->alphaAttachmentThreshold;
/* Apply current entry. */
animationLast = current->animationLast;
@ -422,7 +422,7 @@ int spAnimationState_apply(spAnimationState *self, spSkeleton *skeleton) {
_spAnimationState_applyAttachmentTimeline(self, timeline, skeleton, applyTime, blend, attachments);
} else {
spTimeline_apply(timelines[ii], skeleton, animationLast, applyTime, applyEvents,
&internal->eventsCount, alpha, blend, SP_MIX_DIRECTION_IN);
&internal->eventsCount, alpha, blend, SP_MIX_DIRECTION_IN);
}
}
} else {
@ -438,12 +438,12 @@ int spAnimationState_apply(spAnimationState *self, spSkeleton *skeleton) {
timelineBlend = timelineMode->items[ii] == SUBSEQUENT ? blend : SP_MIX_BLEND_SETUP;
if (!shortestRotation && timeline->type == SP_TIMELINE_ROTATE)
_spAnimationState_applyRotateTimeline(self, timeline, skeleton, applyTime, alpha, timelineBlend,
timelinesRotation, ii << 1, firstFrame);
timelinesRotation, ii << 1, firstFrame);
else if (timeline->type == SP_TIMELINE_ATTACHMENT)
_spAnimationState_applyAttachmentTimeline(self, timeline, skeleton, applyTime, timelineBlend, attachments);
else
spTimeline_apply(timeline, skeleton, animationLast, applyTime, applyEvents, &internal->eventsCount,
alpha, timelineBlend, SP_MIX_DIRECTION_IN);
alpha, timelineBlend, SP_MIX_DIRECTION_IN);
}
}
_spAnimationState_queueEvents(self, current, animationTime);
@ -665,8 +665,8 @@ void _spAnimationState_applyRotateTimeline(spAnimationState *self, spTimeline *t
/* Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. */
diff = r2 - r1;
diff -= CEIL(diff / 360 - 0.5) * 360;
if (diff == 0) {
diff -= CEIL(diff / 360 - 0.5) * 360;
if (diff == 0) {
total = timelinesRotation[i];
} else {
float lastTotal, lastDiff, loops;
@ -716,15 +716,15 @@ void _spAnimationState_queueEvents(spAnimationState *self, spTrackEntry *entry,
/* Queue complete if completed a loop iteration or the animation. */
if (entry->loop) {
if (duration == 0)
complete = -1;
else {
int cycles = (int) (entry->trackTime / duration);
complete = cycles > 0 && cycles > (int) (entry->trackLast / duration);
}
} else {
complete = (animationTime >= animationEnd && entry->animationLast < animationEnd);
}
if (duration == 0)
complete = -1;
else {
int cycles = (int) (entry->trackTime / duration);
complete = cycles > 0 && cycles > (int) (entry->trackLast / duration);
}
} else {
complete = (animationTime >= animationEnd && entry->animationLast < animationEnd);
}
if (complete) _spEventQueue_complete(internal->queue, entry);
/* Queue events after complete. */
@ -918,7 +918,7 @@ _spAnimationState_trackEntry(spAnimationState *self, int trackIndex, spAnimation
entry->eventThreshold = 0;
entry->mixAttachmentThreshold = 0;
entry->alphaAttachmentThreshold = 0;
entry->alphaAttachmentThreshold = 0;
entry->mixDrawOrderThreshold = 0;
entry->animationStart = 0;
@ -1060,13 +1060,13 @@ float spTrackEntry_getTrackComplete(spTrackEntry *entry) {
}
void spTrackEntry_setMixDuration(spTrackEntry *entry, float mixDuration, float delay) {
entry->mixDuration = mixDuration;
if (entry->previous && delay <= 0) delay += spTrackEntry_getTrackComplete(entry) - mixDuration;
entry->delay = delay;
entry->mixDuration = mixDuration;
if (entry->previous && delay <= 0) delay += spTrackEntry_getTrackComplete(entry) - mixDuration;
entry->delay = delay;
}
int spTrackEntry_wasApplied(spTrackEntry *entry) {
return entry->nextTrackLast != -1;
return entry->nextTrackLast != -1;
}
void _spTrackEntry_computeHold(spTrackEntry *entry, spAnimationState *state) {

View File

@ -48,8 +48,8 @@ spBone *spBone_create(spBoneData *data, spSkeleton *skeleton, spBone *parent) {
self->parent = parent;
self->a = 1.0f;
self->d = 1.0f;
self->active = -1;
self->inherit = SP_INHERIT_NORMAL;
self->active = -1;
self->inherit = SP_INHERIT_NORMAL;
spBone_setToSetupPose(self);
return self;
}
@ -70,10 +70,10 @@ void spBone_updateWorldTransform(spBone *self) {
void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotation, float scaleX, float scaleY,
float shearX, float shearY) {
float pa, pb, pc, pd;
float sx = self->skeleton->scaleX;
float sy = self->skeleton->scaleY * (spBone_isYDown() ? -1 : 1);
spBone *parent = self->parent;
float pa, pb, pc, pd;
float sx = self->skeleton->scaleX;
float sy = self->skeleton->scaleY * (spBone_isYDown() ? -1 : 1);
spBone *parent = self->parent;
self->ax = x;
self->ay = y;
@ -84,14 +84,14 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
self->ashearY = shearY;
if (!parent) { /* Root bone. */
float rx = (rotation + shearX) * DEG_RAD;
float ry = (rotation + 90 + shearY) * DEG_RAD;
self->a = COS(rx) * scaleX * sx;
self->b = COS(ry) * scaleY * sx;
self->c = SIN(rx) * scaleX * sy;
self->d = SIN(ry) * scaleY * sy;
self->worldX = x * sx + self->skeleton->x;
self->worldY = y * sy + self->skeleton->y;
float rx = (rotation + shearX) * DEG_RAD;
float ry = (rotation + 90 + shearY) * DEG_RAD;
self->a = COS(rx) * scaleX * sx;
self->b = COS(ry) * scaleY * sx;
self->c = SIN(rx) * scaleX * sy;
self->d = SIN(ry) * scaleY * sy;
self->worldX = x * sx + self->skeleton->x;
self->worldY = y * sy + self->skeleton->y;
return;
}
@ -105,12 +105,12 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
switch (self->inherit) {
case SP_INHERIT_NORMAL: {
float rx = (rotation + shearX) * DEG_RAD;
float ry = (rotation + 90 + shearY) * DEG_RAD;
float la = COS(rx) * scaleX;
float lb = COS(ry) * scaleY;
float lc = SIN(rx) * scaleX;
float ld = SIN(ry) * scaleY;
float rx = (rotation + shearX) * DEG_RAD;
float ry = (rotation + 90 + shearY) * DEG_RAD;
float la = COS(rx) * scaleX;
float lb = COS(ry) * scaleY;
float lc = SIN(rx) * scaleX;
float ld = SIN(ry) * scaleY;
self->a = pa * la + pb * lc;
self->b = pa * lb + pb * ld;
self->c = pc * la + pd * lc;
@ -118,12 +118,12 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
return;
}
case SP_INHERIT_ONLYTRANSLATION: {
float rx = (rotation + shearX) * DEG_RAD;
float ry = (rotation + 90 + shearY) * DEG_RAD;
self->a = COS(rx) * scaleX;
self->b = COS(ry) * scaleY;
self->c = SIN(rx) * scaleX;
self->d = SIN(ry) * scaleY;
float rx = (rotation + shearX) * DEG_RAD;
float ry = (rotation + 90 + shearY) * DEG_RAD;
self->a = COS(rx) * scaleX;
self->b = COS(ry) * scaleY;
self->c = SIN(rx) * scaleX;
self->d = SIN(ry) * scaleY;
break;
}
case SP_INHERIT_NOROTATIONORREFLECTION: {
@ -141,12 +141,12 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
pc = 0;
prx = 90 - ATAN2DEG(pd, pb);
}
float rx = (rotation + shearX - prx) *DEG_RAD;
float ry = (rotation + shearY - prx + 90) *DEG_RAD;
float la = COS(rx) * scaleX;
float lb = COS(ry) * scaleY;
float lc = SIN(rx) * scaleX;
float ld = SIN(ry) * scaleY;
float rx = (rotation + shearX - prx) * DEG_RAD;
float ry = (rotation + shearY - prx + 90) * DEG_RAD;
float la = COS(rx) * scaleX;
float lb = COS(ry) * scaleY;
float lc = SIN(rx) * scaleX;
float ld = SIN(ry) * scaleY;
self->a = pa * la - pb * lc;
self->b = pa * lb - pb * ld;
self->c = pc * la + pd * lc;
@ -155,23 +155,23 @@ void spBone_updateWorldTransformWith(spBone *self, float x, float y, float rotat
}
case SP_INHERIT_NOSCALE:
case SP_INHERIT_NOSCALEORREFLECTION: {
rotation *= DEG_RAD;
float cosine = COS(rotation);
float sine = SIN(rotation);
float za = (pa * cosine + pb * sine) / sx;
float zc = (pc * cosine + pd * sine) / sy;
float s = SQRT(za * za + zc * zc);
rotation *= DEG_RAD;
float cosine = COS(rotation);
float sine = SIN(rotation);
float za = (pa * cosine + pb * sine) / sx;
float zc = (pc * cosine + pd * sine) / sy;
float s = SQRT(za * za + zc * zc);
if (self->data->inherit == SP_INHERIT_NOSCALE && (pa * pd - pb * pc < 0) != (sx < 0 != sy < 0))
s = -s;
rotation = PI / 2 + ATAN2(zc, za);
float zb = COS(rotation) * s;
float zd = SIN(rotation) * s;
shearX *= DEG_RAD;
shearY = (90 + shearY) * DEG_RAD;
float la = COS(shearX) * scaleX;
float lb = COS(shearY) * scaleY;
float lc = SIN(shearX) * scaleX;
float ld = SIN(shearY) * scaleY;
rotation = PI / 2 + ATAN2(zc, za);
float zb = COS(rotation) * s;
float zd = SIN(rotation) * s;
shearX *= DEG_RAD;
shearY = (90 + shearY) * DEG_RAD;
float la = COS(shearX) * scaleX;
float lb = COS(shearY) * scaleY;
float lc = SIN(shearX) * scaleX;
float ld = SIN(shearY) * scaleY;
self->a = za * la + zb * lc;
self->b = za * lb + zb * ld;
self->c = zc * la + zd * lc;
@ -193,7 +193,7 @@ void spBone_setToSetupPose(spBone *self) {
self->scaleY = self->data->scaleY;
self->shearX = self->data->shearX;
self->shearY = self->data->shearY;
self->inherit = self->data->inherit;
self->inherit = self->data->inherit;
}
float spBone_getWorldRotationX(spBone *self) {
@ -225,7 +225,7 @@ void spBone_updateAppliedTransform(spBone *self) {
float s, sa, sc;
float cosine, sine;
float yDownScale = spBone_isYDown() ? -1 : 1;
float yDownScale = spBone_isYDown() ? -1 : 1;
spBone *parent = self->parent;
if (!parent) {
@ -266,7 +266,7 @@ void spBone_updateAppliedTransform(spBone *self) {
}
case SP_INHERIT_NOSCALE:
case SP_INHERIT_NOSCALEORREFLECTION: {
float r = self->rotation * DEG_RAD;
float r = self->rotation * DEG_RAD;
cosine = COS(r), sine = SIN(r);
pa = (pa * cosine + pb * sine) / self->skeleton->scaleX;
pc = (pc * cosine + pd * sine) / self->skeleton->scaleY * yDownScale;
@ -321,12 +321,12 @@ void spBone_worldToLocal(spBone *self, float worldX, float worldY, float *localX
}
void spBone_worldToParent(spBone *self, float worldX, float worldY, float *localX, float *localY) {
if (self->parent == NULL) {
*localX = worldX;
*localY = worldY;
} else {
spBone_worldToLocal(self->parent, worldX, worldY, localX, localY);
}
if (self->parent == NULL) {
*localX = worldX;
*localY = worldY;
} else {
spBone_worldToLocal(self->parent, worldX, worldY, localX, localY);
}
}
void spBone_localToWorld(spBone *self, float localX, float localY, float *worldX, float *worldY) {
@ -336,33 +336,32 @@ void spBone_localToWorld(spBone *self, float localX, float localY, float *worldX
}
void spBone_parentToWorld(spBone *self, float localX, float localY, float *worldX, float *worldY) {
if (self->parent != NULL) {
*worldX = localX;
*worldY = localY;
} else {
spBone_localToWorld(self->parent, localX, localY, worldX, worldY);
}
if (self->parent != NULL) {
*worldX = localX;
*worldY = localY;
} else {
spBone_localToWorld(self->parent, localX, localY, worldX, worldY);
}
}
float spBone_worldToLocalRotation(spBone *self, float worldRotation) {
worldRotation *= DEG_RAD;
float sine = SIN(worldRotation), cosine = COS(worldRotation);
return ATAN2DEG(self->a * sine - self->c * cosine, self->d * cosine - self->b * sine) + self->rotation - self->shearX;
worldRotation *= DEG_RAD;
float sine = SIN(worldRotation), cosine = COS(worldRotation);
return ATAN2DEG(self->a * sine - self->c * cosine, self->d * cosine - self->b * sine) + self->rotation - self->shearX;
}
float spBone_localToWorldRotation(spBone *self, float localRotation) {
localRotation = (localRotation - self->rotation - self->shearX) * DEG_RAD;
float sine = SIN(localRotation), cosine = COS(localRotation);
return ATAN2DEG(cosine * self->c + sine * self->d, cosine * self->a + sine * self->b);
localRotation = (localRotation - self->rotation - self->shearX) * DEG_RAD;
float sine = SIN(localRotation), cosine = COS(localRotation);
return ATAN2DEG(cosine * self->c + sine * self->d, cosine * self->a + sine * self->b);
}
void spBone_rotateWorld(spBone *self, float degrees) {
degrees *= DEG_RAD;
float sine = SIN(degrees), cosine = COS(degrees);
float ra = self->a, rb = self->b;
self->a = cosine * ra - sine * self->c;
self->b = cosine * rb - sine * self->d;
self->c = sine * ra + cosine * self->c;
self->d = sine * rb + cosine * self->d;
degrees *= DEG_RAD;
float sine = SIN(degrees), cosine = COS(degrees);
float ra = self->a, rb = self->b;
self->a = cosine * ra - sine * self->c;
self->b = cosine * rb - sine * self->d;
self->c = sine * ra + cosine * self->c;
self->d = sine * rb + cosine * self->d;
}

View File

@ -38,13 +38,13 @@ spBoneData *spBoneData_create(int index, const char *name, spBoneData *parent) {
self->scaleX = 1;
self->scaleY = 1;
self->inherit = SP_INHERIT_NORMAL;
self->icon = NULL;
self->visible = -1;
return self;
self->icon = NULL;
self->visible = -1;
return self;
}
void spBoneData_dispose(spBoneData *self) {
FREE(self->name);
FREE(self->icon);
FREE(self->icon);
FREE(self);
}

View File

@ -209,13 +209,13 @@ void spDebug_printTimeline(spTimeline *timeline) {
spSequenceTimeline *t = (spSequenceTimeline *) timeline;
_spDebug_printTimelineBase(&t->super);
}
case SP_TIMELINE_INHERIT: {
spInheritTimeline *t = (spInheritTimeline *) timeline;
_spDebug_printTimelineBase(&t->super);
}
default: {
_spDebug_printTimelineBase(timeline);
}
case SP_TIMELINE_INHERIT: {
spInheritTimeline *t = (spInheritTimeline *) timeline;
_spDebug_printTimelineBase(&t->super);
}
default: {
_spDebug_printTimelineBase(timeline);
}
}
}

View File

@ -72,11 +72,11 @@ void spIkConstraint_update(spIkConstraint *self) {
}
void spIkConstraint_setToSetupPose(spIkConstraint *self) {
self->bendDirection = self->data->bendDirection;
self->compress = self->data->compress;
self->stretch = self->data->stretch;
self->softness = self->data->softness;
self->mix = self->data->mix;
self->bendDirection = self->data->bendDirection;
self->compress = self->data->compress;
self->stretch = self->data->stretch;
self->softness = self->data->softness;
self->mix = self->data->mix;
}
void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boolean*/ compress, int /*boolean*/ stretch,

View File

@ -117,9 +117,9 @@ void spPathConstraint_update(spPathConstraint *self) {
for (i = 0, n = spacesCount - 1; i < n; i++) {
spBone *bone = bones[i];
setupLength = bone->data->length;
x = setupLength * bone->a;
y = setupLength * bone->c;
lengths[i] = SQRT(x * x + y * y);
x = setupLength * bone->a;
y = setupLength * bone->c;
lengths[i] = SQRT(x * x + y * y);
}
}
for (i = 1, n = spacesCount; i < n; i++) spaces[i] = spacing;
@ -222,12 +222,12 @@ void spPathConstraint_update(spPathConstraint *self) {
}
void spPathConstraint_setToSetupPose(spPathConstraint *self) {
spPathConstraintData *data = self->data;
self->position = data->position;
self->spacing = data->spacing;
self->mixRotate = data->mixRotate;
self->mixX = data->mixX;
self->mixY = data->mixY;
spPathConstraintData *data = self->data;
self->position = data->position;
self->spacing = data->spacing;
self->mixRotate = data->mixRotate;
self->mixX = data->mixX;
self->mixY = data->mixY;
}
static void _addBeforePosition(float p, float *temp, int i, float *out, int o) {

View File

@ -32,35 +32,35 @@
#include <spine/extension.h>
spPhysicsConstraint *spPhysicsConstraint_create(spPhysicsConstraintData *data, spSkeleton *skeleton) {
spPhysicsConstraint *self = NEW(spPhysicsConstraint);
spPhysicsConstraint *self = NEW(spPhysicsConstraint);
self->data = data;
self->skeleton = skeleton;
self->bone = skeleton->bones[data->bone->index];
self->inertia = data->inertia;
self->strength = data->strength;
self->damping = data->damping;
self->massInverse = data->massInverse;
self->wind = data->wind;
self->gravity = data->gravity;
self->mix = data->mix;
self->skeleton = skeleton;
self->bone = skeleton->bones[data->bone->index];
self->inertia = data->inertia;
self->strength = data->strength;
self->damping = data->damping;
self->massInverse = data->massInverse;
self->wind = data->wind;
self->gravity = data->gravity;
self->mix = data->mix;
self->reset = -1;
self->ux = 0;
self->uy = 0;
self->cx = 0;
self->tx = 0;
self->ty = 0;
self->xOffset = 0;
self->xVelocity = 0;
self->yOffset = 0;
self->yVelocity = 0;
self->rotateOffset = 0;
self->rotateVelocity = 0;
self->scaleOffset = 0;
self->scaleVelocity = 0;
self->active = 0;
self->remaining = 0;
self->lastTime = 0;
self->reset = -1;
self->ux = 0;
self->uy = 0;
self->cx = 0;
self->tx = 0;
self->ty = 0;
self->xOffset = 0;
self->xVelocity = 0;
self->yOffset = 0;
self->yVelocity = 0;
self->rotateOffset = 0;
self->rotateVelocity = 0;
self->scaleOffset = 0;
self->scaleVelocity = 0;
self->active = 0;
self->remaining = 0;
self->lastTime = 0;
return self;
}
@ -69,210 +69,210 @@ void spPhysicsConstraint_dispose(spPhysicsConstraint *self) {
}
void spPhysicsConstraint_reset(spPhysicsConstraint *self) {
self->remaining = 0;
self->lastTime = self->skeleton->time;
self->reset = -1;
self->xOffset = 0;
self->xVelocity = 0;
self->yOffset = 0;
self->yVelocity = 0;
self->rotateOffset = 0;
self->rotateVelocity = 0;
self->scaleOffset = 0;
self->scaleVelocity = 0;
self->remaining = 0;
self->lastTime = self->skeleton->time;
self->reset = -1;
self->xOffset = 0;
self->xVelocity = 0;
self->yOffset = 0;
self->yVelocity = 0;
self->rotateOffset = 0;
self->rotateVelocity = 0;
self->scaleOffset = 0;
self->scaleVelocity = 0;
}
void spPhysicsConstraint_setToSetupPose(spPhysicsConstraint *self) {
self->inertia = self->data->inertia;
self->strength = self->data->strength;
self->damping = self->data->damping;
self->massInverse = self->data->massInverse;
self->wind = self->data->wind;
self->gravity = self->data->gravity;
self->mix = self->data->mix;
self->inertia = self->data->inertia;
self->strength = self->data->strength;
self->damping = self->data->damping;
self->massInverse = self->data->massInverse;
self->wind = self->data->wind;
self->gravity = self->data->gravity;
self->mix = self->data->mix;
}
void spPhysicsConstraint_update(spPhysicsConstraint *self, spPhysics physics) {
float mix = self->mix;
if (mix == 0) return;
float mix = self->mix;
if (mix == 0) return;
int x = self->data->x > 0;
int y = self->data->y > 0;
int rotateOrShearX = self->data->rotate > 0 || self->data->shearX > 0;
int scaleX = self->data->scaleX > 0;
int x = self->data->x > 0;
int y = self->data->y > 0;
int rotateOrShearX = self->data->rotate > 0 || self->data->shearX > 0;
int scaleX = self->data->scaleX > 0;
spBone *bone = self->bone;
float l = bone->data->length;
spBone *bone = self->bone;
float l = bone->data->length;
switch (physics) {
case SP_PHYSICS_NONE:
return;
case SP_PHYSICS_RESET:
spPhysicsConstraint_reset(self);
// Fall through.
case SP_PHYSICS_UPDATE: {
float delta = MAX(self->skeleton->time - self->lastTime, 0.0f);
self->remaining += delta;
self->lastTime = self->skeleton->time;
switch (physics) {
case SP_PHYSICS_NONE:
return;
case SP_PHYSICS_RESET:
spPhysicsConstraint_reset(self);
// Fall through.
case SP_PHYSICS_UPDATE: {
float delta = MAX(self->skeleton->time - self->lastTime, 0.0f);
self->remaining += delta;
self->lastTime = self->skeleton->time;
float bx = bone->worldX, by = bone->worldY;
if (self->reset) {
self->reset = 0;
self->ux = bx;
self->uy = by;
} else {
float a = self->remaining, i = self->inertia, q = self->data->limit * delta, t = self->data->step, f = self->skeleton->data->referenceScale, d = -1;
if (x || y) {
if (x) {
float u = (self->ux - bx) * i;
self->xOffset += u > q ? q : u < -q ? -q
: u;
self->ux = bx;
}
if (y) {
float u = (self->uy - by) * i;
self->yOffset += u > q ? q : u < -q ? -q
: u;
self->uy = by;
}
if (a >= t) {
d = POW(self->damping, 60 * t);
float m = self->massInverse * t, e = self->strength, w = self->wind * f, g = self->gravity * f * (spBone_isYDown() ? -1 : 1);
do {
if (x) {
self->xVelocity += (w - self->xOffset * e) * m;
self->xOffset += self->xVelocity * t;
self->xVelocity *= d;
}
if (y) {
self->yVelocity -= (g + self->yOffset * e) * m;
self->yOffset += self->yVelocity * t;
self->yVelocity *= d;
}
a -= t;
} while (a >= t);
}
if (x) bone->worldX += self->xOffset * mix * self->data->x;
if (y) bone->worldY += self->yOffset * mix * self->data->y;
}
float bx = bone->worldX, by = bone->worldY;
if (self->reset) {
self->reset = 0;
self->ux = bx;
self->uy = by;
} else {
float a = self->remaining, i = self->inertia, q = self->data->limit * delta, t = self->data->step, f = self->skeleton->data->referenceScale, d = -1;
if (x || y) {
if (x) {
float u = (self->ux - bx) * i;
self->xOffset += u > q ? q : u < -q ? -q
: u;
self->ux = bx;
}
if (y) {
float u = (self->uy - by) * i;
self->yOffset += u > q ? q : u < -q ? -q
: u;
self->uy = by;
}
if (a >= t) {
d = POW(self->damping, 60 * t);
float m = self->massInverse * t, e = self->strength, w = self->wind * f, g = self->gravity * f * (spBone_isYDown() ? -1 : 1);
do {
if (x) {
self->xVelocity += (w - self->xOffset * e) * m;
self->xOffset += self->xVelocity * t;
self->xVelocity *= d;
}
if (y) {
self->yVelocity -= (g + self->yOffset * e) * m;
self->yOffset += self->yVelocity * t;
self->yVelocity *= d;
}
a -= t;
} while (a >= t);
}
if (x) bone->worldX += self->xOffset * mix * self->data->x;
if (y) bone->worldY += self->yOffset * mix * self->data->y;
}
if (rotateOrShearX || scaleX) {
float ca = ATAN2(bone->c, bone->a), c, s, mr = 0;
float dx = self->cx - bone->worldX, dy = self->cy - bone->worldY;
if (dx > q)
dx = q;
else if (dx < -q)//
dx = -q;
if (dy > q)
dy = q;
else if (dy < -q)//
dy = -q;
if (rotateOrShearX) {
mr = (self->data->rotate + self->data->shearX) * mix;
float r = ATAN2(dy + self->ty, dx + self->tx) - ca - self->rotateOffset * mr;
self->rotateOffset += (r - CEIL(r * INV_PI2 - 0.5f) * PI2) * i;
r = self->rotateOffset * mr + ca;
c = COS(r);
s = SIN(r);
if (scaleX) {
r = l * spBone_getWorldScaleX(bone);
if (r > 0) self->scaleOffset += (dx * c + dy * s) * i / r;
}
} else {
c = COS(ca);
s = SIN(ca);
float r = l * spBone_getWorldScaleX(bone);
if (r > 0) self->scaleOffset += (dx * c + dy * s) * i / r;
}
a = self->remaining;
if (a >= t) {
if (d == -1) d = POW(self->damping, 60 * t);
float m = self->massInverse * t, e = self->strength, w = self->wind, g = self->gravity, h = l / f;
while (-1) {
a -= t;
if (scaleX) {
self->scaleVelocity += (w * c - g * s - self->scaleOffset * e) * m;
self->scaleOffset += self->scaleVelocity * t;
self->scaleVelocity *= d;
}
if (rotateOrShearX) {
self->rotateVelocity -= ((w * s + g * c) * h + self->rotateOffset * e) * m;
self->rotateOffset += self->rotateVelocity * t;
self->rotateVelocity *= d;
if (a < t) break;
float r = self->rotateOffset * mr + ca;
c = COS(r);
s = SIN(r);
} else if (a < t)//
break;
}
}
}
self->remaining = a;
}
if (rotateOrShearX || scaleX) {
float ca = ATAN2(bone->c, bone->a), c, s, mr = 0;
float dx = self->cx - bone->worldX, dy = self->cy - bone->worldY;
if (dx > q)
dx = q;
else if (dx < -q)//
dx = -q;
if (dy > q)
dy = q;
else if (dy < -q)//
dy = -q;
if (rotateOrShearX) {
mr = (self->data->rotate + self->data->shearX) * mix;
float r = ATAN2(dy + self->ty, dx + self->tx) - ca - self->rotateOffset * mr;
self->rotateOffset += (r - CEIL(r * INV_PI2 - 0.5f) * PI2) * i;
r = self->rotateOffset * mr + ca;
c = COS(r);
s = SIN(r);
if (scaleX) {
r = l * spBone_getWorldScaleX(bone);
if (r > 0) self->scaleOffset += (dx * c + dy * s) * i / r;
}
} else {
c = COS(ca);
s = SIN(ca);
float r = l * spBone_getWorldScaleX(bone);
if (r > 0) self->scaleOffset += (dx * c + dy * s) * i / r;
}
a = self->remaining;
if (a >= t) {
if (d == -1) d = POW(self->damping, 60 * t);
float m = self->massInverse * t, e = self->strength, w = self->wind, g = self->gravity, h = l / f;
while (-1) {
a -= t;
if (scaleX) {
self->scaleVelocity += (w * c - g * s - self->scaleOffset * e) * m;
self->scaleOffset += self->scaleVelocity * t;
self->scaleVelocity *= d;
}
if (rotateOrShearX) {
self->rotateVelocity -= ((w * s + g * c) * h + self->rotateOffset * e) * m;
self->rotateOffset += self->rotateVelocity * t;
self->rotateVelocity *= d;
if (a < t) break;
float r = self->rotateOffset * mr + ca;
c = COS(r);
s = SIN(r);
} else if (a < t)//
break;
}
}
}
self->remaining = a;
}
self->cx = bone->worldX;
self->cy = bone->worldY;
break;
}
case SP_PHYSICS_POSE: {
if (x) bone->worldX += self->xOffset * mix * self->data->x;
if (y) bone->worldY += self->yOffset * mix * self->data->y;
break;
}
}
self->cx = bone->worldX;
self->cy = bone->worldY;
break;
}
case SP_PHYSICS_POSE: {
if (x) bone->worldX += self->xOffset * mix * self->data->x;
if (y) bone->worldY += self->yOffset * mix * self->data->y;
break;
}
}
if (rotateOrShearX) {
float o = self->rotateOffset * mix, s = 0, c = 0, a = 0;
if (self->data->shearX > 0) {
float r = 0;
if (self->data->rotate > 0) {
r = o * self->data->rotate;
s = SIN(r);
c = COS(r);
a = bone->b;
bone->b = c * a - s * bone->d;
bone->d = s * a + c * bone->d;
}
r += o * self->data->shearX;
s = SIN(r);
c = COS(r);
a = bone->a;
bone->a = c * a - s * bone->c;
bone->c = s * a + c * bone->c;
} else {
o *= self->data->rotate;
s = SIN(o);
c = COS(o);
a = bone->a;
bone->a = c * a - s * bone->c;
bone->c = s * a + c * bone->c;
a = bone->b;
bone->b = c * a - s * bone->d;
bone->d = s * a + c * bone->d;
}
}
if (scaleX) {
float s = 1 + self->scaleOffset * mix * self->data->scaleX;
bone->a *= s;
bone->c *= s;
}
if (physics != SP_PHYSICS_POSE) {
self->tx = l * bone->a;
self->ty = l * bone->c;
}
spBone_updateAppliedTransform(bone);
if (rotateOrShearX) {
float o = self->rotateOffset * mix, s = 0, c = 0, a = 0;
if (self->data->shearX > 0) {
float r = 0;
if (self->data->rotate > 0) {
r = o * self->data->rotate;
s = SIN(r);
c = COS(r);
a = bone->b;
bone->b = c * a - s * bone->d;
bone->d = s * a + c * bone->d;
}
r += o * self->data->shearX;
s = SIN(r);
c = COS(r);
a = bone->a;
bone->a = c * a - s * bone->c;
bone->c = s * a + c * bone->c;
} else {
o *= self->data->rotate;
s = SIN(o);
c = COS(o);
a = bone->a;
bone->a = c * a - s * bone->c;
bone->c = s * a + c * bone->c;
a = bone->b;
bone->b = c * a - s * bone->d;
bone->d = s * a + c * bone->d;
}
}
if (scaleX) {
float s = 1 + self->scaleOffset * mix * self->data->scaleX;
bone->a *= s;
bone->c *= s;
}
if (physics != SP_PHYSICS_POSE) {
self->tx = l * bone->a;
self->ty = l * bone->c;
}
spBone_updateAppliedTransform(bone);
}
void spPhysicsConstraint_rotate(spPhysicsConstraint *self, float x, float y, float degrees) {
float r = degrees * DEG_RAD, cosine = COS(r), sine = SIN(r);
float dx = self->cx - x, dy = self->cy - y;
spPhysicsConstraint_translate(self, dx * cosine - dy * sine - dx, dx * sine + dy * cosine - dy);
float r = degrees * DEG_RAD, cosine = COS(r), sine = SIN(r);
float dx = self->cx - x, dy = self->cy - y;
spPhysicsConstraint_translate(self, dx * cosine - dy * sine - dx, dx * sine + dy * cosine - dy);
}
void spPhysicsConstraint_translate(spPhysicsConstraint *self, float x, float y) {
self->ux -= x;
self->uy -= y;
self->cx -= x;
self->cy -= y;
self->ux -= x;
self->uy -= y;
self->cx -= x;
self->cy -= y;
}

View File

@ -31,30 +31,30 @@
#include <spine/extension.h>
spPhysicsConstraintData *spPhysicsConstraintData_create(const char *name) {
spPhysicsConstraintData *self = NEW(spPhysicsConstraintData);
spPhysicsConstraintData *self = NEW(spPhysicsConstraintData);
MALLOC_STR(self->name, name);
self->bone = NULL;
self->x = 0;
self->y = 0;
self->rotate = 0;
self->scaleX = 0;
self->shearX = 0;
self->limit = 0;
self->step = 0;
self->inertia = 0;
self->strength = 0;
self->damping = 0;
self->massInverse = 0;
self->wind = 0;
self->gravity = 0;
self->mix = 0;
self->inertiaGlobal = 0;
self->strengthGlobal = 0;
self->dampingGlobal = 0;
self->massGlobal = 0;
self->windGlobal = 0;
self->gravityGlobal = 0;
self->mixGlobal = 0;
self->bone = NULL;
self->x = 0;
self->y = 0;
self->rotate = 0;
self->scaleX = 0;
self->shearX = 0;
self->limit = 0;
self->step = 0;
self->inertia = 0;
self->strength = 0;
self->damping = 0;
self->massInverse = 0;
self->wind = 0;
self->gravity = 0;
self->mix = 0;
self->inertiaGlobal = 0;
self->strengthGlobal = 0;
self->dampingGlobal = 0;
self->massGlobal = 0;
self->windGlobal = 0;
self->gravityGlobal = 0;
self->mixGlobal = 0;
return self;
}

View File

@ -58,8 +58,8 @@ void spPointAttachment_computeWorldPosition(spPointAttachment *self, spBone *bon
}
float spPointAttachment_computeWorldRotation(spPointAttachment *self, spBone *bone) {
float r = self->rotation * DEG_RAD, cosine = COS(r), sine = SIN(r);
float x = cosine * bone->a + sine * bone->b;
float y = cosine * bone->c + sine * bone->d;
return ATAN2DEG(y, x);
float r = self->rotation * DEG_RAD, cosine = COS(r), sine = SIN(r);
float x = cosine * bone->a + sine * bone->b;
float y = cosine * bone->c + sine * bone->d;
return ATAN2DEG(y, x);
}

View File

@ -85,7 +85,7 @@ spSkeleton *spSkeleton_create(spSkeletonData *data) {
for (i = 0; i < self->bonesCount; ++i) {
spBoneData *boneData = self->data->bones[i];
spBone *bone = self->bones[i];
bone->children = MALLOC(spBone *, childrenCounts[boneData->index]);
bone->children = MALLOC(spBone *, childrenCounts[boneData->index]);
}
for (i = 0; i < self->bonesCount; ++i) {
spBone *bone = self->bones[i];
@ -132,7 +132,7 @@ spSkeleton *spSkeleton_create(spSkeletonData *data) {
self->scaleX = 1;
self->scaleY = 1;
self->time = 0;
self->time = 0;
spSkeleton_updateCache(self);
@ -342,9 +342,9 @@ static void _sortTransformConstraint(_spSkeleton *const internal, spTransformCon
static void _sortPhysicsConstraint(_spSkeleton *const internal, spPhysicsConstraint *constraint) {
spBone *bone = constraint->bone;
constraint->active = constraint->bone->active && (!constraint->data->skinRequired || (internal->super.skin != 0 &&
spPhysicsConstraintDataArray_contains(
internal->super.skin->physicsConstraints,
constraint->data)));
spPhysicsConstraintDataArray_contains(
internal->super.skin->physicsConstraints,
constraint->data)));
if (!constraint->active)
return;
@ -367,7 +367,7 @@ void spSkeleton_updateCache(spSkeleton *self) {
internal->updateCacheCapacity =
self->bonesCount + self->ikConstraintsCount + self->transformConstraintsCount + self->pathConstraintsCount +
self->physicsConstraintsCount;
self->physicsConstraintsCount;
FREE(internal->updateCache);
internal->updateCache = MALLOC(_spUpdate, internal->updateCacheCapacity);
internal->updateCacheCount = 0;
@ -483,7 +483,7 @@ void spSkeleton_updateWorldTransform(const spSkeleton *self, spPhysics physics)
}
void spSkeleton_update(spSkeleton *self, float delta) {
self->time += delta;
self->time += delta;
}
void spSkeleton_updateWorldTransformWith(const spSkeleton *self, const spBone *parent, spPhysics physics) {

View File

@ -58,53 +58,53 @@ typedef struct {
} _spSkeletonBinary;
static int string_lastIndexOf(const char *str, char needle) {
if (!str) return -1;
int lastIndex = -1;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == needle) {
lastIndex = i;
}
}
return lastIndex;
if (!str) return -1;
int lastIndex = -1;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == needle) {
lastIndex = i;
}
}
return lastIndex;
}
static char *string_substring(const char *str, int start, int end) {
if (str == NULL || start > end || start < 0) {
return NULL;
}
if (str == NULL || start > end || start < 0) {
return NULL;
}
int len = end - start;
char *substr = MALLOC(char, len + 1);
if (substr == NULL) {
return NULL;
}
int len = end - start;
char *substr = MALLOC(char, len + 1);
if (substr == NULL) {
return NULL;
}
strncpy(substr, str + start, len);
substr[len] = '\0';
strncpy(substr, str + start, len);
substr[len] = '\0';
return substr;
return substr;
}
static int string_starts_with(const char *str, const char *needle) {
int lenStr, lenNeedle, i;
if (!str) return 0;
lenStr = strlen(str);
lenNeedle = strlen(needle);
if (lenStr < lenNeedle) return 0;
for (i = 0; i < lenNeedle; i++) {
if (str[i] != needle[i]) return 0;
}
return -1;
int lenStr, lenNeedle, i;
if (!str) return 0;
lenStr = strlen(str);
lenNeedle = strlen(needle);
if (lenStr < lenNeedle) return 0;
for (i = 0; i < lenNeedle; i++) {
if (str[i] != needle[i]) return 0;
}
return -1;
}
static char *string_copy(const char *str) {
if (str == NULL) return NULL;
int len = strlen(str);
char *tmp = malloc(len + 1);
strncpy(tmp, str, len);
tmp[len] = '\0';
return tmp;
if (str == NULL) return NULL;
int len = strlen(str);
char *tmp = malloc(len + 1);
strncpy(tmp, str, len);
tmp[len] = '\0';
return tmp;
}
spSkeletonBinary *spSkeletonBinary_createWithLoader(spAttachmentLoader *attachmentLoader) {
@ -314,7 +314,7 @@ static void readTimeline(_dataInput *input, spTimelineArray *timelines, spCurveT
time = time2;
value = value2;
}
spTimelineArray_add(timelines, SUPER(timeline));
spTimelineArray_add(timelines, SUPER(timeline));
}
static void readTimeline2(_dataInput *input, spTimelineArray *timelines, spCurveTimeline2 *timeline, float scale) {
@ -610,60 +610,60 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
for (ii = 0, nn = readVarint(input, 1); ii < nn; ++ii) {
unsigned char timelineType = readByte(input);
int frameCount = readVarint(input, 1);
if (timelineType == BONE_INHERIT) {
spInheritTimeline *timeline = spInheritTimeline_create(frameCount, boneIndex);
for (frame = 0; frame < frameCount; frame++) {
float time = readFloat(input);
spInherit inherit = readByte(input);
spInheritTimeline_setFrame(timeline, frame, time, inherit);
}
spTimelineArray_add(timelines, SUPER(timeline));
continue;
}
if (timelineType == BONE_INHERIT) {
spInheritTimeline *timeline = spInheritTimeline_create(frameCount, boneIndex);
for (frame = 0; frame < frameCount; frame++) {
float time = readFloat(input);
spInherit inherit = readByte(input);
spInheritTimeline_setFrame(timeline, frame, time, inherit);
}
spTimelineArray_add(timelines, SUPER(timeline));
continue;
}
int bezierCount = readVarint(input, 1);
switch (timelineType) {
case BONE_ROTATE:
readTimeline(input, timelines, SUPER(spRotateTimeline_create(frameCount, bezierCount, boneIndex)),
1);
1);
break;
case BONE_TRANSLATE:
readTimeline2(input,timelines,
SUPER(spTranslateTimeline_create(frameCount, bezierCount, boneIndex)),
scale);
readTimeline2(input, timelines,
SUPER(spTranslateTimeline_create(frameCount, bezierCount, boneIndex)),
scale);
break;
case BONE_TRANSLATEX:
readTimeline(input, timelines,
SUPER(spTranslateXTimeline_create(frameCount, bezierCount, boneIndex)),
scale);
SUPER(spTranslateXTimeline_create(frameCount, bezierCount, boneIndex)),
scale);
break;
case BONE_TRANSLATEY:
readTimeline(input, timelines,
SUPER(spTranslateYTimeline_create(frameCount, bezierCount, boneIndex)),
scale);
SUPER(spTranslateYTimeline_create(frameCount, bezierCount, boneIndex)),
scale);
break;
case BONE_SCALE:
readTimeline2(input, timelines, SUPER(spScaleTimeline_create(frameCount, bezierCount, boneIndex)),
1);
1);
break;
case BONE_SCALEX:
readTimeline(input, timelines, SUPER(spScaleXTimeline_create(frameCount, bezierCount, boneIndex)),
1);
1);
break;
case BONE_SCALEY:
readTimeline(input, timelines, SUPER(spScaleYTimeline_create(frameCount, bezierCount, boneIndex)),
1);
1);
break;
case BONE_SHEAR:
readTimeline2(input, timelines, SUPER(spShearTimeline_create(frameCount, bezierCount, boneIndex)),
1);
1);
break;
case BONE_SHEARX:
readTimeline(input, timelines, SUPER(spShearXTimeline_create(frameCount, bezierCount, boneIndex)),
1);
1);
break;
case BONE_SHEARY:
readTimeline(input, timelines, SUPER(spShearYTimeline_create(frameCount, bezierCount, boneIndex)),
1);
1);
break;
default: {
for (iii = 0; iii < timelines->size; ++iii)
@ -684,20 +684,20 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
int frameLast = frameCount - 1;
int bezierCount = readVarint(input, 1);
spIkConstraintTimeline *timeline = spIkConstraintTimeline_create(frameCount, bezierCount, index);
int flags = readByte(input);
float time = readFloat(input), mix = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0;
float softness = (flags & 4) != 0 ? readFloat(input) * scale : 0;
int flags = readByte(input);
float time = readFloat(input), mix = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0;
float softness = (flags & 4) != 0 ? readFloat(input) * scale : 0;
for (frame = 0, bezier = 0;; frame++) {
spIkConstraintTimeline_setFrame(timeline, frame, time, mix, softness, (flags & 8) != 0 ? 1 : -1, (flags & 16) != 0, (flags & 32) != 0);
spIkConstraintTimeline_setFrame(timeline, frame, time, mix, softness, (flags & 8) != 0 ? 1 : -1, (flags & 16) != 0, (flags & 32) != 0);
if (frame == frameLast) break;
flags = readByte(input);
float time2 = readFloat(input), mix2 = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0;
float softness2 = (flags & 4) != 0 ? readFloat(input) * scale : 0;
if ((flags & 64) != 0)
spCurveTimeline_setStepped(SUPER(timeline), frame);
else if ((flags & 128) != 0) {
setBezier(input, SUPER(SUPER(timeline)), bezier++, frame, 0, time, time2, mix, mix2, 1);
setBezier(input, SUPER(SUPER(timeline)), bezier++, frame, 1, time, time2, softness, softness2, scale);
flags = readByte(input);
float time2 = readFloat(input), mix2 = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0;
float softness2 = (flags & 4) != 0 ? readFloat(input) * scale : 0;
if ((flags & 64) != 0)
spCurveTimeline_setStepped(SUPER(timeline), frame);
else if ((flags & 128) != 0) {
setBezier(input, SUPER(SUPER(timeline)), bezier++, frame, 0, time, time2, mix, mix2, 1);
setBezier(input, SUPER(SUPER(timeline)), bezier++, frame, 1, time, time2, softness, softness2, scale);
}
time = time2;
mix = mix2;
@ -766,19 +766,19 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
switch (type) {
case PATH_POSITION: {
readTimeline(input, timelines, SUPER(spPathConstraintPositionTimeline_create(frameCount, bezierCount, index)),
data->positionMode == SP_POSITION_MODE_FIXED ? scale
: 1);
data->positionMode == SP_POSITION_MODE_FIXED ? scale
: 1);
break;
}
case PATH_SPACING: {
readTimeline(input, timelines,
SUPER(spPathConstraintSpacingTimeline_create(frameCount,
bezierCount,
index)),
data->spacingMode == SP_SPACING_MODE_LENGTH ||
data->spacingMode == SP_SPACING_MODE_FIXED
? scale
: 1);
SUPER(spPathConstraintSpacingTimeline_create(frameCount,
bezierCount,
index)),
data->spacingMode == SP_SPACING_MODE_LENGTH ||
data->spacingMode == SP_SPACING_MODE_FIXED
? scale
: 1);
break;
}
case PATH_MIX: {
@ -821,43 +821,43 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
}
}
for (i = 0, n = readVarint(input, 1); i < n; i++) {
int index = readVarint(input, 1) - 1;
for (ii = 0, nn = readVarint(input, 1); ii < nn; ii++) {
int type = readByte(input);
int frameCount = readVarint(input, 1);
if (type == PHYSICS_RESET) {
spPhysicsConstraintResetTimeline *timeline = spPhysicsConstraintResetTimeline_create(frameCount, index);
for (frame = 0; frame < frameCount; frame++)
spPhysicsConstraintResetTimeline_setFrame(timeline, frame, readFloat(input));
spTimelineArray_add(timelines, SUPER(timeline));
continue;
}
int bezierCount = readVarint(input, 1);
switch (type) {
case PHYSICS_INERTIA:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA)), 1);
break;
case PHYSICS_STRENGTH:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH)), 1);
break;
case PHYSICS_DAMPING:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING)), 1);
break;
case PHYSICS_MASS:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_MASS)), 1);
break;
case PHYSICS_WIND:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_WIND)), 1);
break;
case PHYSICS_GRAVITY:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY)), 1);
break;
case PHYSICS_MIX:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_MIX)), 1);
}
}
}
for (i = 0, n = readVarint(input, 1); i < n; i++) {
int index = readVarint(input, 1) - 1;
for (ii = 0, nn = readVarint(input, 1); ii < nn; ii++) {
int type = readByte(input);
int frameCount = readVarint(input, 1);
if (type == PHYSICS_RESET) {
spPhysicsConstraintResetTimeline *timeline = spPhysicsConstraintResetTimeline_create(frameCount, index);
for (frame = 0; frame < frameCount; frame++)
spPhysicsConstraintResetTimeline_setFrame(timeline, frame, readFloat(input));
spTimelineArray_add(timelines, SUPER(timeline));
continue;
}
int bezierCount = readVarint(input, 1);
switch (type) {
case PHYSICS_INERTIA:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA)), 1);
break;
case PHYSICS_STRENGTH:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH)), 1);
break;
case PHYSICS_DAMPING:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING)), 1);
break;
case PHYSICS_MASS:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_MASS)), 1);
break;
case PHYSICS_WIND:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_WIND)), 1);
break;
case PHYSICS_GRAVITY:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY)), 1);
break;
case PHYSICS_MIX:
readTimeline(input, timelines, SUPER(spPhysicsConstraintTimeline_create(frameCount, bezierCount, index, SP_TIMELINE_PHYSICSCONSTRAINT_MIX)), 1);
}
}
}
/* Attachment timelines. */
for (i = 0, n = readVarint(input, 1); i < n; ++i) {
@ -1000,13 +1000,13 @@ static spAnimation *_spSkeletonBinary_readAnimation(spSkeletonBinary *self, cons
spEvent *event = spEvent_create(time, eventData);
event->intValue = readVarint(input, 0);
event->floatValue = readFloat(input);
const char *event_stringValue = readString(input);
if (event_stringValue == NULL) {
event->stringValue = string_copy(eventData->stringValue);
} else {
event->stringValue = string_copy(event_stringValue);
FREE(event_stringValue);
}
const char *event_stringValue = readString(input);
if (event_stringValue == NULL) {
event->stringValue = string_copy(eventData->stringValue);
} else {
event->stringValue = string_copy(event_stringValue);
FREE(event_stringValue);
}
if (eventData->audioPath) {
event->volume = readFloat(input);
@ -1046,81 +1046,81 @@ static unsigned short *_readShortArray(_dataInput *input, int n) {
return array;
}
static int _readVertices(_dataInput *input, float **vertices, int *verticesLength, int **bones, int *bonesCount, int/*bool*/ weighted, float scale) {
int vertexCount = readVarint(input, 1);
*verticesLength = vertexCount << 1;
if (!weighted) {
*vertices = _readFloatArray(input, *verticesLength, scale);
*bones = NULL;
*bonesCount = 0;
return *verticesLength;
}
static int _readVertices(_dataInput *input, float **vertices, int *verticesLength, int **bones, int *bonesCount, int /*bool*/ weighted, float scale) {
int vertexCount = readVarint(input, 1);
*verticesLength = vertexCount << 1;
if (!weighted) {
*vertices = _readFloatArray(input, *verticesLength, scale);
*bones = NULL;
*bonesCount = 0;
return *verticesLength;
}
float *v = MALLOC(float, (*verticesLength) * 3 * 3);
int *b = MALLOC(int, (*verticesLength) * 3);
int boneIdx = 0;
int vertexIdx = 0;
for (int i = 0; i < vertexCount; ++i) {
int boneCount = readVarint(input, 1);
b[boneIdx++] = boneCount;
for (int ii = 0; ii < boneCount; ++ii) {
b[boneIdx++] = readVarint(input, 1);
v[vertexIdx++] = readFloat(input) * scale;
v[vertexIdx++] = readFloat(input) * scale;
v[vertexIdx++] = readFloat(input);
}
}
*vertices = v;
*bones = b;
*bonesCount = boneIdx;
*verticesLength = vertexIdx;
return vertexCount << 1;
float *v = MALLOC(float, (*verticesLength) * 3 * 3);
int *b = MALLOC(int, (*verticesLength) * 3);
int boneIdx = 0;
int vertexIdx = 0;
for (int i = 0; i < vertexCount; ++i) {
int boneCount = readVarint(input, 1);
b[boneIdx++] = boneCount;
for (int ii = 0; ii < boneCount; ++ii) {
b[boneIdx++] = readVarint(input, 1);
v[vertexIdx++] = readFloat(input) * scale;
v[vertexIdx++] = readFloat(input) * scale;
v[vertexIdx++] = readFloat(input);
}
}
*vertices = v;
*bones = b;
*bonesCount = boneIdx;
*verticesLength = vertexIdx;
return vertexCount << 1;
}
spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput *input,
spSkin *skin, int slotIndex, const char *attachmentName,
spSkeletonData *skeletonData, int /*bool*/ nonessential) {
int flags = readByte(input);
int flags = readByte(input);
const char *name = (flags & 8) != 0 ? readStringRef(input, skeletonData) : attachmentName;
spAttachmentType type = (flags & 0x7);
spAttachmentType type = (flags & 0x7);
switch (type) {
switch (type) {
case SP_ATTACHMENT_REGION: {
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char*)name;
path = string_copy(path);
spColor color;
spColor_setFromFloats(&color, 1, 1, 1, 1);
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
float rotation = (flags & 128) != 0 ? readFloat(input) : 0;
float x = readFloat(input) * self->scale;
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char *) name;
path = string_copy(path);
spColor color;
spColor_setFromFloats(&color, 1, 1, 1, 1);
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
float rotation = (flags & 128) != 0 ? readFloat(input) : 0;
float x = readFloat(input) * self->scale;
float y = readFloat(input) * self->scale;
float scaleX = readFloat(input);
float scaleY = readFloat(input);
float width = readFloat(input) * self->scale;
float height = readFloat(input) * self->scale;
spRegionAttachment *region = SUB_CAST(spRegionAttachment, spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name,
path, sequence));
region->path = path;
region->rotation = rotation;
region->x = x;
region->y = y;
region->scaleX = scaleX;
region->scaleY = scaleY;
region->width = width;
region->height = height;
spColor_setFromColor(&region->color, &color);
region->sequence = sequence;
if (sequence == NULL) spRegionAttachment_updateRegion(region);
spAttachmentLoader_configureAttachment(self->attachmentLoader, SUPER(region));
return SUPER(region);
spRegionAttachment *region = SUB_CAST(spRegionAttachment, spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name,
path, sequence));
region->path = path;
region->rotation = rotation;
region->x = x;
region->y = y;
region->scaleX = scaleX;
region->scaleY = scaleY;
region->width = width;
region->height = height;
spColor_setFromColor(&region->color, &color);
region->sequence = sequence;
if (sequence == NULL) spRegionAttachment_updateRegion(region);
spAttachmentLoader_configureAttachment(self->attachmentLoader, SUPER(region));
return SUPER(region);
}
case SP_ATTACHMENT_BOUNDING_BOX: {
spBoundingBoxAttachment *box = SUB_CAST(spBoundingBoxAttachment, spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0,
NULL));
NULL));
if (!box) return NULL;
_readVertices(input, &box->super.vertices, &box->super.verticesCount, &box->super.bones, &box->super.bonesCount, (flags & 16) != 0, self->scale);
box->super.worldVerticesLength = box->super.verticesCount;
_readVertices(input, &box->super.vertices, &box->super.verticesCount, &box->super.bones, &box->super.bonesCount, (flags & 16) != 0, self->scale);
box->super.worldVerticesLength = box->super.verticesCount;
if (nonessential) {
readColor(input, &box->color.r, &box->color.g, &box->color.b, &box->color.a);
}
@ -1128,96 +1128,96 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput
return SUPER(SUPER(box));
}
case SP_ATTACHMENT_MESH: {
float *uvs = NULL;
int uvsCount = 0;
unsigned short *triangles = NULL;
int trianglesCount = 0;
float *vertices = NULL;
int verticesCount = 0;
int *bones = NULL;
int bonesCount = 0;
int hullLength = 0;
float width = 0;
float height = 0;
unsigned short *edges = NULL;
int edgesCount = 0;
float *uvs = NULL;
int uvsCount = 0;
unsigned short *triangles = NULL;
int trianglesCount = 0;
float *vertices = NULL;
int verticesCount = 0;
int *bones = NULL;
int bonesCount = 0;
int hullLength = 0;
float width = 0;
float height = 0;
unsigned short *edges = NULL;
int edgesCount = 0;
char* path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char*)name;
path = string_copy(path);
spColor color;
spColor_setFromFloats(&color, 1, 1, 1, 1);
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
hullLength = readVarint(input, 1);
int verticesLength = _readVertices(input, &vertices, &verticesCount, &bones, &bonesCount, (flags & 128) != 0, self->scale);
uvsCount = verticesLength;
uvs = _readFloatArray(input, uvsCount, 1);
trianglesCount = (verticesLength - hullLength - 2) * 3;
triangles = _readShortArray(input, trianglesCount);
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char *) name;
path = string_copy(path);
spColor color;
spColor_setFromFloats(&color, 1, 1, 1, 1);
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
hullLength = readVarint(input, 1);
int verticesLength = _readVertices(input, &vertices, &verticesCount, &bones, &bonesCount, (flags & 128) != 0, self->scale);
uvsCount = verticesLength;
uvs = _readFloatArray(input, uvsCount, 1);
trianglesCount = (verticesLength - hullLength - 2) * 3;
triangles = _readShortArray(input, trianglesCount);
if (nonessential) {
edgesCount = readVarint(input, 1);
edges = _readShortArray(input, edgesCount);
width = readFloat(input);
height = readFloat(input);
}
if (nonessential) {
edgesCount = readVarint(input, 1);
edges = _readShortArray(input, edgesCount);
width = readFloat(input);
height = readFloat(input);
}
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path, sequence);
if (!attachment) return NULL;
spMeshAttachment *mesh = SUB_CAST(spMeshAttachment, attachment);
mesh->path = path;
spColor_setFromColor(&mesh->color, &color);
mesh->regionUVs = uvs;
mesh->triangles = triangles;
mesh->trianglesCount = trianglesCount;
mesh->super.vertices = vertices;
mesh->super.verticesCount = verticesCount;
mesh->super.bones = bones;
mesh->super.bonesCount = bonesCount;
mesh->super.worldVerticesLength = verticesLength;
mesh->hullLength = hullLength;
mesh->edges = edges;
mesh->edgesCount = edgesCount;
mesh->width = width;
mesh->height = height;
mesh->sequence = sequence;
if (sequence == NULL) spMeshAttachment_updateRegion(mesh);
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
return attachment;
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path, sequence);
if (!attachment) return NULL;
spMeshAttachment *mesh = SUB_CAST(spMeshAttachment, attachment);
mesh->path = path;
spColor_setFromColor(&mesh->color, &color);
mesh->regionUVs = uvs;
mesh->triangles = triangles;
mesh->trianglesCount = trianglesCount;
mesh->super.vertices = vertices;
mesh->super.verticesCount = verticesCount;
mesh->super.bones = bones;
mesh->super.bonesCount = bonesCount;
mesh->super.worldVerticesLength = verticesLength;
mesh->hullLength = hullLength;
mesh->edges = edges;
mesh->edgesCount = edgesCount;
mesh->width = width;
mesh->height = height;
mesh->sequence = sequence;
if (sequence == NULL) spMeshAttachment_updateRegion(mesh);
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);
return attachment;
}
case SP_ATTACHMENT_LINKED_MESH: {
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char*)name;
path = string_copy(path);
spColor color;
spColor_setFromFloats(&color, 1, 1, 1, 1);
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
int/*bool*/ inheritTimelines = (flags & 128) != 0;
int skinIndex = readVarint(input, 1);
char *parent = readStringRef(input, skeletonData);
float width = 0, height = 0;
if (nonessential) {
width = readFloat(input) * self->scale;
height = readFloat(input) * self->scale;
}
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path, sequence);
spMeshAttachment *mesh = NULL;
if (!attachment)
return NULL;
mesh = SUB_CAST(spMeshAttachment, attachment);
mesh->path = (char*)path;
if (mesh->path) {
char *tmp = NULL;
MALLOC_STR(tmp, mesh->path);
mesh->path = tmp;
}
spColor_setFromColor(&mesh->color, &color);
mesh->sequence = sequence;
mesh->width = width;
mesh->height = height;
_spSkeletonBinary_addLinkedMesh(self, mesh, skinIndex, slotIndex, parent, inheritTimelines);
return attachment;
char *path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : (char *) name;
path = string_copy(path);
spColor color;
spColor_setFromFloats(&color, 1, 1, 1, 1);
if ((flags & 32) != 0) readColor(input, &color.r, &color.g, &color.b, &color.a);
spSequence *sequence = (flags & 64) != 0 ? readSequence(input) : NULL;
int /*bool*/ inheritTimelines = (flags & 128) != 0;
int skinIndex = readVarint(input, 1);
char *parent = readStringRef(input, skeletonData);
float width = 0, height = 0;
if (nonessential) {
width = readFloat(input) * self->scale;
height = readFloat(input) * self->scale;
}
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path, sequence);
spMeshAttachment *mesh = NULL;
if (!attachment)
return NULL;
mesh = SUB_CAST(spMeshAttachment, attachment);
mesh->path = (char *) path;
if (mesh->path) {
char *tmp = NULL;
MALLOC_STR(tmp, mesh->path);
mesh->path = tmp;
}
spColor_setFromColor(&mesh->color, &color);
mesh->sequence = sequence;
mesh->width = width;
mesh->height = height;
_spSkeletonBinary_addLinkedMesh(self, mesh, skinIndex, slotIndex, parent, inheritTimelines);
return attachment;
}
case SP_ATTACHMENT_PATH: {
spAttachment *attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0,
@ -1226,11 +1226,11 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput
if (!attachment)
return NULL;
path = SUB_CAST(spPathAttachment, attachment);
path->closed = (flags & 16) != 0;
path->constantSpeed = (flags & 32) != 0;
int verticesLength = _readVertices(input, &path->super.vertices, &path->super.verticesCount, &path->super.bones, &path->super.bonesCount, (flags & 64) != 0, self->scale);
path->super.worldVerticesLength = verticesLength;
path->lengthsLength = verticesLength / 6;
path->closed = (flags & 16) != 0;
path->constantSpeed = (flags & 32) != 0;
int verticesLength = _readVertices(input, &path->super.vertices, &path->super.verticesCount, &path->super.bones, &path->super.bonesCount, (flags & 64) != 0, self->scale);
path->super.worldVerticesLength = verticesLength;
path->lengthsLength = verticesLength / 6;
path->lengths = MALLOC(float, path->lengthsLength);
for (int i = 0; i < path->lengthsLength; ++i) {
path->lengths[i] = readFloat(input) * self->scale;
@ -1266,8 +1266,8 @@ spAttachment *spSkeletonBinary_readAttachment(spSkeletonBinary *self, _dataInput
if (!attachment)
return NULL;
clip = SUB_CAST(spClippingAttachment, attachment);
int verticesLength = _readVertices(input, &clip->super.vertices, &clip->super.verticesCount, &clip->super.bones, &clip->super.bonesCount, (flags & 16) != 0, self->scale);
clip->super.worldVerticesLength = verticesLength;
int verticesLength = _readVertices(input, &clip->super.vertices, &clip->super.verticesCount, &clip->super.bones, &clip->super.bonesCount, (flags & 16) != 0, self->scale);
clip->super.worldVerticesLength = verticesLength;
if (nonessential) {
readColor(input, &clip->color.r, &clip->color.g, &clip->color.b, &clip->color.a);
}
@ -1290,10 +1290,10 @@ spSkin *spSkeletonBinary_readSkin(spSkeletonBinary *self, _dataInput *input, int
if (slotCount == 0) return NULL;
skin = spSkin_create("default");
} else {
char *name = readString(input);
char *name = readString(input);
skin = spSkin_create(name);
FREE(name);
if (nonessential) readColor(input, &skin->color.r, &skin->color.g, &skin->color.b, &skin->color.a);
FREE(name);
if (nonessential) readColor(input, &skin->color.r, &skin->color.g, &skin->color.b, &skin->color.a);
for (i = 0, n = readVarint(input, 1); i < n; i++)
spBoneDataArray_add(skin->bones, skeletonData->bones[readVarint(input, 1)]);
@ -1307,10 +1307,10 @@ spSkin *spSkeletonBinary_readSkin(spSkeletonBinary *self, _dataInput *input, int
for (i = 0, n = readVarint(input, 1); i < n; i++)
spPathConstraintDataArray_add(skin->pathConstraints, skeletonData->pathConstraints[readVarint(input, 1)]);
for (i = 0, n = readVarint(input, 1); i < n; i++)
spPhysicsConstraintDataArray_add(skin->physicsConstraints, skeletonData->physicsConstraints[readVarint(input, 1)]);
for (i = 0, n = readVarint(input, 1); i < n; i++)
spPhysicsConstraintDataArray_add(skin->physicsConstraints, skeletonData->physicsConstraints[readVarint(input, 1)]);
slotCount = readVarint(input, 1);
slotCount = readVarint(input, 1);
}
for (i = 0; i < slotCount; ++i) {
@ -1380,7 +1380,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
skeletonData->y = readFloat(input);
skeletonData->width = readFloat(input);
skeletonData->height = readFloat(input);
skeletonData->referenceScale = readFloat(input);
skeletonData->referenceScale = readFloat(input);
nonessential = readBoolean(input);
@ -1424,8 +1424,8 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
data->skinRequired = readBoolean(input);
if (nonessential) {
readColor(input, &data->color.r, &data->color.g, &data->color.b, &data->color.a);
data->icon = readString(input);
data->visible = readBoolean(input);
data->icon = readString(input);
data->visible = readBoolean(input);
}
skeletonData->bones[i] = data;
}
@ -1435,14 +1435,14 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
skeletonData->slots = MALLOC(spSlotData *, skeletonData->slotsCount);
for (i = 0; i < skeletonData->slotsCount; ++i) {
char *slotName = readString(input);
char *pathName = NULL;
if (nonessential) {
int slash = string_lastIndexOf(slotName, '/');
if (slash != -1) {
pathName = string_substring(slotName, 0, slash);
slotName = string_substring(slotName, slash + 1, strlen(slotName));
}
}
char *pathName = NULL;
if (nonessential) {
int slash = string_lastIndexOf(slotName, '/');
if (slash != -1) {
pathName = string_substring(slotName, 0, slash);
slotName = string_substring(slotName, slash + 1, strlen(slotName));
}
}
spBoneData *boneData = skeletonData->bones[readVarint(input, 1)];
spSlotData *slotData = spSlotData_create(i, slotName, boneData);
FREE(slotName);
@ -1460,10 +1460,10 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
else
slotData->attachmentName = 0;
slotData->blendMode = (spBlendMode) readVarint(input, 1);
if (nonessential) {
slotData->visible = readBoolean(input);
slotData->path = pathName;
}
if (nonessential) {
slotData->visible = readBoolean(input);
slotData->path = pathName;
}
skeletonData->slots[i] = slotData;
}
@ -1473,23 +1473,23 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
for (i = 0; i < skeletonData->ikConstraintsCount; ++i) {
const char *name = readString(input);
spIkConstraintData *data = spIkConstraintData_create(name);
FREE(name);
FREE(name);
data->order = readVarint(input, 1);
data->bonesCount = readVarint(input, 1);
data->bones = MALLOC(spBoneData *, data->bonesCount);
for (ii = 0; ii < data->bonesCount; ++ii)
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
data->target = skeletonData->bones[readVarint(input, 1)];
int flags = readByte(input);
data->skinRequired = (flags & 1) != 0;
data->bendDirection = (flags & 2) != 0 ? 1 : -1;
data->compress = (flags & 4) != 0;
data->stretch = (flags & 8) != 0;
data->uniform = (flags & 16) != 0;
if ((flags & 32) != 0) data->mix = (flags & 64) != 0 ? readFloat(input) : 1;
if ((flags & 128) != 0) data->softness = readFloat(input) * self->scale;
int flags = readByte(input);
data->skinRequired = (flags & 1) != 0;
data->bendDirection = (flags & 2) != 0 ? 1 : -1;
data->compress = (flags & 4) != 0;
data->stretch = (flags & 8) != 0;
data->uniform = (flags & 16) != 0;
if ((flags & 32) != 0) data->mix = (flags & 64) != 0 ? readFloat(input) : 1;
if ((flags & 128) != 0) data->softness = readFloat(input) * self->scale;
skeletonData->ikConstraints[i] = data;
skeletonData->ikConstraints[i] = data;
}
/* Transform constraints. */
@ -1499,32 +1499,32 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
for (i = 0; i < skeletonData->transformConstraintsCount; ++i) {
const char *name = readString(input);
spTransformConstraintData *data = spTransformConstraintData_create(name);
FREE(name);
FREE(name);
data->order = readVarint(input, 1);
data->bonesCount = readVarint(input, 1);
data->bones = MALLOC(spBoneData *, data->bonesCount);
for (ii = 0; ii < data->bonesCount; ++ii)
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
data->target = skeletonData->bones[readVarint(input, 1)];
int flags = readByte(input);
data->skinRequired = (flags & 1) != 0;
data->local = (flags & 2) != 0;
data->relative = (flags & 4) != 0;
if ((flags & 8) != 0) data->offsetRotation = readFloat(input);
if ((flags & 16) != 0) data->offsetX = readFloat(input) * self->scale;
if ((flags & 32) != 0) data->offsetY = readFloat(input) * self->scale;
if ((flags & 64) != 0) data->offsetScaleX = readFloat(input);
if ((flags & 128) != 0) data->offsetScaleY = readFloat(input);
flags = readByte(input);
if ((flags & 1) != 0) data->offsetShearY = readFloat(input);
if ((flags & 2) != 0) data->mixRotate = readFloat(input);
if ((flags & 4) != 0) data->mixX = readFloat(input);
if ((flags & 8) != 0) data->mixY = readFloat(input);
if ((flags & 16) != 0) data->mixScaleX = readFloat(input);
if ((flags & 32) != 0) data->mixScaleY = readFloat(input);
if ((flags & 64) != 0) data->mixShearY = readFloat(input);
int flags = readByte(input);
data->skinRequired = (flags & 1) != 0;
data->local = (flags & 2) != 0;
data->relative = (flags & 4) != 0;
if ((flags & 8) != 0) data->offsetRotation = readFloat(input);
if ((flags & 16) != 0) data->offsetX = readFloat(input) * self->scale;
if ((flags & 32) != 0) data->offsetY = readFloat(input) * self->scale;
if ((flags & 64) != 0) data->offsetScaleX = readFloat(input);
if ((flags & 128) != 0) data->offsetScaleY = readFloat(input);
flags = readByte(input);
if ((flags & 1) != 0) data->offsetShearY = readFloat(input);
if ((flags & 2) != 0) data->mixRotate = readFloat(input);
if ((flags & 4) != 0) data->mixX = readFloat(input);
if ((flags & 8) != 0) data->mixY = readFloat(input);
if ((flags & 16) != 0) data->mixScaleX = readFloat(input);
if ((flags & 32) != 0) data->mixScaleY = readFloat(input);
if ((flags & 64) != 0) data->mixShearY = readFloat(input);
skeletonData->transformConstraints[i] = data;
skeletonData->transformConstraints[i] = data;
}
/* Path constraints */
@ -1533,7 +1533,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
for (i = 0; i < skeletonData->pathConstraintsCount; ++i) {
const char *name = readString(input);
spPathConstraintData *data = spPathConstraintData_create(name);
FREE(name);
FREE(name);
data->order = readVarint(input, 1);
data->skinRequired = readBoolean(input);
data->bonesCount = readVarint(input, 1);
@ -1541,12 +1541,12 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
for (ii = 0; ii < data->bonesCount; ++ii)
data->bones[ii] = skeletonData->bones[readVarint(input, 1)];
data->target = skeletonData->slots[readVarint(input, 1)];
int flags = readByte(input);
data->positionMode = (flags & 1);
data->spacingMode = ((flags >> 1) & 3);
data->rotateMode = ((flags >> 3) & 3);
if ((flags & 128) != 0) data->offsetRotation = readFloat(input);
data->position = readFloat(input);
int flags = readByte(input);
data->positionMode = (flags & 1);
data->spacingMode = ((flags >> 1) & 3);
data->rotateMode = ((flags >> 3) & 3);
if ((flags & 128) != 0) data->offsetRotation = readFloat(input);
data->position = readFloat(input);
if (data->positionMode == SP_POSITION_MODE_FIXED) data->position *= self->scale;
data->spacing = readFloat(input);
if (data->spacingMode == SP_SPACING_MODE_LENGTH || data->spacingMode == SP_SPACING_MODE_FIXED)
@ -1557,41 +1557,41 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
skeletonData->pathConstraints[i] = data;
}
// Physics constraints.
skeletonData->physicsConstraintsCount = readVarint(input, 1);
skeletonData->physicsConstraints = MALLOC(spPhysicsConstraintData *, skeletonData->physicsConstraintsCount);
for (i = 0; i < skeletonData->physicsConstraintsCount; i++) {
const char *name = readString(input);
spPhysicsConstraintData *data = spPhysicsConstraintData_create(name);
FREE(name);
data->order = readVarint(input, 1);
data->bone = skeletonData->bones[readVarint(input, 1)];
int flags = readByte(input);
data->skinRequired = (flags & 1) != 0;
if ((flags & 2) != 0) data->x = readFloat(input);
if ((flags & 4) != 0) data->y = readFloat(input);
if ((flags & 8) != 0) data->rotate = readFloat(input);
if ((flags & 16) != 0) data->scaleX = readFloat(input);
if ((flags & 32) != 0) data->shearX = readFloat(input);
data->limit = ((flags & 64) != 0 ? readFloat(input) : 5000) * self->scale;
data->step = 1.f / readByte(input);
data->inertia = readFloat(input);
data->strength = readFloat(input);
data->damping = readFloat(input);
data->massInverse = (flags & 128) != 0 ? readFloat(input) : 1;
data->wind = readFloat(input);
data->gravity = readFloat(input);
flags = readByte(input);
if ((flags & 1) != 0) data->inertiaGlobal = -1;
if ((flags & 2) != 0) data->strengthGlobal = -1;
if ((flags & 4) != 0) data->dampingGlobal = -1;
if ((flags & 8) != 0) data->massGlobal = -1;
if ((flags & 16) != 0) data->windGlobal = -1;
if ((flags & 32) != 0) data->gravityGlobal = -1;
if ((flags & 64) != 0) data->mixGlobal = -1;
data->mix = (flags & 128) != 0 ? readFloat(input) : 1;
skeletonData->physicsConstraints[i] = data;
}
// Physics constraints.
skeletonData->physicsConstraintsCount = readVarint(input, 1);
skeletonData->physicsConstraints = MALLOC(spPhysicsConstraintData *, skeletonData->physicsConstraintsCount);
for (i = 0; i < skeletonData->physicsConstraintsCount; i++) {
const char *name = readString(input);
spPhysicsConstraintData *data = spPhysicsConstraintData_create(name);
FREE(name);
data->order = readVarint(input, 1);
data->bone = skeletonData->bones[readVarint(input, 1)];
int flags = readByte(input);
data->skinRequired = (flags & 1) != 0;
if ((flags & 2) != 0) data->x = readFloat(input);
if ((flags & 4) != 0) data->y = readFloat(input);
if ((flags & 8) != 0) data->rotate = readFloat(input);
if ((flags & 16) != 0) data->scaleX = readFloat(input);
if ((flags & 32) != 0) data->shearX = readFloat(input);
data->limit = ((flags & 64) != 0 ? readFloat(input) : 5000) * self->scale;
data->step = 1.f / readByte(input);
data->inertia = readFloat(input);
data->strength = readFloat(input);
data->damping = readFloat(input);
data->massInverse = (flags & 128) != 0 ? readFloat(input) : 1;
data->wind = readFloat(input);
data->gravity = readFloat(input);
flags = readByte(input);
if ((flags & 1) != 0) data->inertiaGlobal = -1;
if ((flags & 2) != 0) data->strengthGlobal = -1;
if ((flags & 4) != 0) data->dampingGlobal = -1;
if ((flags & 8) != 0) data->massGlobal = -1;
if ((flags & 16) != 0) data->windGlobal = -1;
if ((flags & 32) != 0) data->gravityGlobal = -1;
if ((flags & 64) != 0) data->mixGlobal = -1;
data->mix = (flags & 128) != 0 ? readFloat(input) : 1;
skeletonData->physicsConstraints[i] = data;
}
/* Default skin. */
skeletonData->defaultSkin = spSkeletonBinary_readSkin(self, input, -1, skeletonData, nonessential);
@ -1624,14 +1624,14 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
/* Linked meshes. */
for (i = 0; i < internal->linkedMeshCount; ++i) {
_spLinkedMesh *linkedMesh = internal->linkedMeshes + i;
spSkin *skin = skeletonData->skins[linkedMesh->skinIndex];
spSkin *skin = skeletonData->skins[linkedMesh->skinIndex];
if (!skin) {
FREE(input);
spSkeletonData_dispose(skeletonData);
_spSkeletonBinary_setError(self, "Skin not found", "");
return NULL;
}
spAttachment *parent = spSkin_getAttachment(skin, linkedMesh->slotIndex, linkedMesh->parent);
spAttachment *parent = spSkin_getAttachment(skin, linkedMesh->slotIndex, linkedMesh->parent);
if (!parent) {
FREE(input);
spSkeletonData_dispose(skeletonData);
@ -1651,7 +1651,7 @@ spSkeletonData *spSkeletonBinary_readSkeletonData(spSkeletonBinary *self, const
for (i = 0; i < skeletonData->eventsCount; ++i) {
const char *name = readString(input);
spEventData *eventData = spEventData_create(name);
FREE(name);
FREE(name);
eventData->intValue = readVarint(input, 0);
eventData->floatValue = readFloat(input);
eventData->stringValue = readString(input);

View File

@ -74,9 +74,9 @@ void spSkeletonData_dispose(spSkeletonData *self) {
spPathConstraintData_dispose(self->pathConstraints[i]);
FREE(self->pathConstraints);
for (i = 0; i < self->physicsConstraintsCount; i++)
spPhysicsConstraintData_dispose(self->physicsConstraints[i]);
FREE(self->physicsConstraints);
for (i = 0; i < self->physicsConstraintsCount; i++)
spPhysicsConstraintData_dispose(self->physicsConstraints[i]);
FREE(self->physicsConstraints);
FREE(self->hash);
FREE(self->version);
@ -144,8 +144,8 @@ spPathConstraintData *spSkeletonData_findPathConstraint(const spSkeletonData *se
}
spPhysicsConstraintData *spSkeletonData_findPhysicsConstraint(const spSkeletonData *self, const char *constraintName) {
int i;
for (i = 0; i < self->physicsConstraintsCount; ++i)
if (strcmp(self->physicsConstraints[i]->name, constraintName) == 0) return self->physicsConstraints[i];
return 0;
int i;
for (i = 0; i < self->physicsConstraintsCount; ++i)
if (strcmp(self->physicsConstraints[i]->name, constraintName) == 0) return self->physicsConstraints[i];
return 0;
}

View File

@ -269,14 +269,14 @@ int findPathConstraintIndex(spSkeletonJson *json, const spSkeletonData *skeleton
}
int findPhysicsConstraintIndex(spSkeletonJson *json, const spSkeletonData *skeletonData, const spPhysicsConstraintData *constraint, spTimelineArray *timelines) {
if (constraint) {
int i;
for (i = 0; i < skeletonData->physicsConstraintsCount; ++i)
if (skeletonData->physicsConstraints[i] == constraint) return i;
}
cleanUpTimelines(timelines);
_spSkeletonJson_setError(json, NULL, "Physics constraint not found: ", constraint->name);
return -1;
if (constraint) {
int i;
for (i = 0; i < skeletonData->physicsConstraintsCount; ++i)
if (skeletonData->physicsConstraints[i] == constraint) return i;
}
cleanUpTimelines(timelines);
_spSkeletonJson_setError(json, NULL, "Physics constraint not found: ", constraint->name);
return -1;
}
static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *root, spSkeletonData *skeletonData) {
@ -288,7 +288,7 @@ static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *ro
Json *ik = Json_getItem(root, "ik");
Json *transform = Json_getItem(root, "transform");
Json *paths = Json_getItem(root, "path");
Json *physics = Json_getItem(root, "physics");
Json *physics = Json_getItem(root, "physics");
Json *attachmentsJson = Json_getItem(root, "attachments");
Json *drawOrderJson = Json_getItem(root, "drawOrder");
Json *events = Json_getItem(root, "events");
@ -528,29 +528,29 @@ static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *ro
spShearXTimeline *timeline = spShearXTimeline_create(frames, frames, boneIndex);
spTimelineArray_add(timelines, readTimeline(timelineMap->child, SUPER(timeline), 0, 1));
} else if (strcmp(timelineMap->name, "sheary") == 0) {
spShearYTimeline *timeline = spShearYTimeline_create(frames, frames, boneIndex);
spTimelineArray_add(timelines, readTimeline(timelineMap->child, SUPER(timeline), 0, 1));
} else if (strcmp(timelineMap->name, "inherit") == 0) {
spInheritTimeline *timeline = spInheritTimeline_create(frames, boneIndex);
keyMap = timelineMap->child;
for (frame = 0;; frame++) {
float time = Json_getFloat(keyMap, "time", 0);
const char *value = Json_getString(keyMap, "value", "normal");
spInherit inherit = SP_INHERIT_NORMAL;
if (strcmp(value, "normal") == 0) inherit = SP_INHERIT_NORMAL;
else if (strcmp(value, "onlyTranslation") == 0)
inherit = SP_INHERIT_ONLYTRANSLATION;
else if (strcmp(value, "noRotationOrReflection") == 0)
inherit = SP_INHERIT_NOROTATIONORREFLECTION;
else if (strcmp(value, "noScale") == 0)
inherit = SP_INHERIT_NOSCALE;
else if (strcmp(value, "noScaleOrReflection") == 0)
inherit = SP_INHERIT_NOSCALEORREFLECTION;
spInheritTimeline_setFrame(timeline, frame, time, inherit);
nextMap = keyMap->next;
if (!nextMap) break;
}
spTimelineArray_add(timelines, SUPER(timeline));
spShearYTimeline *timeline = spShearYTimeline_create(frames, frames, boneIndex);
spTimelineArray_add(timelines, readTimeline(timelineMap->child, SUPER(timeline), 0, 1));
} else if (strcmp(timelineMap->name, "inherit") == 0) {
spInheritTimeline *timeline = spInheritTimeline_create(frames, boneIndex);
keyMap = timelineMap->child;
for (frame = 0;; frame++) {
float time = Json_getFloat(keyMap, "time", 0);
const char *value = Json_getString(keyMap, "value", "normal");
spInherit inherit = SP_INHERIT_NORMAL;
if (strcmp(value, "normal") == 0) inherit = SP_INHERIT_NORMAL;
else if (strcmp(value, "onlyTranslation") == 0)
inherit = SP_INHERIT_ONLYTRANSLATION;
else if (strcmp(value, "noRotationOrReflection") == 0)
inherit = SP_INHERIT_NOROTATIONORREFLECTION;
else if (strcmp(value, "noScale") == 0)
inherit = SP_INHERIT_NOSCALE;
else if (strcmp(value, "noScaleOrReflection") == 0)
inherit = SP_INHERIT_NOSCALEORREFLECTION;
spInheritTimeline_setFrame(timeline, frame, time, inherit);
nextMap = keyMap->next;
if (!nextMap) break;
}
spTimelineArray_add(timelines, SUPER(timeline));
} else {
cleanUpTimelines(timelines);
_spSkeletonJson_setError(self, NULL, "Invalid timeline type for a bone: ", timelineMap->name);
@ -734,49 +734,49 @@ static spAnimation *_spSkeletonJson_readAnimation(spSkeletonJson *self, Json *ro
}
}
/** Physics constraint timelines. */
for (constraintMap = physics ? physics->child : 0; constraintMap; constraintMap = constraintMap->next) {
int index = -1;
if (constraintMap->name && strlen(constraintMap->name) > 0) {
spPhysicsConstraintData *constraint = spSkeletonData_findPhysicsConstraint(skeletonData, constraintMap->name);
index = findPhysicsConstraintIndex(self, skeletonData, constraint, timelines);
if (index == -1) return NULL;
}
for (timelineMap = constraintMap->child; timelineMap; timelineMap = timelineMap->next) {
keyMap = timelineMap->child;
if (keyMap == NULL) continue;
const char *timelineName = timelineMap->name;
int frames = timelineMap->size;
if (strcmp(timelineName, "reset") == 0) {
spPhysicsConstraintResetTimeline *timeline = spPhysicsConstraintResetTimeline_create(frames, index);
for (frame = 0; keyMap != NULL; keyMap = keyMap->next, frame++) {
spPhysicsConstraintResetTimeline_setFrame(timeline, frame, Json_getFloat(keyMap, "time", 0));
}
spTimelineArray_add(timelines, SUPER(timeline));
continue;
}
/** Physics constraint timelines. */
for (constraintMap = physics ? physics->child : 0; constraintMap; constraintMap = constraintMap->next) {
int index = -1;
if (constraintMap->name && strlen(constraintMap->name) > 0) {
spPhysicsConstraintData *constraint = spSkeletonData_findPhysicsConstraint(skeletonData, constraintMap->name);
index = findPhysicsConstraintIndex(self, skeletonData, constraint, timelines);
if (index == -1) return NULL;
}
for (timelineMap = constraintMap->child; timelineMap; timelineMap = timelineMap->next) {
keyMap = timelineMap->child;
if (keyMap == NULL) continue;
const char *timelineName = timelineMap->name;
int frames = timelineMap->size;
if (strcmp(timelineName, "reset") == 0) {
spPhysicsConstraintResetTimeline *timeline = spPhysicsConstraintResetTimeline_create(frames, index);
for (frame = 0; keyMap != NULL; keyMap = keyMap->next, frame++) {
spPhysicsConstraintResetTimeline_setFrame(timeline, frame, Json_getFloat(keyMap, "time", 0));
}
spTimelineArray_add(timelines, SUPER(timeline));
continue;
}
spPhysicsConstraintTimeline *timeline = NULL;
if (strcmp(timelineName, "inertia") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA);
} else if (strcmp(timelineName, "strength") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH);
} else if (strcmp(timelineName, "damping") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING);
} else if (strcmp(timelineName, "mass") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_MASS);
} else if (strcmp(timelineName, "wind") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_WIND);
} else if (strcmp(timelineName, "gravity") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY);
} else if (strcmp(timelineName, "mix") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_MIX);
} else {
continue;
}
spTimelineArray_add(timelines, readTimeline(keyMap, SUPER(timeline), 0, 1));
}
}
spPhysicsConstraintTimeline *timeline = NULL;
if (strcmp(timelineName, "inertia") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_INERTIA);
} else if (strcmp(timelineName, "strength") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_STRENGTH);
} else if (strcmp(timelineName, "damping") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_DAMPING);
} else if (strcmp(timelineName, "mass") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_MASS);
} else if (strcmp(timelineName, "wind") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_WIND);
} else if (strcmp(timelineName, "gravity") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_GRAVITY);
} else if (strcmp(timelineName, "mix") == 0) {
timeline = spPhysicsConstraintTimeline_create(frames, frames, index, SP_TIMELINE_PHYSICSCONSTRAINT_MIX);
} else {
continue;
}
spTimelineArray_add(timelines, readTimeline(keyMap, SUPER(timeline), 0, 1));
}
}
/* Attachment timelines. */
for (attachmentsMap = attachmentsJson ? attachmentsJson->child : 0; attachmentsMap; attachmentsMap = attachmentsMap->next) {
@ -1042,31 +1042,31 @@ static int string_starts_with(const char *str, const char *needle) {
}
static int string_lastIndexOf(const char *str, char needle) {
if (!str) return -1;
int lastIndex = -1;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == needle) {
lastIndex = i;
}
}
return lastIndex;
if (!str) return -1;
int lastIndex = -1;
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] == needle) {
lastIndex = i;
}
}
return lastIndex;
}
static char *string_substring(const char *str, int start, int end) {
if (str == NULL || start > end || start < 0) {
return NULL;
}
if (str == NULL || start > end || start < 0) {
return NULL;
}
int len = end - start;
char *substr = MALLOC(char, len + 1);
if (substr == NULL) {
return NULL;
}
int len = end - start;
char *substr = MALLOC(char, len + 1);
if (substr == NULL) {
return NULL;
}
strncpy(substr, str + start, len);
substr[len] = '\0';
strncpy(substr, str + start, len);
substr[len] = '\0';
return substr;
return substr;
}
spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char *json) {
@ -1101,7 +1101,7 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
skeletonData->y = Json_getFloat(skeleton, "y", 0);
skeletonData->width = Json_getFloat(skeleton, "width", 0);
skeletonData->height = Json_getFloat(skeleton, "height", 0);
skeletonData->referenceScale = Json_getFloat(skeleton, "referenceScale", 100) * self->scale;
skeletonData->referenceScale = Json_getFloat(skeleton, "referenceScale", 100) * self->scale;
skeletonData->fps = Json_getFloat(skeleton, "fps", 30);
skeletonData->imagesPath = Json_getString(skeleton, "images", 0);
if (skeletonData->imagesPath) {
@ -1161,13 +1161,13 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
color = Json_getString(boneMap, "color", 0);
if (color) toColor2(&data->color, color, -1);
data->icon = Json_getString(boneMap, "icon", "");
if (data->icon) {
char *tmp = NULL;
MALLOC_STR(tmp, data->icon);
data->icon = tmp;
}
data->visible = Json_getInt(boneMap, "visible", -1) ? -1 : 0;
data->icon = Json_getString(boneMap, "icon", "");
if (data->icon) {
char *tmp = NULL;
MALLOC_STR(tmp, data->icon);
data->icon = tmp;
}
data->visible = Json_getInt(boneMap, "visible", -1) ? -1 : 0;
skeletonData->bones[i] = data;
skeletonData->bonesCount++;
@ -1193,13 +1193,13 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
return NULL;
}
char *pathName = NULL;
char *slotName = (char*)Json_getString(slotMap, "name", NULL);
int slash = string_lastIndexOf(slotName, '/');
if (slash != -1) {
pathName = string_substring(slotName, 0, slash);
slotName = string_substring(slotName, slash + 1, strlen(slotName));
}
char *pathName = NULL;
char *slotName = (char *) Json_getString(slotMap, "name", NULL);
int slash = string_lastIndexOf(slotName, '/');
if (slash != -1) {
pathName = string_substring(slotName, 0, slash);
slotName = string_substring(slotName, slash + 1, strlen(slotName));
}
data = spSlotData_create(i, slotName, boneData);
color = Json_getString(slotMap, "color", 0);
@ -1234,8 +1234,8 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
data->blendMode = SP_BLEND_MODE_SCREEN;
}
data->visible = Json_getInt(slotMap, "visible", -1);
data->path = pathName;
data->visible = Json_getInt(slotMap, "visible", -1);
data->path = pathName;
skeletonData->slots[i] = data;
}
}
@ -1407,53 +1407,53 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
}
}
/* Physics constraints */
physics = Json_getItem(root, "physics");
if (physics) {
Json *constraintMap;
skeletonData->physicsConstraintsCount = physics->size;
skeletonData->physicsConstraints = MALLOC(spPhysicsConstraintData *, physics->size);
for (constraintMap = physics->child, i = 0; constraintMap; constraintMap = constraintMap->next, ++i) {
const char *name;
/* Physics constraints */
physics = Json_getItem(root, "physics");
if (physics) {
Json *constraintMap;
skeletonData->physicsConstraintsCount = physics->size;
skeletonData->physicsConstraints = MALLOC(spPhysicsConstraintData *, physics->size);
for (constraintMap = physics->child, i = 0; constraintMap; constraintMap = constraintMap->next, ++i) {
const char *name;
spPhysicsConstraintData *data = spPhysicsConstraintData_create(
Json_getString(constraintMap, "name", 0));
data->order = Json_getInt(constraintMap, "order", 0);
data->skinRequired = Json_getInt(constraintMap, "skin", 0);
spPhysicsConstraintData *data = spPhysicsConstraintData_create(
Json_getString(constraintMap, "name", 0));
data->order = Json_getInt(constraintMap, "order", 0);
data->skinRequired = Json_getInt(constraintMap, "skin", 0);
name = Json_getString(constraintMap, "bone", 0);
data->bone = spSkeletonData_findBone(skeletonData, name);
if (!data->bone) {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, "Physics bone not found: ", name);
return NULL;
}
name = Json_getString(constraintMap, "bone", 0);
data->bone = spSkeletonData_findBone(skeletonData, name);
if (!data->bone) {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, "Physics bone not found: ", name);
return NULL;
}
data->x = Json_getFloat(constraintMap, "x", 0);
data->y = Json_getFloat(constraintMap, "y", 0);
data->rotate = Json_getFloat(constraintMap, "rotate", 0);
data->scaleX = Json_getFloat(constraintMap, "scaleX", 0);
data->shearX = Json_getFloat(constraintMap, "shearX", 0);
data->limit = Json_getFloat(constraintMap, "limit", 5000) * self->scale;
data->step = 1.0f / Json_getInt(constraintMap, "fps", 60);
data->inertia = Json_getFloat(constraintMap, "inertia", 1);
data->strength = Json_getFloat(constraintMap, "strength", 100);
data->damping = Json_getFloat(constraintMap, "damping", 1);
data->massInverse = 1.0f / Json_getFloat(constraintMap, "mass", 1);
data->wind = Json_getFloat(constraintMap, "wind", 0);
data->gravity = Json_getFloat(constraintMap, "gravity", 0);
data->mix = Json_getFloat(constraintMap, "mix", 1);
data->inertiaGlobal = Json_getInt(constraintMap, "inertiaGlobal", 0);
data->strengthGlobal = Json_getInt(constraintMap, "strengthGlobal", 0);
data->dampingGlobal = Json_getInt(constraintMap, "dampingGlobal", 0);
data->massGlobal = Json_getInt(constraintMap, "massGlobal", 0);
data->windGlobal = Json_getInt(constraintMap, "windGlobal", 0);
data->gravityGlobal = Json_getInt(constraintMap, "gravityGlobal", 0);
data->mixGlobal = Json_getInt(constraintMap, "mixGlobal", 0);
data->x = Json_getFloat(constraintMap, "x", 0);
data->y = Json_getFloat(constraintMap, "y", 0);
data->rotate = Json_getFloat(constraintMap, "rotate", 0);
data->scaleX = Json_getFloat(constraintMap, "scaleX", 0);
data->shearX = Json_getFloat(constraintMap, "shearX", 0);
data->limit = Json_getFloat(constraintMap, "limit", 5000) * self->scale;
data->step = 1.0f / Json_getInt(constraintMap, "fps", 60);
data->inertia = Json_getFloat(constraintMap, "inertia", 1);
data->strength = Json_getFloat(constraintMap, "strength", 100);
data->damping = Json_getFloat(constraintMap, "damping", 1);
data->massInverse = 1.0f / Json_getFloat(constraintMap, "mass", 1);
data->wind = Json_getFloat(constraintMap, "wind", 0);
data->gravity = Json_getFloat(constraintMap, "gravity", 0);
data->mix = Json_getFloat(constraintMap, "mix", 1);
data->inertiaGlobal = Json_getInt(constraintMap, "inertiaGlobal", 0);
data->strengthGlobal = Json_getInt(constraintMap, "strengthGlobal", 0);
data->dampingGlobal = Json_getInt(constraintMap, "dampingGlobal", 0);
data->massGlobal = Json_getInt(constraintMap, "massGlobal", 0);
data->windGlobal = Json_getInt(constraintMap, "windGlobal", 0);
data->gravityGlobal = Json_getInt(constraintMap, "gravityGlobal", 0);
data->mixGlobal = Json_getInt(constraintMap, "mixGlobal", 0);
skeletonData->physicsConstraints[i] = data;
}
}
skeletonData->physicsConstraints[i] = data;
}
}
/* Skins. */
skins = Json_getItem(root, "skins");
@ -1522,19 +1522,19 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
}
}
skinPart = Json_getItem(skinMap, "physics");
if (skinPart) {
for (skinPart = skinPart->child; skinPart; skinPart = skinPart->next) {
spPhysicsConstraintData *constraint = spSkeletonData_findPhysicsConstraint(skeletonData,
skinPart->valueString);
if (!constraint) {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, "Skin physics constraint not found: ", skinPart->valueString);
return NULL;
}
spPhysicsConstraintDataArray_add(skin->physicsConstraints, constraint);
}
}
skinPart = Json_getItem(skinMap, "physics");
if (skinPart) {
for (skinPart = skinPart->child; skinPart; skinPart = skinPart->next) {
spPhysicsConstraintData *constraint = spSkeletonData_findPhysicsConstraint(skeletonData,
skinPart->valueString);
if (!constraint) {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, "Skin physics constraint not found: ", skinPart->valueString);
return NULL;
}
spPhysicsConstraintDataArray_add(skin->physicsConstraints, constraint);
}
}
skeletonData->skins[skeletonData->skinsCount++] = skin;
if (strcmp(skin->name, "default") == 0) skeletonData->defaultSkin = skin;
@ -1661,7 +1661,7 @@ spSkeletonData *spSkeletonJson_readSkeletonData(spSkeletonJson *self, const char
mesh->edgesCount = entry->size;
mesh->edges = MALLOC(unsigned short, entry->size);
for (entry = entry->child, ii = 0; entry; entry = entry->next, ++ii)
mesh->edges[ii] = (unsigned short)entry->valueInt;
mesh->edges[ii] = (unsigned short) entry->valueInt;
}
spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment);

View File

@ -44,7 +44,7 @@ _SP_ARRAY_IMPLEMENT_TYPE(spPhysicsConstraintDataArray, spPhysicsConstraintData *
_Entry *_Entry_create(int slotIndex, const char *name, spAttachment *attachment) {
_Entry *self = NEW(_Entry);
self->slotIndex = slotIndex;
MALLOC_STR(self->name, (char *)name);
MALLOC_STR(self->name, (char *) name);
self->attachment = attachment;
return self;
}
@ -69,13 +69,13 @@ static void _SkinHashTableEntry_dispose(_SkinHashTableEntry *self) {
spSkin *spSkin_create(const char *name) {
spSkin *self = SUPER(NEW(_spSkin));
MALLOC_STR(self->name, (char*)name);
MALLOC_STR(self->name, (char *) name);
self->bones = spBoneDataArray_create(4);
self->ikConstraints = spIkConstraintDataArray_create(4);
self->transformConstraints = spTransformConstraintDataArray_create(4);
self->pathConstraints = spPathConstraintDataArray_create(4);
self->physicsConstraints = spPhysicsConstraintDataArray_create(4);
spColor_setFromFloats(&self->color, 0.99607843f, 0.61960787f, 0.30980393f, 1);
self->physicsConstraints = spPhysicsConstraintDataArray_create(4);
spColor_setFromFloats(&self->color, 0.99607843f, 0.61960787f, 0.30980393f, 1);
return self;
}
@ -107,7 +107,7 @@ void spSkin_dispose(spSkin *self) {
spIkConstraintDataArray_dispose(self->ikConstraints);
spTransformConstraintDataArray_dispose(self->transformConstraints);
spPathConstraintDataArray_dispose(self->pathConstraints);
spPhysicsConstraintDataArray_dispose(self->physicsConstraints);
spPhysicsConstraintDataArray_dispose(self->physicsConstraints);
FREE(self->name);
FREE(self);
}
@ -202,10 +202,10 @@ void spSkin_addSkin(spSkin *self, const spSkin *other) {
spPathConstraintDataArray_add(self->pathConstraints, other->pathConstraints->items[i]);
}
for (i = 0; i < other->physicsConstraints->size; i++) {
if (!spPhysicsConstraintDataArray_contains(self->physicsConstraints, other->physicsConstraints->items[i]))
spPhysicsConstraintDataArray_add(self->physicsConstraints, other->physicsConstraints->items[i]);
}
for (i = 0; i < other->physicsConstraints->size; i++) {
if (!spPhysicsConstraintDataArray_contains(self->physicsConstraints, other->physicsConstraints->items[i]))
spPhysicsConstraintDataArray_add(self->physicsConstraints, other->physicsConstraints->items[i]);
}
entry = spSkin_getAttachments(other);
while (entry) {
@ -238,10 +238,10 @@ void spSkin_copySkin(spSkin *self, const spSkin *other) {
spPathConstraintDataArray_add(self->pathConstraints, other->pathConstraints->items[i]);
}
for (i = 0; i < other->physicsConstraints->size; i++) {
if (!spPhysicsConstraintDataArray_contains(self->physicsConstraints, other->physicsConstraints->items[i]))
spPhysicsConstraintDataArray_add(self->physicsConstraints, other->physicsConstraints->items[i]);
}
for (i = 0; i < other->physicsConstraints->size; i++) {
if (!spPhysicsConstraintDataArray_contains(self->physicsConstraints, other->physicsConstraints->items[i]))
spPhysicsConstraintDataArray_add(self->physicsConstraints, other->physicsConstraints->items[i]);
}
entry = spSkin_getAttachments(other);
while (entry) {
@ -293,5 +293,5 @@ void spSkin_clear(spSkin *self) {
spIkConstraintDataArray_clear(self->ikConstraints);
spTransformConstraintDataArray_clear(self->transformConstraints);
spPathConstraintDataArray_clear(self->pathConstraints);
spPhysicsConstraintDataArray_clear(self->physicsConstraints);
spPhysicsConstraintDataArray_clear(self->physicsConstraints);
}

View File

@ -80,7 +80,7 @@ void spSlot_setToSetupPose(spSlot *self) {
else {
spAttachment *attachment = spSkeleton_getAttachmentForSlotIndex(
self->bone->skeleton, self->data->index, self->data->attachmentName);
self->attachment = 0;
self->attachment = 0;
spSlot_setAttachment(self, attachment);
}
}

View File

@ -36,7 +36,7 @@ spSlotData *spSlotData_create(const int index, const char *name, spBoneData *bon
MALLOC_STR(self->name, name);
self->boneData = boneData;
spColor_setFromFloats(&self->color, 1, 1, 1, 1);
self->visible = -1;
self->visible = -1;
return self;
}

View File

@ -193,8 +193,8 @@ void _spTransformConstraint_applyAbsoluteLocal(spTransformConstraint *self) {
rotation = bone->arotation;
if (mixRotate != 0) {
r = target->arotation - rotation + self->data->offsetRotation;
r -= CEIL(r / 360 - 0.5) * 360;
rotation += r * mixRotate;
r -= CEIL(r / 360 - 0.5) * 360;
rotation += r * mixRotate;
}
x = bone->ax, y = bone->ay;
@ -210,8 +210,8 @@ void _spTransformConstraint_applyAbsoluteLocal(spTransformConstraint *self) {
shearY = bone->ashearY;
if (mixShearY != 0) {
r = target->ashearY - shearY + self->data->offsetShearY;
r -= CEIL(r / 360 - 0.5) * 360;
shearY += r * mixShearY;
r -= CEIL(r / 360 - 0.5) * 360;
shearY += r * mixShearY;
}
spBone_updateWorldTransformWith(bone, x, y, rotation, scaleX, scaleY, bone->ashearX, shearY);
@ -259,11 +259,11 @@ void spTransformConstraint_update(spTransformConstraint *self) {
}
void spTransformConstraint_setToSetupPose(spTransformConstraint *self) {
spTransformConstraintData *data = self->data;
self->mixRotate = data->mixRotate;
self->mixX = data->mixX;
self->mixY = data->mixY;
self->mixScaleX = data->mixScaleX;
self->mixScaleY = data->mixScaleY;
self->mixShearY = data->mixShearY;
spTransformConstraintData *data = self->data;
self->mixRotate = data->mixRotate;
self->mixX = data->mixX;
self->mixY = data->mixY;
self->mixScaleX = data->mixScaleX;
self->mixScaleY = data->mixScaleY;
self->mixShearY = data->mixShearY;
}

View File

@ -32,7 +32,7 @@
#include "SpineSprite.h"
void SpineSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineSkeleton::update_world_transform);
ClassDB::bind_method(D_METHOD("update_world_transform", "physics"), &SpineSkeleton::update_world_transform);
ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineSkeleton::set_to_setup_pose);
ClassDB::bind_method(D_METHOD("set_bones_to_setup_pose"), &SpineSkeleton::set_bones_to_setup_pose);
ClassDB::bind_method(D_METHOD("set_slots_to_setup_pose"), &SpineSkeleton::set_slots_to_setup_pose);

View File

@ -649,146 +649,146 @@ void testMixAndMatch(spSkeletonData *skeletonData, spAtlas *atlas) {
}
void cloudpot(spSkeletonData *skeletonData, spAtlas *atlas) {
UNUSED(atlas);
UNUSED(atlas);
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
drawable->timeScale = 1;
drawable->setUsePremultipliedAlpha(true);
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
drawable->timeScale = 1;
drawable->setUsePremultipliedAlpha(true);
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "playing-in-the-rain", true);
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "playing-in-the-rain", true);
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - cloudpot");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - cloudpot");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
drawable->update(delta, SP_PHYSICS_UPDATE);
drawable->update(delta, SP_PHYSICS_UPDATE);
window.clear();
window.draw(*drawable);
window.display();
}
window.clear();
window.draw(*drawable);
window.display();
}
}
void sack(spSkeletonData *skeletonData, spAtlas *atlas) {
UNUSED(atlas);
UNUSED(atlas);
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
drawable->timeScale = 1;
drawable->setUsePremultipliedAlpha(true);
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
drawable->timeScale = 1;
drawable->setUsePremultipliedAlpha(true);
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "walk", true);
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "walk", true);
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - sack");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - sack");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
drawable->update(delta, SP_PHYSICS_UPDATE);
drawable->update(delta, SP_PHYSICS_UPDATE);
window.clear();
window.draw(*drawable);
window.display();
}
window.clear();
window.draw(*drawable);
window.display();
}
}
void snowglobe(spSkeletonData *skeletonData, spAtlas *atlas) {
UNUSED(atlas);
UNUSED(atlas);
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
drawable->timeScale = 1;
drawable->setUsePremultipliedAlpha(true);
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
drawable->timeScale = 1;
drawable->setUsePremultipliedAlpha(true);
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "shake", true);
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "shake", true);
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - snowglobe");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - snowglobe");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
drawable->update(delta, SP_PHYSICS_UPDATE);
drawable->update(delta, SP_PHYSICS_UPDATE);
window.clear();
window.draw(*drawable);
window.display();
}
window.clear();
window.draw(*drawable);
window.display();
}
}
void celestialCircus(spSkeletonData *skeletonData, spAtlas *atlas) {
UNUSED(atlas);
UNUSED(atlas);
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
drawable->timeScale = 1;
drawable->setUsePremultipliedAlpha(true);
SkeletonDrawable *drawable = new SkeletonDrawable(skeletonData);
drawable->timeScale = 1;
drawable->setUsePremultipliedAlpha(true);
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "swing", true);
spSkeleton *skeleton = drawable->skeleton;
skeleton->x = 320;
skeleton->y = 480;
spSkeleton_updateWorldTransform(skeleton, SP_PHYSICS_UPDATE);
spAnimationState_setAnimationByName(drawable->state, 0, "swing", true);
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - celestrial circus");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - celestrial circus");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
drawable->update(delta, SP_PHYSICS_UPDATE);
drawable->update(delta, SP_PHYSICS_UPDATE);
window.clear();
window.draw(*drawable);
window.display();
}
window.clear();
window.draw(*drawable);
window.display();
}
}
int main() {
testcase(cloudpot, "data/cloud-pot.json", "data/cloud-pot.skel", "data/cloud-pot-pma.atlas", 0.2);
testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f);
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f);
testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f);
testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor-pma.atlas", 0.5f);
testcase(cloudpot, "data/cloud-pot.json", "data/cloud-pot.skel", "data/cloud-pot-pma.atlas", 0.2);
testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f);
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f);
testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f);
testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor-pma.atlas", 0.5f);
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
testcase(ikDemo, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);
testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);

View File

@ -152,7 +152,7 @@ namespace spine {
void SkeletonDrawable::update(float deltaTime, spPhysics physics) {
spAnimationState_update(state, deltaTime * timeScale);
spAnimationState_apply(state, skeleton);
spSkeleton_update(skeleton, deltaTime * timeScale);
spSkeleton_update(skeleton, deltaTime * timeScale);
spSkeleton_updateWorldTransform(skeleton, physics);
}

View File

@ -775,7 +775,7 @@ int main() {
testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f);
testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f);
testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f);
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f);
testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.62f);
testcase(ikDemo, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f);
testcase(vine, "data/vine-pro.json", "data/vine-pro.skel", "data/vine-pma.atlas", 0.5f);

View File

@ -8,11 +8,15 @@ up into multiple modules:
1. `spine-canvas/`, a self-contained Canvas backend, built on the core classes.
1. `spine-threejs/`, a self-contained THREE.JS backend, built on the core classes.
1. `spine-player/`, a self-contained player to easily display Spine animations on your website, built on the core classes and WebGL backend.
1. `spine-phaser/`, a Phaser backend, built on the core classes.
1. `spine-pixi/`, a Pixi backend, built on the core classes.
In most cases, the `spine-player` module is best suited for your needs. Please refer to the [Spine Web Player documentation](https://esotericsoftware.com/spine-player) for more information.
For documentation of the core API in `spine-core`, please refer to our [Spine Runtimes Guide](http://esotericsoftware.com/spine-runtimes-guide).
For documentation of spine-phaser, please refer to our [spine-phaser Guide](https://esotericsoftware.com/spine-phaser).
For module specific APIs in `spine-canvas`, `spine-webgl`, and `spine-threejs`, please refer to the [Examples](#examples) in the respecitve `spine-<modulename>/example` folder. For `spine-webgl` specifically, we have provided additional [demos](spine-webgl/demos), which you can also [view online](http://esotericsoftware.com/spine-demos).
## Licensing
@ -45,20 +49,26 @@ You can include a module in your project via a `<script>` tag from the [unpkg](h
```
// spine-ts Core
<script src="https://unpkg.com/@esotericsoftware/spine-core@4.0.*/dist/iife/spine-core.js"></script>
<script src="https://unpkg.com/@esotericsoftware/spine-core@4.2.*/dist/iife/spine-core.js"></script>
// spine-ts Canvas
<script src="https://unpkg.com/@esotericsoftware/spine-canvas@4.0.*/dist/iife/spine-canvas.js"></script>
<script src="https://unpkg.com/@esotericsoftware/spine-canvas@4.2.*/dist/iife/spine-canvas.js"></script>
// spine-ts WebGL
<script src="https://unpkg.com/@esotericsoftware/spine-webgl@4.0.*/dist/iife/spine-webgl.js"></script>
<script src="https://unpkg.com/@esotericsoftware/spine-webgl@4.2.*/dist/iife/spine-webgl.js"></script>
// spine-ts Player, which requires a spine-player.css as well
<script src="https://unpkg.com/@esotericsoftware/spine-player@4.0.*/dist/iife/spine-player.js"></script>
<script src="https://unpkg.com/@esotericsoftware/spine-player@4.2.*/dist/iife/spine-player.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@esotericsoftware/spine-player@4.0.*/dist/spine-player.css">
// spine-ts ThreeJS
<script src="https://unpkg.com/@esotericsoftware/spine-threejs@4.0.*/dist/iife/spine-threejs.js"></script>
<script src="https://unpkg.com/@esotericsoftware/spine-threejs@4.2.*/dist/iife/spine-threejs.js"></script>
// spine-phaser
<script src="https://unpkg.com/@esotericsoftware/spine-phaser@4.2.*/dist/iife/spine-phaser.js"></script>
// spine-pixi
<script src="https://unpkg.com/@esotericsoftware/spine-pixi@4.2.*/dist/iife/spine-pixi.js"></script>
```
We also provide `js.map` source maps. They will be automatically fetched from unpkg when debugging code of a spine-module in Chrome, Firefox, or Safari, mapping the JavaScript code back to its original TypeScript sources.
@ -75,6 +85,8 @@ npm install @esotericsoftware/spine-canvas
npm install @esotericsoftware/spine-webgl
npm install @esotericsoftware/spine-player
npm install @esotericsoftware/spine-threejs
npm install @esotericsoftware/spine-phaser
npm install @esotericsoftware/spine-pixi
```
spine-ts modules are provided in the [ECMAScript format](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), which can be consumed natively by all modern browsers, or bundled by tools like [webpack](https://webpack.js.org/), [Babel](https://babeljs.io/), [Parcel](https://parceljs.org/), or [esbuild](https://esbuild.github.io/). You can import functions and classes from a spine-ts module in your JavaScript or TypeScript code using the `import` syntax to get access to all exported constants, functions, and classes of a module:

View File

@ -138,6 +138,7 @@ export class SkeletonMesh extends THREE.Object3D {
state.update(deltaTime);
state.apply(skeleton);
skeleton.update(deltaTime);
skeleton.updateWorldTransform(Physics.update);
this.updateGeometry();