Added SP_ prefix to enums.

Super fun. Don't forget you can use SPINE_SHORT_NAMES.
This commit is contained in:
NathanSweet 2014-04-27 23:23:13 +02:00
parent b44bca68d9
commit a180398975
14 changed files with 557 additions and 73 deletions

View File

@ -75,7 +75,13 @@ typedef spAnimation Animation;
/**/
typedef enum {
TIMELINE_SCALE, TIMELINE_ROTATE, TIMELINE_TRANLATE, TIMELINE_COLOR, TIMELINE_ATTACHMENT, TIMELINE_EVENT, TIMELINE_DRAWORDER
SP_TIMELINE_SCALE,
SP_TIMELINE_ROTATE,
SP_TIMELINE_TRANSLATE,
SP_TIMELINE_COLOR,
SP_TIMELINE_ATTACHMENT,
SP_TIMELINE_EVENT,
SP_TIMELINE_DRAWORDER
} spTimelineType;
struct spTimeline {
@ -90,6 +96,13 @@ void spTimeline_apply (const spTimeline* self, struct spSkeleton* skeleton, floa
#ifdef SPINE_SHORT_NAMES
typedef spTimeline Timeline;
#define TIMELINE_SCALE SP_TIMELINE_SCALE
#define TIMELINE_ROTATE SP_TIMELINE_ROTATE
#define TIMELINE_TRANSLATE SP_TIMELINE_TRANSLATE
#define TIMELINE_COLOR SP_TIMELINE_COLOR
#define TIMELINE_ATTACHMENT SP_TIMELINE_ATTACHMENT
#define TIMELINE_EVENT SP_TIMELINE_EVENT
#define TIMELINE_DRAWORDER SP_TIMELINE_DRAWORDER
#define Timeline_dispose(...) spTimeline_dispose(__VA_ARGS__)
#define Timeline_apply(...) spTimeline_apply(__VA_ARGS__)
#endif

View File

@ -40,7 +40,7 @@ extern "C" {
#endif
typedef enum {
ANIMATION_START, ANIMATION_END, ANIMATION_COMPLETE, ANIMATION_EVENT
SP_ANIMATION_START, SP_ANIMATION_END, SP_ANIMATION_COMPLETE, SP_ANIMATION_EVENT
} spEventType;
typedef struct spAnimationState spAnimationState;
@ -95,6 +95,10 @@ spTrackEntry* spAnimationState_getCurrent (spAnimationState* self, int trackInde
#ifdef SPINE_SHORT_NAMES
typedef spEventType EventType;
#define SP_ANIMATION_START SP_SP_ANIMATION_START
#define SP_ANIMATION_END SP_SP_ANIMATION_END
#define SP_ANIMATION_COMPLETE SP_SP_ANIMATION_COMPLETE
#define SP_ANIMATION_EVENT SP_SP_ANIMATION_EVENT
typedef spAnimationStateListener AnimationStateListener;
typedef spTrackEntry TrackEntry;
typedef spAnimationState AnimationState;

View File

@ -36,21 +36,27 @@ extern "C" {
#endif
typedef enum {
ATLAS_ALPHA, ATLAS_INTENSITY, ATLAS_LUMINANCE_ALPHA, ATLAS_RGB565, ATLAS_RGBA4444, ATLAS_RGB888, ATLAS_RGBA8888
SP_ATLAS_ALPHA,
SP_ATLAS_INTENSITY,
SP_ATLAS_LUMINANCE_ALPHA,
SP_ATLAS_RGB565,
SP_ATLAS_RGBA4444,
SP_ATLAS_RGB888,
SP_ATLAS_RGBA8888
} spAtlasFormat;
typedef enum {
ATLAS_NEAREST,
ATLAS_LINEAR,
ATLAS_MIPMAP,
ATLAS_MIPMAP_NEAREST_NEAREST,
ATLAS_MIPMAP_LINEAR_NEAREST,
ATLAS_MIPMAP_NEAREST_LINEAR,
ATLAS_MIPMAP_LINEAR_LINEAR
SP_ATLAS_NEAREST,
SP_ATLAS_LINEAR,
SP_ATLAS_MIPMAP,
SP_ATLAS_MIPMAP_NEAREST_NEAREST,
SP_ATLAS_MIPMAP_LINEAR_NEAREST,
SP_ATLAS_MIPMAP_NEAREST_LINEAR,
SP_ATLAS_MIPMAP_LINEAR_LINEAR
} spAtlasFilter;
typedef enum {
ATLAS_MIRROREDREPEAT, ATLAS_CLAMPTOEDGE, ATLAS_REPEAT
SP_ATLAS_MIRROREDREPEAT, SP_ATLAS_CLAMPTOEDGE, SP_ATLAS_REPEAT
} spAtlasWrap;
typedef struct spAtlasPage spAtlasPage;
@ -71,8 +77,25 @@ void spAtlasPage_dispose (spAtlasPage* self);
#ifdef SPINE_SHORT_NAMES
typedef spAtlasFormat AtlasFormat;
#define ATLAS_ALPHA SP_ATLAS_ALPHA
#define ATLAS_INTENSITY SP_ATLAS_INTENSITY
#define ATLAS_LUMINANCE_ALPHA SP_ATLAS_LUMINANCE_ALPHA
#define ATLAS_RGB565 SP_ATLAS_RGB565
#define ATLAS_RGBA4444 SP_ATLAS_RGBA4444
#define ATLAS_RGB888 SP_ATLAS_RGB888
#define ATLAS_RGBA8888 SP_ATLAS_RGBA8888
typedef spAtlasFilter AtlasFilter;
#define ATLAS_NEAREST SP_ATLAS_NEAREST
#define ATLAS_LINEAR SP_ATLAS_LINEAR
#define ATLAS_MIPMAP SP_ATLAS_MIPMAP
#define ATLAS_MIPMAP_NEAREST_NEAREST SP_ATLAS_MIPMAP_NEAREST_NEAREST
#define ATLAS_MIPMAP_LINEAR_NEAREST SP_ATLAS_MIPMAP_LINEAR_NEAREST
#define ATLAS_MIPMAP_NEAREST_LINEAR SP_ATLAS_MIPMAP_NEAREST_LINEAR
#define ATLAS_MIPMAP_LINEAR_LINEAR SP_ATLAS_MIPMAP_LINEAR_LINEAR
typedef spAtlasWrap AtlasWrap;
#define ATLAS_MIRROREDREPEAT SP_ATLAS_MIRROREDREPEAT
#define ATLAS_CLAMPTOEDGE SP_ATLAS_CLAMPTOEDGE
#define ATLAS_REPEAT SP_ATLAS_REPEAT
typedef spAtlasPage AtlasPage;
#define AtlasPage_create(...) spAtlasPage_create(__VA_ARGS__)
#define AtlasPage_dispose(...) spAtlasPage_dispose(__VA_ARGS__)

View File

@ -38,7 +38,7 @@ extern "C" {
struct spSlot;
typedef enum {
ATTACHMENT_REGION, ATTACHMENT_BOUNDING_BOX
SP_ATTACHMENT_REGION, SP_ATTACHMENT_BOUNDING_BOX, SP_ATTACHMENT_MESH, SP_ATTACHMENT_SKINNED_MESH
} spAttachmentType;
typedef struct spAttachment spAttachment;
@ -53,6 +53,10 @@ void spAttachment_dispose (spAttachment* self);
#ifdef SPINE_SHORT_NAMES
typedef spAttachmentType AttachmentType;
#define ATTACHMENT_REGION SP_ATTACHMENT_REGION
#define ATTACHMENT_BOUNDING_BOX SP_ATTACHMENT_BOUNDING_BOX
#define ATTACHMENT_MESH SP_ATTACHMENT_MESH
#define ATTACHMENT_SKINNED_MESH SP_ATTACHMENT_SKINNED_MESH
typedef spAttachment Attachment;
#define Attachment_dispose(...) spAttachment_dispose(__VA_ARGS__)
#endif

View File

@ -40,7 +40,7 @@ extern "C" {
#endif
typedef enum {
VERTEX_X1 = 0, VERTEX_Y1, VERTEX_X2, VERTEX_Y2, VERTEX_X3, VERTEX_Y3, VERTEX_X4, VERTEX_Y4
SP_VERTEX_X1 = 0, SP_VERTEX_Y1, SP_VERTEX_X2, SP_VERTEX_Y2, SP_VERTEX_X3, SP_VERTEX_Y3, SP_VERTEX_X4, SP_VERTEX_Y4
} spVertexIndex;
typedef struct spRegionAttachment spRegionAttachment;
@ -65,6 +65,14 @@ void spRegionAttachment_computeWorldVertices (spRegionAttachment* self, float x,
#ifdef SPINE_SHORT_NAMES
typedef spVertexIndex VertexIndex;
#define VERTEX_X1 SP_VERTEX_X1
#define VERTEX_Y1 SP_VERTEX_Y1
#define VERTEX_X2 SP_VERTEX_X2
#define VERTEX_Y2 SP_VERTEX_Y2
#define VERTEX_X3 SP_VERTEX_X3
#define VERTEX_Y3 SP_VERTEX_Y3
#define VERTEX_X4 SP_VERTEX_X4
#define VERTEX_Y4 SP_VERTEX_Y4
typedef spRegionAttachment RegionAttachment;
#define RegionAttachment_create(...) spRegionAttachment_create(__VA_ARGS__)
#define RegionAttachment_setUVs(...) spRegionAttachment_setUVs(__VA_ARGS__)

View File

@ -287,7 +287,7 @@ void _spRotateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
}
spRotateTimeline* spRotateTimeline_create (int frameCount) {
return _spBaseTimeline_create(frameCount, TIMELINE_ROTATE, 2, _spRotateTimeline_apply);
return _spBaseTimeline_create(frameCount, SP_TIMELINE_ROTATE, 2, _spRotateTimeline_apply);
}
void spRotateTimeline_setFrame (spRotateTimeline* self, int frameIndex, float time, float angle) {
@ -335,7 +335,7 @@ void _spTranslateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleto
}
spTranslateTimeline* spTranslateTimeline_create (int frameCount) {
return _spBaseTimeline_create(frameCount, TIMELINE_TRANLATE, 3, _spTranslateTimeline_apply);
return _spBaseTimeline_create(frameCount, SP_TIMELINE_TRANSLATE, 3, _spTranslateTimeline_apply);
}
void spTranslateTimeline_setFrame (spTranslateTimeline* self, int frameIndex, float time, float x, float y) {
@ -379,7 +379,7 @@ void _spScaleTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f
}
spScaleTimeline* spScaleTimeline_create (int frameCount) {
return _spBaseTimeline_create(frameCount, TIMELINE_SCALE, 3, _spScaleTimeline_apply);
return _spBaseTimeline_create(frameCount, SP_TIMELINE_SCALE, 3, _spScaleTimeline_apply);
}
void spScaleTimeline_setFrame (spScaleTimeline* self, int frameIndex, float time, float x, float y) {
@ -443,7 +443,7 @@ void _spColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f
}
spColorTimeline* spColorTimeline_create (int frameCount) {
return (spColorTimeline*)_spBaseTimeline_create(frameCount, TIMELINE_COLOR, 5, _spColorTimeline_apply);
return (spColorTimeline*)_spBaseTimeline_create(frameCount, SP_TIMELINE_COLOR, 5, _spColorTimeline_apply);
}
void spColorTimeline_setFrame (spColorTimeline* self, int frameIndex, float time, float r, float g, float b, float a) {
@ -490,7 +490,7 @@ void _spAttachmentTimeline_dispose (spTimeline* timeline) {
spAttachmentTimeline* spAttachmentTimeline_create (int frameCount) {
spAttachmentTimeline* self = NEW(spAttachmentTimeline);
_spTimeline_init(SUPER(self), TIMELINE_ATTACHMENT, _spAttachmentTimeline_dispose, _spAttachmentTimeline_apply);
_spTimeline_init(SUPER(self), SP_TIMELINE_ATTACHMENT, _spAttachmentTimeline_dispose, _spAttachmentTimeline_apply);
CONST_CAST(int, self->framesLength) = frameCount;
CONST_CAST(float*, self->frames) = CALLOC(float, frameCount);
@ -557,7 +557,7 @@ void _spEventTimeline_dispose (spTimeline* timeline) {
spEventTimeline* spEventTimeline_create (int frameCount) {
spEventTimeline* self = NEW(spEventTimeline);
_spTimeline_init(SUPER(self), TIMELINE_EVENT, _spEventTimeline_dispose, _spEventTimeline_apply);
_spTimeline_init(SUPER(self), SP_TIMELINE_EVENT, _spEventTimeline_dispose, _spEventTimeline_apply);
CONST_CAST(int, self->framesLength) = frameCount;
CONST_CAST(float*, self->frames) = CALLOC(float, frameCount);
@ -613,7 +613,7 @@ void _spDrawOrderTimeline_dispose (spTimeline* timeline) {
spDrawOrderTimeline* spDrawOrderTimeline_create (int frameCount, int slotCount) {
spDrawOrderTimeline* self = NEW(spDrawOrderTimeline);
_spTimeline_init(SUPER(self), TIMELINE_DRAWORDER, _spDrawOrderTimeline_dispose, _spDrawOrderTimeline_apply);
_spTimeline_init(SUPER(self), SP_TIMELINE_DRAWORDER, _spDrawOrderTimeline_dispose, _spDrawOrderTimeline_apply);
CONST_CAST(int, self->framesLength) = frameCount;
CONST_CAST(float*, self->frames) = CALLOC(float, frameCount);

View File

@ -155,14 +155,14 @@ void spAnimationState_apply (spAnimationState* self, spSkeleton* skeleton) {
for (ii = 0; ii < eventCount; ii++) {
spEvent* event = internal->events[ii];
if (current->listener) {
current->listener(self, i, ANIMATION_EVENT, event, 0);
current->listener(self, i, SP_ANIMATION_EVENT, event, 0);
if (self->tracks[i] != current) {
entryChanged = 1;
break;
}
}
if (self->listener) {
self->listener(self, i, ANIMATION_EVENT, event, 0);
self->listener(self, i, SP_ANIMATION_EVENT, event, 0);
if (self->tracks[i] != current) {
entryChanged = 1;
break;
@ -176,11 +176,11 @@ void spAnimationState_apply (spAnimationState* self, spSkeleton* skeleton) {
: (current->lastTime < current->endTime && time >= current->endTime)) {
int count = (int)(time / current->endTime);
if (current->listener) {
current->listener(self, i, ANIMATION_COMPLETE, 0, count);
current->listener(self, i, SP_ANIMATION_COMPLETE, 0, count);
if (self->tracks[i] != current) continue;
}
if (self->listener) {
self->listener(self, i, ANIMATION_COMPLETE, 0, count);
self->listener(self, i, SP_ANIMATION_COMPLETE, 0, count);
if (self->tracks[i] != current) continue;
}
}
@ -202,8 +202,8 @@ void spAnimationState_clearTrack (spAnimationState* self, int trackIndex) {
current = self->tracks[trackIndex];
if (!current) return;
if (current->listener) current->listener(self, trackIndex, ANIMATION_END, 0, 0);
if (self->listener) self->listener(self, trackIndex, ANIMATION_END, 0, 0);
if (current->listener) current->listener(self, trackIndex, SP_ANIMATION_END, 0, 0);
if (self->listener) self->listener(self, trackIndex, SP_ANIMATION_END, 0, 0);
self->tracks[trackIndex] = 0;
@ -228,8 +228,8 @@ void _spAnimationState_setCurrent (spAnimationState* self, int index, spTrackEnt
spTrackEntry* previous = current->previous;
current->previous = 0;
if (current->listener) current->listener(self, index, ANIMATION_END, 0, 0);
if (self->listener) self->listener(self, index, ANIMATION_END, 0, 0);
if (current->listener) current->listener(self, index, SP_ANIMATION_END, 0, 0);
if (self->listener) self->listener(self, index, SP_ANIMATION_END, 0, 0);
entry->mixDuration = spAnimationStateData_getMix(self->data, current->animation, entry->animation);
if (entry->mixDuration > 0) {
@ -249,10 +249,10 @@ void _spAnimationState_setCurrent (spAnimationState* self, int index, spTrackEnt
self->tracks[index] = entry;
if (entry->listener) {
entry->listener(self, index, ANIMATION_START, 0, 0);
entry->listener(self, index, SP_ANIMATION_START, 0, 0);
if (self->tracks[index] != entry) return;
}
if (self->listener) self->listener(self, index, ANIMATION_START, 0, 0);
if (self->listener) self->listener(self, index, SP_ANIMATION_START, 0, 0);
}
spTrackEntry* spAnimationState_setAnimationByName (spAnimationState* self, int trackIndex, const char* animationName,

View File

@ -212,8 +212,8 @@ spAtlas* spAtlas_readAtlas (const char* begin, int length, const char* dir) {
if (!readValue(end, &str)) return abortAtlas(self);
if (!equals(&str, "none")) {
page->uWrap = *str.begin == 'x' ? ATLAS_REPEAT : (*str.begin == 'y' ? ATLAS_CLAMPTOEDGE : ATLAS_REPEAT);
page->vWrap = *str.begin == 'x' ? ATLAS_CLAMPTOEDGE : (*str.begin == 'y' ? ATLAS_REPEAT : ATLAS_REPEAT);
page->uWrap = *str.begin == 'x' ? SP_ATLAS_REPEAT : (*str.begin == 'y' ? SP_ATLAS_CLAMPTOEDGE : SP_ATLAS_REPEAT);
page->vWrap = *str.begin == 'x' ? SP_ATLAS_CLAMPTOEDGE : (*str.begin == 'y' ? SP_ATLAS_REPEAT : SP_ATLAS_REPEAT);
}
_spAtlasPage_createTexture(page, path);

View File

@ -35,7 +35,7 @@ spAttachment* _spAtlasAttachmentLoader_newAttachment (spAttachmentLoader* loader
const char* name, const char* path) {
spAtlasAttachmentLoader* self = SUB_CAST(spAtlasAttachmentLoader, loader);
switch (type) {
case ATTACHMENT_REGION: {
case SP_ATTACHMENT_REGION: {
spRegionAttachment* attachment;
spAtlasRegion* region = spAtlas_findRegion(self->atlas, name);
if (!region) {
@ -53,7 +53,7 @@ spAttachment* _spAtlasAttachmentLoader_newAttachment (spAttachmentLoader* loader
attachment->regionOriginalHeight = region->originalHeight;
return SUPER(attachment);
}
case ATTACHMENT_BOUNDING_BOX:
case SP_ATTACHMENT_BOUNDING_BOX:
return SUPER(spBoundingBoxAttachment_create(name));
default:
_spAttachmentLoader_setUnknownTypeError(loader, type);

View File

@ -42,7 +42,7 @@ void _spBoundingBoxAttachment_dispose (spAttachment* attachment) {
spBoundingBoxAttachment* spBoundingBoxAttachment_create (const char* name) {
spBoundingBoxAttachment* self = NEW(spBoundingBoxAttachment);
_spAttachment_init(SUPER(self), name, ATTACHMENT_BOUNDING_BOX, _spBoundingBoxAttachment_dispose);
_spAttachment_init(SUPER(self), name, SP_ATTACHMENT_BOUNDING_BOX, _spBoundingBoxAttachment_dispose);
return self;
}

View File

@ -47,29 +47,29 @@ spRegionAttachment* spRegionAttachment_create (const char* name) {
self->g = 1;
self->b = 1;
self->a = 1;
_spAttachment_init(SUPER(self), name, ATTACHMENT_REGION, _spRegionAttachment_dispose);
_spAttachment_init(SUPER(self), name, SP_ATTACHMENT_REGION, _spRegionAttachment_dispose);
return self;
}
void spRegionAttachment_setUVs (spRegionAttachment* self, float u, float v, float u2, float v2, int/*bool*/rotate) {
if (rotate) {
self->uvs[VERTEX_X2] = u;
self->uvs[VERTEX_Y2] = v2;
self->uvs[VERTEX_X3] = u;
self->uvs[VERTEX_Y3] = v;
self->uvs[VERTEX_X4] = u2;
self->uvs[VERTEX_Y4] = v;
self->uvs[VERTEX_X1] = u2;
self->uvs[VERTEX_Y1] = v2;
self->uvs[SP_VERTEX_X2] = u;
self->uvs[SP_VERTEX_Y2] = v2;
self->uvs[SP_VERTEX_X3] = u;
self->uvs[SP_VERTEX_Y3] = v;
self->uvs[SP_VERTEX_X4] = u2;
self->uvs[SP_VERTEX_Y4] = v;
self->uvs[SP_VERTEX_X1] = u2;
self->uvs[SP_VERTEX_Y1] = v2;
} else {
self->uvs[VERTEX_X1] = u;
self->uvs[VERTEX_Y1] = v2;
self->uvs[VERTEX_X2] = u;
self->uvs[VERTEX_Y2] = v;
self->uvs[VERTEX_X3] = u2;
self->uvs[VERTEX_Y3] = v;
self->uvs[VERTEX_X4] = u2;
self->uvs[VERTEX_Y4] = v2;
self->uvs[SP_VERTEX_X1] = u;
self->uvs[SP_VERTEX_Y1] = v2;
self->uvs[SP_VERTEX_X2] = u;
self->uvs[SP_VERTEX_Y2] = v;
self->uvs[SP_VERTEX_X3] = u2;
self->uvs[SP_VERTEX_Y3] = v;
self->uvs[SP_VERTEX_X4] = u2;
self->uvs[SP_VERTEX_Y4] = v2;
}
}
@ -96,26 +96,26 @@ void spRegionAttachment_updateOffset (spRegionAttachment* self) {
float localX2Sin = localX2 * sine;
float localY2Cos = localY2 * cosine + self->y;
float localY2Sin = localY2 * sine;
self->offset[VERTEX_X1] = localXCos - localYSin;
self->offset[VERTEX_Y1] = localYCos + localXSin;
self->offset[VERTEX_X2] = localXCos - localY2Sin;
self->offset[VERTEX_Y2] = localY2Cos + localXSin;
self->offset[VERTEX_X3] = localX2Cos - localY2Sin;
self->offset[VERTEX_Y3] = localY2Cos + localX2Sin;
self->offset[VERTEX_X4] = localX2Cos - localYSin;
self->offset[VERTEX_Y4] = localYCos + localX2Sin;
self->offset[SP_VERTEX_X1] = localXCos - localYSin;
self->offset[SP_VERTEX_Y1] = localYCos + localXSin;
self->offset[SP_VERTEX_X2] = localXCos - localY2Sin;
self->offset[SP_VERTEX_Y2] = localY2Cos + localXSin;
self->offset[SP_VERTEX_X3] = localX2Cos - localY2Sin;
self->offset[SP_VERTEX_Y3] = localY2Cos + localX2Sin;
self->offset[SP_VERTEX_X4] = localX2Cos - localYSin;
self->offset[SP_VERTEX_Y4] = localYCos + localX2Sin;
}
void spRegionAttachment_computeWorldVertices (spRegionAttachment* self, float x, float y, spBone* bone, float* vertices) {
float* offset = self->offset;
x += bone->worldX;
y += bone->worldY;
vertices[VERTEX_X1] = offset[VERTEX_X1] * bone->m00 + offset[VERTEX_Y1] * bone->m01 + x;
vertices[VERTEX_Y1] = offset[VERTEX_X1] * bone->m10 + offset[VERTEX_Y1] * bone->m11 + y;
vertices[VERTEX_X2] = offset[VERTEX_X2] * bone->m00 + offset[VERTEX_Y2] * bone->m01 + x;
vertices[VERTEX_Y2] = offset[VERTEX_X2] * bone->m10 + offset[VERTEX_Y2] * bone->m11 + y;
vertices[VERTEX_X3] = offset[VERTEX_X3] * bone->m00 + offset[VERTEX_Y3] * bone->m01 + x;
vertices[VERTEX_Y3] = offset[VERTEX_X3] * bone->m10 + offset[VERTEX_Y3] * bone->m11 + y;
vertices[VERTEX_X4] = offset[VERTEX_X4] * bone->m00 + offset[VERTEX_Y4] * bone->m01 + x;
vertices[VERTEX_Y4] = offset[VERTEX_X4] * bone->m10 + offset[VERTEX_Y4] * bone->m11 + y;
vertices[SP_VERTEX_X1] = offset[SP_VERTEX_X1] * bone->m00 + offset[SP_VERTEX_Y1] * bone->m01 + x;
vertices[SP_VERTEX_Y1] = offset[SP_VERTEX_X1] * bone->m10 + offset[SP_VERTEX_Y1] * bone->m11 + y;
vertices[SP_VERTEX_X2] = offset[SP_VERTEX_X2] * bone->m00 + offset[SP_VERTEX_Y2] * bone->m01 + x;
vertices[SP_VERTEX_Y2] = offset[SP_VERTEX_X2] * bone->m10 + offset[SP_VERTEX_Y2] * bone->m11 + y;
vertices[SP_VERTEX_X3] = offset[SP_VERTEX_X3] * bone->m00 + offset[SP_VERTEX_Y3] * bone->m01 + x;
vertices[SP_VERTEX_Y3] = offset[SP_VERTEX_X3] * bone->m10 + offset[SP_VERTEX_Y3] * bone->m11 + y;
vertices[SP_VERTEX_X4] = offset[SP_VERTEX_X4] * bone->m00 + offset[SP_VERTEX_Y4] * bone->m01 + x;
vertices[SP_VERTEX_Y4] = offset[SP_VERTEX_X4] * bone->m10 + offset[SP_VERTEX_Y4] * bone->m11 + y;
}

View File

@ -131,7 +131,7 @@ void spSkeletonBounds_update (spSkeletonBounds* self, spSkeleton* skeleton, int/
spSlot* slot = skeleton->slots[i];
spAttachment* attachment = slot->attachment;
if (!attachment || attachment->type != ATTACHMENT_BOUNDING_BOX) continue;
if (!attachment || attachment->type != SP_ATTACHMENT_BOUNDING_BOX) continue;
boundingBox = (spBoundingBoxAttachment*)attachment;
self->boundingBoxes[self->count] = boundingBox;

View File

@ -420,9 +420,9 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
const char* typeString = Json_getString(attachmentMap, "type", "region");
spAttachmentType type;
if (strcmp(typeString, "region") == 0)
type = ATTACHMENT_REGION;
type = SP_ATTACHMENT_REGION;
else if (strcmp(typeString, "boundingbox") == 0)
type = ATTACHMENT_BOUNDING_BOX;
type = SP_ATTACHMENT_BOUNDING_BOX;
else {
spSkeletonData_dispose(skeletonData);
_spSkeletonJson_setError(self, root, "Unknown attachment type: ", typeString);
@ -440,7 +440,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
}
switch (attachment->type) {
case ATTACHMENT_REGION: {
case SP_ATTACHMENT_REGION: {
spRegionAttachment* regionAttachment = (spRegionAttachment*)attachment;
regionAttachment->x = Json_getFloat(attachmentMap, "x", 0) * self->scale;
regionAttachment->y = Json_getFloat(attachmentMap, "y", 0) * self->scale;
@ -461,7 +461,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
spRegionAttachment_updateOffset(regionAttachment);
break;
}
case ATTACHMENT_BOUNDING_BOX: {
case SP_ATTACHMENT_BOUNDING_BOX: {
spBoundingBoxAttachment* box = (spBoundingBoxAttachment*)attachment;
Json* verticesArray = Json_getItem(attachmentMap, "vertices");
Json* vertex;

View File

@ -0,0 +1,432 @@
/******************************************************************************
* Spine Runtimes Software License
* Version 2.1
*
* Copyright (c) 2013, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable and
* non-transferable license to install, execute and perform the Spine Runtimes
* Software (the "Software") solely for internal use. Without the written
* permission of Esoteric Software (typically granted by licensing Spine), you
* may not (a) modify, translate, adapt or otherwise create derivative works,
* improvements of the Software or develop new applications using the Software
* or (b) remove, delete, alter or obscure any trademarks or any copyright,
* trademark, patent or other intellectual property or proprietary rights
* notices on or in the Software, including any copy thereof. Redistributions
* in binary or source form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package com.esotericsoftware.spine;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool.Poolable;
import com.badlogic.gdx.utils.Pools;
/** Stores state for an animation and automatically mixes between animations. */
public class AnimationStatePR {
private final AnimationStateData data;
private Array<TrackEntry> tracks = new Array();
private final Array<Event> events = new Array();
private final Array<AnimationStateListener> listeners = new Array();
private float timeScale = 1;
public AnimationStatePR (AnimationStateData data) {
if (data == null) throw new IllegalArgumentException("data cannot be null.");
this.data = data;
}
public void update (float delta) {
delta *= timeScale;
for (int i = 0; i < tracks.size; i++) {
TrackEntry current = tracks.get(i);
if (current == null) continue;
float trackDelta = delta * current.timeScale;
current.time += trackDelta;
if (current.mixDuration > 0) {
if (current.previous != null) current.previous.time += trackDelta;
current.mixTime += trackDelta;
}
TrackEntry next = current.next;
if (next != null) {
if (current.lastTime >= next.delay) setCurrent(i, next);
} else {
// End non-looping animation when it reaches its end time and there is no next entry.
if (!current.loop && current.lastTime >= current.endTime) clearTrack(i);
}
}
}
public void apply (Skeleton skeleton) {
Array<Event> events = this.events;
int listenerCount = listeners.size;
for (int i = 0; i < tracks.size; i++) {
TrackEntry current = tracks.get(i);
if (current == null) continue;
events.size = 0;
float time = current.time;
float lastTime = current.lastTime;
float endTime = current.endTime;
boolean loop = current.loop;
if (!loop && time > endTime) time = endTime;
TrackEntry previous = current.previous;
if (current.mixDuration > 0) {
float alpha = current.mixTime / current.mixDuration;
if (alpha >= 1) {
alpha = 1;
current.mixDuration = 0;
}
if (previous == null) {
current.animation.mix(skeleton, lastTime, time, loop, events, alpha);
System.out.println("none -> " + current.animation + ": " + alpha);
} else {
float previousTime = previous.time;
if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
if (current.animation == null) {
previous.animation.mix(skeleton, previousTime, previousTime, previous.loop, null, 1 - alpha);
System.out.println(previous.animation + " -> none: " + alpha);
} else {
previous.animation.apply(skeleton, previousTime, previousTime, previous.loop, null);
current.animation.mix(skeleton, lastTime, time, loop, events, alpha);
System.out.println(previous.animation + " -> " + current.animation + ": " + alpha);
}
if (alpha >= 1) {
Pools.free(previous);
current.previous = null;
current.mixDuration = 0;
}
}
} else
current.animation.apply(skeleton, lastTime, time, loop, events);
for (int ii = 0, nn = events.size; ii < nn; ii++) {
Event event = events.get(ii);
if (current.listener != null) current.listener.event(i, event);
for (int iii = 0; iii < listenerCount; iii++)
listeners.get(iii).event(i, event);
}
// Check if completed the animation or a loop iteration.
if (loop ? (lastTime % endTime > time % endTime) : (lastTime < endTime && time >= endTime)) {
int count = (int)(time / endTime);
if (current.listener != null) current.listener.complete(i, count);
for (int ii = 0, nn = listeners.size; ii < nn; ii++)
listeners.get(ii).complete(i, count);
}
current.lastTime = current.time;
}
}
public void clearTracks () {
for (int i = 0, n = tracks.size; i < n; i++)
clearTrack(i);
tracks.clear();
}
public void clearTrack (int trackIndex) {
if (trackIndex >= tracks.size) return;
TrackEntry current = tracks.get(trackIndex);
if (current == null) return;
if (current.listener != null) current.listener.end(trackIndex);
for (int i = 0, n = listeners.size; i < n; i++)
listeners.get(i).end(trackIndex);
tracks.set(trackIndex, null);
freeAll(current);
if (current.previous != null) Pools.free(current.previous);
}
private void freeAll (TrackEntry entry) {
while (entry != null) {
TrackEntry next = entry.next;
Pools.free(entry);
entry = next;
}
}
private TrackEntry expandToIndex (int index) {
if (index < tracks.size) return tracks.get(index);
tracks.ensureCapacity(index - tracks.size + 1);
tracks.size = index + 1;
return null;
}
private void setCurrent (int index, TrackEntry entry) {
TrackEntry current = expandToIndex(index);
if (current != null) {
if (current.previous != null) {
Pools.free(current.previous);
current.previous = null;
}
if (current.listener != null) current.listener.end(index);
for (int i = 0, n = listeners.size; i < n; i++)
listeners.get(i).end(index);
entry.mixDuration = entry.animation != null ? data.getMix(current.animation, entry.animation) : data.defaultMix;
if (entry.mixDuration > 0) {
entry.mixTime = 0;
entry.previous = current;
} else
Pools.free(current);
} else
entry.mixDuration = data.defaultMix;
tracks.set(index, entry);
if (entry.listener != null) entry.listener.start(index);
for (int i = 0, n = listeners.size; i < n; i++)
listeners.get(i).start(index);
}
/** @see #setAnimation(int, Animation, boolean) */
public TrackEntry setAnimation (int trackIndex, String animationName, boolean loop) {
Animation animation = data.getSkeletonData().findAnimation(animationName);
if (animation == null) throw new IllegalArgumentException("Animation not found: " + animationName);
return setAnimation(trackIndex, animation, loop);
}
/** Set the current animation. Any queued animations are cleared. */
public TrackEntry setAnimation (int trackIndex, Animation animation, boolean loop) {
TrackEntry current = expandToIndex(trackIndex);
if (current != null) freeAll(current.next);
TrackEntry entry = Pools.obtain(TrackEntry.class);
entry.animation = animation;
entry.loop = loop;
entry.endTime = animation.getDuration();
setCurrent(trackIndex, entry);
return entry;
}
/** {@link #addAnimation(int, Animation, boolean, float)} */
public TrackEntry addAnimation (int trackIndex, String animationName, boolean loop, float delay) {
Animation animation = data.getSkeletonData().findAnimation(animationName);
if (animation == null) throw new IllegalArgumentException("Animation not found: " + animationName);
return addAnimation(trackIndex, animation, loop, delay);
}
/** Adds an animation to be played delay seconds after the current or last queued animation.
* @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */
public TrackEntry addAnimation (int trackIndex, Animation animation, boolean loop, float delay) {
TrackEntry entry = Pools.obtain(TrackEntry.class);
entry.animation = animation;
entry.loop = loop;
entry.endTime = animation != null ? animation.getDuration() : data.defaultMix;
TrackEntry last = expandToIndex(trackIndex);
if (last != null) {
while (last.next != null)
last = last.next;
last.next = entry;
} else
tracks.set(trackIndex, entry);
if (delay <= 0) {
if (last != null) {
float mix = animation != null ? data.getMix(last.animation, animation) : data.defaultMix;
delay += last.endTime - mix;
} else
delay = 0;
}
entry.delay = delay;
return entry;
}
/** @return May be null. */
public TrackEntry getCurrent (int trackIndex) {
if (trackIndex >= tracks.size) return null;
return tracks.get(trackIndex);
}
/** Adds a listener to receive events for all animations. */
public void addListener (AnimationStateListener listener) {
if (listener == null) throw new IllegalArgumentException("listener cannot be null.");
listeners.add(listener);
}
/** Removes the listener added with {@link #addListener(AnimationStateListener)}. */
public void removeListener (AnimationStateListener listener) {
listeners.removeValue(listener, true);
}
public float getTimeScale () {
return timeScale;
}
public void setTimeScale (float timeScale) {
this.timeScale = timeScale;
}
public AnimationStateData getData () {
return data;
}
public String toString () {
StringBuilder buffer = new StringBuilder(64);
for (int i = 0, n = tracks.size; i < n; i++) {
TrackEntry entry = tracks.get(i);
if (entry == null) continue;
if (buffer.length() > 0) buffer.append(", ");
buffer.append(entry.toString());
}
if (buffer.length() == 0) return "<none>";
return buffer.toString();
}
static public class TrackEntry implements Poolable {
TrackEntry next, previous;
Animation animation;
boolean loop;
float delay, time, lastTime, endTime, timeScale = 1;
float mixTime, mixDuration;
AnimationStateListener listener;
public void reset () {
next = null;
previous = null;
animation = null;
listener = null;
timeScale = 1;
lastTime = -1;
time = 0;
mixDuration = 0;
mixTime = 0;
}
public Animation getAnimation () {
return animation;
}
public void setAnimation (Animation animation) {
this.animation = animation;
}
public boolean getLoop () {
return loop;
}
public void setLoop (boolean loop) {
this.loop = loop;
}
public float getDelay () {
return delay;
}
public void setDelay (float delay) {
this.delay = delay;
}
public float getTime () {
return time;
}
public void setTime (float time) {
this.time = time;
}
public float getEndTime () {
return endTime;
}
public void setEndTime (float endTime) {
this.endTime = endTime;
}
public AnimationStateListener getListener () {
return listener;
}
public void setListener (AnimationStateListener listener) {
this.listener = listener;
}
public float getLastTime () {
return lastTime;
}
public void setLastTime (float lastTime) {
this.lastTime = lastTime;
}
public float getTimeScale () {
return timeScale;
}
public void setTimeScale (float timeScale) {
this.timeScale = timeScale;
}
public TrackEntry getNext () {
return next;
}
public void setNext (TrackEntry next) {
this.next = next;
}
/** Returns true if the current time is greater than the end time, regardless of looping. */
public boolean isComplete () {
return time >= endTime;
}
public String toString () {
return animation == null ? "<none>" : animation.name;
}
}
static public interface AnimationStateListener {
/** Invoked when the current animation triggers an event. */
public void event (int trackIndex, Event event);
/** Invoked when the current animation has completed.
* @param loopCount The number of times the animation reached the end. */
public void complete (int trackIndex, int loopCount);
/** Invoked just after the current animation is set. */
public void start (int trackIndex);
/** Invoked just before the current animation is replaced. */
public void end (int trackIndex);
}
static public abstract class AnimationStateAdapter implements AnimationStateListener {
public void event (int trackIndex, Event event) {
}
public void complete (int trackIndex, int loopCount) {
}
public void start (int trackIndex) {
}
public void end (int trackIndex) {
}
}
}