Reverting spine files

This commit is contained in:
hobogenized 2015-04-22 22:07:52 -04:00
parent e2aaa88f1e
commit 30b2821729
3 changed files with 56 additions and 56 deletions

View File

@ -266,12 +266,12 @@ void _spRotateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
bone = skeleton->bones[self->boneIndex]; bone = skeleton->bones[self->boneIndex];
if (time >= self->frames[self->framesCount - 2]) { /* Time is after last frame. */ if (time >= self->frames[self->framesCount - 2]) { /* Time is after last frame. */
float tempAmount = bone->data->rotation + self->frames[self->framesCount - 1] - bone->rotation; float amount = bone->data->rotation + self->frames[self->framesCount - 1] - bone->rotation;
while (tempAmount > 180) while (amount > 180)
tempAmount -= 360; amount -= 360;
while (tempAmount < -180) while (amount < -180)
tempAmount += 360; amount += 360;
bone->rotation += tempAmount * alpha; bone->rotation += amount * alpha;
return; return;
} }

View File

@ -266,7 +266,7 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
int slotIndex = spSkeletonData_findSlotIndex(skeletonData, slotMap->name); int slotIndex = spSkeletonData_findSlotIndex(skeletonData, slotMap->name);
Json* timelineArray; Json* timelineArray;
for (timelineArray = slotMap->child; timelineArray; timelineArray = timelineArray->next) { for (timelineArray = slotMap->child; timelineArray; timelineArray = timelineArray->next) {
Json* currFrame; Json* frame;
int verticesCount = 0; int verticesCount = 0;
float* tempVertices; float* tempVertices;
spFFDTimeline *timeline; spFFDTimeline *timeline;
@ -287,8 +287,8 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
timeline->attachment = attachment; timeline->attachment = attachment;
tempVertices = MALLOC(float, verticesCount); tempVertices = MALLOC(float, verticesCount);
for (currFrame = timelineArray->child, i = 0; currFrame; currFrame = currFrame->next, ++i) { for (frame = timelineArray->child, i = 0; frame; frame = frame->next, ++i) {
Json* vertices = Json_getItem(currFrame, "vertices"); Json* vertices = Json_getItem(frame, "vertices");
float* frameVertices; float* frameVertices;
if (!vertices) { if (!vertices) {
if (attachment->type == SP_ATTACHMENT_MESH) if (attachment->type == SP_ATTACHMENT_MESH)
@ -298,7 +298,7 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
memset(frameVertices, 0, sizeof(float) * verticesCount); memset(frameVertices, 0, sizeof(float) * verticesCount);
} }
} else { } else {
int v, start = Json_getInt(currFrame, "offset", 0); int v, start = Json_getInt(frame, "offset", 0);
Json* vertex; Json* vertex;
frameVertices = tempVertices; frameVertices = tempVertices;
memset(frameVertices, 0, sizeof(float) * start); memset(frameVertices, 0, sizeof(float) * start);
@ -316,8 +316,8 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
frameVertices[v] += meshVertices[v]; frameVertices[v] += meshVertices[v];
} }
} }
spFFDTimeline_setFrame(timeline, i, Json_getFloat(currFrame, "time", 0), frameVertices); spFFDTimeline_setFrame(timeline, i, Json_getFloat(frame, "time", 0), frameVertices);
readCurve(SUPER(timeline), i, currFrame); readCurve(SUPER(timeline), i, frame);
} }
FREE(tempVertices); FREE(tempVertices);
@ -333,16 +333,16 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
spDrawOrderTimeline* timeline = spDrawOrderTimeline_create(drawOrder->size, skeletonData->slotsCount); spDrawOrderTimeline* timeline = spDrawOrderTimeline_create(drawOrder->size, skeletonData->slotsCount);
for (frame = drawOrder->child, i = 0; frame; frame = frame->next, ++i) { for (frame = drawOrder->child, i = 0; frame; frame = frame->next, ++i) {
int ii; int ii;
int* currDrawOrder = 0; int* drawOrder = 0;
Json* offsets = Json_getItem(frame, "offsets"); Json* offsets = Json_getItem(frame, "offsets");
if (offsets) { if (offsets) {
Json* offsetMap; Json* offsetMap;
int* unchanged = MALLOC(int, skeletonData->slotsCount - offsets->size); int* unchanged = MALLOC(int, skeletonData->slotsCount - offsets->size);
int originalIndex = 0, unchangedIndex = 0; int originalIndex = 0, unchangedIndex = 0;
currDrawOrder = MALLOC(int, skeletonData->slotsCount); drawOrder = MALLOC(int, skeletonData->slotsCount);
for (ii = skeletonData->slotsCount - 1; ii >= 0; --ii) for (ii = skeletonData->slotsCount - 1; ii >= 0; --ii)
currDrawOrder[ii] = -1; drawOrder[ii] = -1;
for (offsetMap = offsets->child; offsetMap; offsetMap = offsetMap->next) { for (offsetMap = offsets->child; offsetMap; offsetMap = offsetMap->next) {
int slotIndex = spSkeletonData_findSlotIndex(skeletonData, Json_getString(offsetMap, "slot", 0)); int slotIndex = spSkeletonData_findSlotIndex(skeletonData, Json_getString(offsetMap, "slot", 0));
@ -355,7 +355,7 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
while (originalIndex != slotIndex) while (originalIndex != slotIndex)
unchanged[unchangedIndex++] = originalIndex++; unchanged[unchangedIndex++] = originalIndex++;
/* Set changed items. */ /* Set changed items. */
currDrawOrder[originalIndex + Json_getInt(offsetMap, "offset", 0)] = originalIndex; drawOrder[originalIndex + Json_getInt(offsetMap, "offset", 0)] = originalIndex;
originalIndex++; originalIndex++;
} }
/* Collect remaining unchanged items. */ /* Collect remaining unchanged items. */
@ -363,11 +363,11 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
unchanged[unchangedIndex++] = originalIndex++; unchanged[unchangedIndex++] = originalIndex++;
/* Fill in unchanged items. */ /* Fill in unchanged items. */
for (ii = skeletonData->slotsCount - 1; ii >= 0; ii--) for (ii = skeletonData->slotsCount - 1; ii >= 0; ii--)
if (currDrawOrder[ii] == -1) currDrawOrder[ii] = unchanged[--unchangedIndex]; if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex];
FREE(unchanged); FREE(unchanged);
} }
spDrawOrderTimeline_setFrame(timeline, i, Json_getFloat(frame, "time", 0), currDrawOrder); spDrawOrderTimeline_setFrame(timeline, i, Json_getFloat(frame, "time", 0), drawOrder);
FREE(currDrawOrder); FREE(drawOrder);
} }
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline); animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
duration = timeline->frames[drawOrder->size - 1]; duration = timeline->frames[drawOrder->size - 1];
@ -376,24 +376,24 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
/* Event timeline. */ /* Event timeline. */
if (events) { if (events) {
Json* currFrame; Json* frame;
spEventTimeline* timeline = spEventTimeline_create(events->size); spEventTimeline* timeline = spEventTimeline_create(events->size);
for (currFrame = events->child, i = 0; currFrame; currFrame = currFrame->next, ++i) { for (frame = events->child, i = 0; frame; frame = frame->next, ++i) {
spEvent* event; spEvent* event;
const char* stringValue; const char* stringValue;
spEventData* eventData = spSkeletonData_findEvent(skeletonData, Json_getString(currFrame, "name", 0)); spEventData* eventData = spSkeletonData_findEvent(skeletonData, Json_getString(frame, "name", 0));
if (!eventData) { if (!eventData) {
spAnimation_dispose(animation); spAnimation_dispose(animation);
_spSkeletonJson_setError(self, 0, "Event not found: ", Json_getString(currFrame, "name", 0)); _spSkeletonJson_setError(self, 0, "Event not found: ", Json_getString(frame, "name", 0));
return 0; return 0;
} }
event = spEvent_create(eventData); event = spEvent_create(eventData);
event->intValue = Json_getInt(currFrame, "int", eventData->intValue); event->intValue = Json_getInt(frame, "int", eventData->intValue);
event->floatValue = Json_getFloat(currFrame, "float", eventData->floatValue); event->floatValue = Json_getFloat(frame, "float", eventData->floatValue);
stringValue = Json_getString(currFrame, "string", eventData->stringValue); stringValue = Json_getString(frame, "string", eventData->stringValue);
if (stringValue) MALLOC_STR(event->stringValue, stringValue); if (stringValue) MALLOC_STR(event->stringValue, stringValue);
spEventTimeline_setFrame(timeline, i, Json_getFloat(currFrame, "time", 0), event); spEventTimeline_setFrame(timeline, i, Json_getFloat(frame, "time", 0), event);
} }
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline); animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
duration = timeline->frames[events->size - 1]; duration = timeline->frames[events->size - 1];
@ -571,7 +571,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
const char* attachmentName = Json_getString(attachmentMap, "name", skinAttachmentName); const char* attachmentName = Json_getString(attachmentMap, "name", skinAttachmentName);
const char* path = Json_getString(attachmentMap, "path", attachmentName); const char* path = Json_getString(attachmentMap, "path", attachmentName);
const char* color; const char* color;
int currIndex; int i;
Json* entry; Json* entry;
const char* typeString = Json_getString(attachmentMap, "type", "region"); const char* typeString = Json_getString(attachmentMap, "type", "region");
@ -631,19 +631,19 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
entry = Json_getItem(attachmentMap, "vertices"); entry = Json_getItem(attachmentMap, "vertices");
mesh->verticesCount = entry->size; mesh->verticesCount = entry->size;
mesh->vertices = MALLOC(float, entry->size); mesh->vertices = MALLOC(float, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
mesh->vertices[currIndex] = entry->valueFloat * self->scale; mesh->vertices[i] = entry->valueFloat * self->scale;
entry = Json_getItem(attachmentMap, "triangles"); entry = Json_getItem(attachmentMap, "triangles");
mesh->trianglesCount = entry->size; mesh->trianglesCount = entry->size;
mesh->triangles = MALLOC(int, entry->size); mesh->triangles = MALLOC(int, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
mesh->triangles[currIndex] = entry->valueInt; mesh->triangles[i] = entry->valueInt;
entry = Json_getItem(attachmentMap, "uvs"); entry = Json_getItem(attachmentMap, "uvs");
mesh->regionUVs = MALLOC(float, entry->size); mesh->regionUVs = MALLOC(float, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
mesh->regionUVs[currIndex] = entry->valueFloat; mesh->regionUVs[i] = entry->valueFloat;
spMeshAttachment_updateUVs(mesh); spMeshAttachment_updateUVs(mesh);
@ -661,8 +661,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
if (entry) { if (entry) {
mesh->edgesCount = entry->size; mesh->edgesCount = entry->size;
mesh->edges = MALLOC(int, entry->size); mesh->edges = MALLOC(int, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
mesh->edges[currIndex] = entry->valueInt; mesh->edges[i] = entry->valueInt;
} }
mesh->width = Json_getFloat(attachmentMap, "width", 32) * self->scale; mesh->width = Json_getFloat(attachmentMap, "width", 32) * self->scale;
@ -679,32 +679,32 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
entry = Json_getItem(attachmentMap, "uvs"); entry = Json_getItem(attachmentMap, "uvs");
mesh->uvsCount = entry->size; mesh->uvsCount = entry->size;
mesh->regionUVs = MALLOC(float, entry->size); mesh->regionUVs = MALLOC(float, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
mesh->regionUVs[currIndex] = entry->valueFloat; mesh->regionUVs[i] = entry->valueFloat;
entry = Json_getItem(attachmentMap, "vertices"); entry = Json_getItem(attachmentMap, "vertices");
verticesCount = entry->size; verticesCount = entry->size;
vertices = MALLOC(float, entry->size); vertices = MALLOC(float, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
vertices[currIndex] = entry->valueFloat; vertices[i] = entry->valueFloat;
for (currIndex = 0; currIndex < verticesCount;) { for (i = 0; i < verticesCount;) {
int bonesCount = (int)vertices[currIndex]; int bonesCount = (int)vertices[i];
mesh->bonesCount += bonesCount + 1; mesh->bonesCount += bonesCount + 1;
mesh->weightsCount += bonesCount * 3; mesh->weightsCount += bonesCount * 3;
currIndex += 1 + bonesCount * 4; i += 1 + bonesCount * 4;
} }
mesh->bones = MALLOC(int, mesh->bonesCount); mesh->bones = MALLOC(int, mesh->bonesCount);
mesh->weights = MALLOC(float, mesh->weightsCount); mesh->weights = MALLOC(float, mesh->weightsCount);
for (currIndex = 0, b = 0, w = 0; currIndex < verticesCount;) { for (i = 0, b = 0, w = 0; i < verticesCount;) {
int bonesCount = (int)vertices[currIndex++]; int bonesCount = (int)vertices[i++];
mesh->bones[b++] = bonesCount; mesh->bones[b++] = bonesCount;
for (nn = currIndex + bonesCount * 4; currIndex < nn; currIndex += 4, ++b, w += 3) { for (nn = i + bonesCount * 4; i < nn; i += 4, ++b, w += 3) {
mesh->bones[b] = (int)vertices[currIndex]; mesh->bones[b] = (int)vertices[i];
mesh->weights[w] = vertices[currIndex + 1] * self->scale; mesh->weights[w] = vertices[i + 1] * self->scale;
mesh->weights[w + 1] = vertices[currIndex + 2] * self->scale; mesh->weights[w + 1] = vertices[i + 2] * self->scale;
mesh->weights[w + 2] = vertices[currIndex + 3]; mesh->weights[w + 2] = vertices[i + 3];
} }
} }
@ -713,8 +713,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
entry = Json_getItem(attachmentMap, "triangles"); entry = Json_getItem(attachmentMap, "triangles");
mesh->trianglesCount = entry->size; mesh->trianglesCount = entry->size;
mesh->triangles = MALLOC(int, entry->size); mesh->triangles = MALLOC(int, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
mesh->triangles[currIndex] = entry->valueInt; mesh->triangles[i] = entry->valueInt;
spSkinnedMeshAttachment_updateUVs(mesh); spSkinnedMeshAttachment_updateUVs(mesh);
@ -732,7 +732,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
if (entry) { if (entry) {
mesh->edgesCount = entry->size; mesh->edgesCount = entry->size;
mesh->edges = MALLOC(int, entry->size); mesh->edges = MALLOC(int, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
mesh->edges[i] = entry->valueInt; mesh->edges[i] = entry->valueInt;
} }
@ -745,8 +745,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
entry = Json_getItem(attachmentMap, "vertices"); entry = Json_getItem(attachmentMap, "vertices");
box->verticesCount = entry->size; box->verticesCount = entry->size;
box->vertices = MALLOC(float, entry->size); box->vertices = MALLOC(float, entry->size);
for (entry = entry->child, currIndex = 0; entry; entry = entry->next, ++currIndex) for (entry = entry->child, i = 0; entry; entry = entry->next, ++i)
box->vertices[currIndex] = entry->valueFloat * self->scale; box->vertices[i] = entry->valueFloat * self->scale;
break; break;
} }
} }

View File

@ -48,7 +48,7 @@ void _spAtlasPage_disposeTexture (spAtlasPage* self) {
char* _spUtil_readFile (const char* path, int* length) { char* _spUtil_readFile (const char* path, int* length) {
Data data = FileUtils::getInstance()->getDataFromFile( Data data = FileUtils::getInstance()->getDataFromFile(
FileUtils::getInstance()->fullPathForFilename(path).c_str()); FileUtils::getInstance()->fullPathForFilename(path).c_str());
*length = (int) data.getSize(); *length = data.getSize();
char* bytes = MALLOC(char, *length); char* bytes = MALLOC(char, *length);
memcpy(bytes, data.getBytes(), *length); memcpy(bytes, data.getBytes(), *length);
return bytes; return bytes;