mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Compile with C89.
This commit is contained in:
parent
359b25d9d4
commit
f8401d954a
@ -55,9 +55,9 @@ Animation* Animation_create (const char* name, int timelineCount);
|
|||||||
void Animation_dispose (Animation* self);
|
void Animation_dispose (Animation* self);
|
||||||
|
|
||||||
void Animation_apply (const Animation* self, struct Skeleton* skeleton, float lastTime, float time, int loop,
|
void Animation_apply (const Animation* self, struct Skeleton* skeleton, float lastTime, float time, int loop,
|
||||||
Event**/*out*/events, int*/*out*/eventCount);
|
Event** events, int* eventCount);
|
||||||
void Animation_mix (const Animation* self, struct Skeleton* skeleton, float lastTime, float time, int loop, Event**/*out*/events,
|
void Animation_mix (const Animation* self, struct Skeleton* skeleton, float lastTime, float time, int loop, Event** events,
|
||||||
int*/*out*/eventCount, float alpha);
|
int* eventCount, float alpha);
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
|
|||||||
@ -52,5 +52,7 @@
|
|||||||
#include <spine/Skin.h>
|
#include <spine/Skin.h>
|
||||||
#include <spine/Slot.h>
|
#include <spine/Slot.h>
|
||||||
#include <spine/SlotData.h>
|
#include <spine/SlotData.h>
|
||||||
|
#include <spine/Event.h>
|
||||||
|
#include <spine/EventData.h>
|
||||||
|
|
||||||
#endif /* SPINE_SPINE_H_ */
|
#endif /* SPINE_SPINE_H_ */
|
||||||
|
|||||||
@ -524,15 +524,16 @@ void _EventTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float l
|
|||||||
|
|
||||||
if (lastTime > time) {
|
if (lastTime > time) {
|
||||||
/* Fire events after last time for looped animations. */
|
/* Fire events after last time for looped animations. */
|
||||||
_EventTimeline_apply(timeline, skeleton, lastTime, INT_MAX, firedEvents, eventCount, alpha);
|
_EventTimeline_apply(timeline, skeleton, lastTime, (float)INT_MAX, firedEvents, eventCount, alpha);
|
||||||
lastTime = 0;
|
lastTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->framesLength == 1)
|
if (self->framesLength == 1)
|
||||||
frameIndex = 0;
|
frameIndex = 0;
|
||||||
else {
|
else {
|
||||||
|
float frame;
|
||||||
frameIndex = binarySearch(self->frames, self->framesLength, lastTime, 1);
|
frameIndex = binarySearch(self->frames, self->framesLength, lastTime, 1);
|
||||||
float frame = self->frames[frameIndex];
|
frame = self->frames[frameIndex];
|
||||||
while (frameIndex > 0) {
|
while (frameIndex > 0) {
|
||||||
float lastFrame = self->frames[frameIndex - 1];
|
float lastFrame = self->frames[frameIndex - 1];
|
||||||
/* Fire multiple events with the same frame and events that occurred at lastTime. */
|
/* Fire multiple events with the same frame and events that occurred at lastTime. */
|
||||||
|
|||||||
@ -69,9 +69,8 @@ void _AnimationState_setCurrent (AnimationState* self, int index, TrackEntry* en
|
|||||||
|
|
||||||
AnimationState* AnimationState_create (AnimationStateData* data) {
|
AnimationState* AnimationState_create (AnimationStateData* data) {
|
||||||
_AnimationState* internal = NEW(_AnimationState);
|
_AnimationState* internal = NEW(_AnimationState);
|
||||||
internal->events = MALLOC(Event*, 64);
|
|
||||||
|
|
||||||
AnimationState* self = SUPER(internal);
|
AnimationState* self = SUPER(internal);
|
||||||
|
internal->events = MALLOC(Event*, 64);
|
||||||
CONST_CAST(AnimationStateData*, self->data) = data;
|
CONST_CAST(AnimationStateData*, self->data) = data;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -85,12 +84,13 @@ void AnimationState_dispose (AnimationState* self) {
|
|||||||
|
|
||||||
void AnimationState_update (AnimationState* self, float delta) {
|
void AnimationState_update (AnimationState* self, float delta) {
|
||||||
int i;
|
int i;
|
||||||
|
float time, endTime;
|
||||||
for (i = 0; i < self->trackCount; i++) {
|
for (i = 0; i < self->trackCount; i++) {
|
||||||
TrackEntry* current = self->tracks[i];
|
TrackEntry* current = self->tracks[i];
|
||||||
if (!current) continue;
|
if (!current) continue;
|
||||||
|
|
||||||
float time = current->time + delta;
|
time = current->time + delta;
|
||||||
float endTime = current->endTime;
|
endTime = current->endTime;
|
||||||
|
|
||||||
current->time = time;
|
current->time = time;
|
||||||
if (current->previous) {
|
if (current->previous) {
|
||||||
@ -106,10 +106,9 @@ void AnimationState_update (AnimationState* self, float delta) {
|
|||||||
if (self->listener) self->listener(self, i, ANIMATION_COMPLETE, 0, count);
|
if (self->listener) self->listener(self, i, ANIMATION_COMPLETE, 0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackEntry* next = current->next;
|
if (current->next && time >= current->next->delay) {
|
||||||
if (next && time >= next->delay) {
|
if (current->next->animation)
|
||||||
if (next->animation)
|
_AnimationState_setCurrent(self, i, current->next);
|
||||||
_AnimationState_setCurrent(self, i, next);
|
|
||||||
else
|
else
|
||||||
AnimationState_clearTrack(self, i);
|
AnimationState_clearTrack(self, i);
|
||||||
}
|
}
|
||||||
@ -120,19 +119,20 @@ void AnimationState_apply (AnimationState* self, Skeleton* skeleton) {
|
|||||||
|
|
||||||
int i, ii;
|
int i, ii;
|
||||||
int eventCount;
|
int eventCount;
|
||||||
|
TrackEntry* previous;
|
||||||
for (i = 0; i < self->trackCount; i++) {
|
for (i = 0; i < self->trackCount; i++) {
|
||||||
TrackEntry* current = self->tracks[i];
|
TrackEntry* current = self->tracks[i];
|
||||||
if (!current) continue;
|
if (!current) continue;
|
||||||
|
|
||||||
eventCount = 0;
|
eventCount = 0;
|
||||||
|
|
||||||
TrackEntry* previous = current->previous;
|
previous = current->previous;
|
||||||
if (!previous) {
|
if (!previous) {
|
||||||
Animation_apply(current->animation, skeleton, current->lastTime, current->time, current->loop, internal->events,
|
Animation_apply(current->animation, skeleton, current->lastTime, current->time, current->loop, internal->events,
|
||||||
&eventCount);
|
&eventCount);
|
||||||
} else {
|
} else {
|
||||||
Animation_apply(previous->animation, skeleton, INT_MAX, previous->time, previous->loop, internal->events, &eventCount);
|
|
||||||
float alpha = current->mixTime / current->mixDuration;
|
float alpha = current->mixTime / current->mixDuration;
|
||||||
|
Animation_apply(previous->animation, skeleton, (float)INT_MAX, previous->time, previous->loop, internal->events, &eventCount);
|
||||||
if (alpha >= 1) {
|
if (alpha >= 1) {
|
||||||
alpha = 1;
|
alpha = 1;
|
||||||
_TrackEntry_dispose(current->previous);
|
_TrackEntry_dispose(current->previous);
|
||||||
@ -160,8 +160,9 @@ void AnimationState_clear (AnimationState* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AnimationState_clearTrack (AnimationState* self, int trackIndex) {
|
void AnimationState_clearTrack (AnimationState* self, int trackIndex) {
|
||||||
|
TrackEntry* current;
|
||||||
if (trackIndex >= self->trackCount) return;
|
if (trackIndex >= self->trackCount) return;
|
||||||
TrackEntry* current = self->tracks[trackIndex];
|
current = self->tracks[trackIndex];
|
||||||
if (!current) return;
|
if (!current) return;
|
||||||
|
|
||||||
if (current->listener) current->listener(self, trackIndex, ANIMATION_END, 0, 0);
|
if (current->listener) current->listener(self, trackIndex, ANIMATION_END, 0, 0);
|
||||||
@ -173,14 +174,17 @@ void AnimationState_clearTrack (AnimationState* self, int trackIndex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TrackEntry* _AnimationState_expandToIndex (AnimationState* self, int index) {
|
TrackEntry* _AnimationState_expandToIndex (AnimationState* self, int index) {
|
||||||
|
TrackEntry** newTracks;
|
||||||
if (index < self->trackCount) return self->tracks[index];
|
if (index < self->trackCount) return self->tracks[index];
|
||||||
TrackEntry** newTracks = CALLOC(TrackEntry*, index + 1);
|
newTracks = CALLOC(TrackEntry*, index + 1);
|
||||||
memcpy(newTracks, self->tracks, self->trackCount * sizeof(TrackEntry*));
|
memcpy(newTracks, self->tracks, self->trackCount * sizeof(TrackEntry*));
|
||||||
self->tracks = newTracks;
|
self->tracks = newTracks;
|
||||||
self->trackCount = index + 1;
|
self->trackCount = index + 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void _AnimationState_setCurrent (AnimationState* self, int index, TrackEntry* entry) {
|
void _AnimationState_setCurrent (AnimationState* self, int index, TrackEntry* entry) {
|
||||||
TrackEntry* current = _AnimationState_expandToIndex(self, index);
|
TrackEntry* current = _AnimationState_expandToIndex(self, index);
|
||||||
if (current) {
|
if (current) {
|
||||||
@ -193,6 +197,7 @@ void _AnimationState_setCurrent (AnimationState* self, int index, TrackEntry* en
|
|||||||
if (self->listener) self->listener(self, index, ANIMATION_END, 0, 0);
|
if (self->listener) self->listener(self, index, ANIMATION_END, 0, 0);
|
||||||
|
|
||||||
entry->mixDuration = AnimationStateData_getMix(self->data, current->animation, entry->animation);
|
entry->mixDuration = AnimationStateData_getMix(self->data, current->animation, entry->animation);
|
||||||
|
printf("mix %f\n", entry->mixDuration);
|
||||||
if (entry->mixDuration > 0) {
|
if (entry->mixDuration > 0) {
|
||||||
entry->mixTime = 0;
|
entry->mixTime = 0;
|
||||||
entry->previous = current;
|
entry->previous = current;
|
||||||
@ -212,10 +217,11 @@ TrackEntry* AnimationState_setAnimationByName (AnimationState* self, int trackIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
TrackEntry* AnimationState_setAnimation (AnimationState* self, int trackIndex, Animation* animation, int/*bool*/loop) {
|
TrackEntry* AnimationState_setAnimation (AnimationState* self, int trackIndex, Animation* animation, int/*bool*/loop) {
|
||||||
|
TrackEntry* entry;
|
||||||
TrackEntry* current = _AnimationState_expandToIndex(self, trackIndex);
|
TrackEntry* current = _AnimationState_expandToIndex(self, trackIndex);
|
||||||
if (current) _TrackEntry_disposeAll(current->next);
|
if (current) _TrackEntry_disposeAll(current->next);
|
||||||
|
|
||||||
TrackEntry* entry = _TrackEntry_create();
|
entry = _TrackEntry_create();
|
||||||
entry->animation = animation;
|
entry->animation = animation;
|
||||||
entry->loop = loop;
|
entry->loop = loop;
|
||||||
entry->time = 0;
|
entry->time = 0;
|
||||||
@ -231,13 +237,15 @@ TrackEntry* AnimationState_addAnimationByName (AnimationState* self, int trackIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
TrackEntry* AnimationState_addAnimation (AnimationState* self, int trackIndex, Animation* animation, int/*bool*/loop, float delay) {
|
TrackEntry* AnimationState_addAnimation (AnimationState* self, int trackIndex, Animation* animation, int/*bool*/loop, float delay) {
|
||||||
|
TrackEntry* last;
|
||||||
|
|
||||||
TrackEntry* entry = _TrackEntry_create();
|
TrackEntry* entry = _TrackEntry_create();
|
||||||
entry->animation = animation;
|
entry->animation = animation;
|
||||||
entry->loop = loop;
|
entry->loop = loop;
|
||||||
entry->time = 0;
|
entry->time = 0;
|
||||||
entry->endTime = animation ? animation->duration : 0;
|
entry->endTime = animation ? animation->duration : 0;
|
||||||
|
|
||||||
TrackEntry* last = _AnimationState_expandToIndex(self, trackIndex);
|
last = _AnimationState_expandToIndex(self, trackIndex);
|
||||||
if (last) {
|
if (last) {
|
||||||
while (last->next)
|
while (last->next)
|
||||||
last = last->next;
|
last = last->next;
|
||||||
|
|||||||
@ -230,16 +230,18 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
|
|||||||
|
|
||||||
EventTimeline* timeline = EventTimeline_create(events->size);
|
EventTimeline* timeline = EventTimeline_create(events->size);
|
||||||
for (frame = events->child, i = 0; frame; frame = frame->next, ++i) {
|
for (frame = events->child, i = 0; frame; frame = frame->next, ++i) {
|
||||||
|
Event* event;
|
||||||
|
const char* stringValue;
|
||||||
EventData* eventData = SkeletonData_findEvent(skeletonData, Json_getString(frame, "name", 0));
|
EventData* eventData = SkeletonData_findEvent(skeletonData, Json_getString(frame, "name", 0));
|
||||||
if (!eventData) {
|
if (!eventData) {
|
||||||
Animation_dispose(animation);
|
Animation_dispose(animation);
|
||||||
_SkeletonJson_setError(self, 0, "Event not found: ", Json_getString(frame, "name", 0));
|
_SkeletonJson_setError(self, 0, "Event not found: ", Json_getString(frame, "name", 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Event* event = Event_create(eventData);
|
event = Event_create(eventData);
|
||||||
event->intValue = Json_getInt(frame, "int", eventData->intValue);
|
event->intValue = Json_getInt(frame, "int", eventData->intValue);
|
||||||
event->floatValue = Json_getFloat(frame, "float", eventData->floatValue);
|
event->floatValue = Json_getFloat(frame, "float", eventData->floatValue);
|
||||||
const char* stringValue = Json_getString(frame, "string", eventData->stringValue);
|
stringValue = Json_getString(frame, "string", eventData->stringValue);
|
||||||
if (stringValue) MALLOC_STR(event->stringValue, stringValue);
|
if (stringValue) MALLOC_STR(event->stringValue, stringValue);
|
||||||
EventTimeline_setFrame(timeline, i, Json_getFloat(frame, "time", 0), event);
|
EventTimeline_setFrame(timeline, i, Json_getFloat(frame, "time", 0), event);
|
||||||
}
|
}
|
||||||
@ -477,12 +479,13 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
|
|||||||
events = Json_getItem(root, "events");
|
events = Json_getItem(root, "events");
|
||||||
if (events) {
|
if (events) {
|
||||||
Json *eventMap;
|
Json *eventMap;
|
||||||
|
const char* stringValue;
|
||||||
skeletonData->events = MALLOC(EventData*, events->size);
|
skeletonData->events = MALLOC(EventData*, events->size);
|
||||||
for (eventMap = events->child; eventMap; eventMap = eventMap->next) {
|
for (eventMap = events->child; eventMap; eventMap = eventMap->next) {
|
||||||
EventData* eventData = EventData_create(eventMap->name);
|
EventData* eventData = EventData_create(eventMap->name);
|
||||||
eventData->intValue = Json_getInt(eventMap, "int", 0);
|
eventData->intValue = Json_getInt(eventMap, "int", 0);
|
||||||
eventData->floatValue = Json_getFloat(eventMap, "float", 0);
|
eventData->floatValue = Json_getFloat(eventMap, "float", 0);
|
||||||
const char* stringValue = Json_getString(eventMap, "string", 0);
|
stringValue = Json_getString(eventMap, "string", 0);
|
||||||
if (stringValue) MALLOC_STR(eventData->stringValue, stringValue);
|
if (stringValue) MALLOC_STR(eventData->stringValue, stringValue);
|
||||||
skeletonData->events[skeletonData->eventCount++] = eventData;
|
skeletonData->events[skeletonData->eventCount++] = eventData;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user