mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 02:06:03 +08:00
Make AnimationState TrackEntry create/dispose functions optional.
closes #218
This commit is contained in:
parent
7199d22417
commit
36809166a2
@ -87,8 +87,6 @@ extern "C" {
|
|||||||
void _spAtlasPage_createTexture (spAtlasPage* self, const char* path);
|
void _spAtlasPage_createTexture (spAtlasPage* self, const char* path);
|
||||||
void _spAtlasPage_disposeTexture (spAtlasPage* self);
|
void _spAtlasPage_disposeTexture (spAtlasPage* self);
|
||||||
char* _spUtil_readFile (const char* path, int* length);
|
char* _spUtil_readFile (const char* path, int* length);
|
||||||
spTrackEntry* _spAnimationState_createTrackEntry (spAnimationState* self);
|
|
||||||
void _spAnimationState_disposeTrackEntry (spAnimationState* self, spTrackEntry* entry);
|
|
||||||
|
|
||||||
#ifdef SPINE_SHORT_NAMES
|
#ifdef SPINE_SHORT_NAMES
|
||||||
#define _AtlasPage_createTexture(...) _spAtlasPage_createTexture(__VA_ARGS__)
|
#define _AtlasPage_createTexture(...) _spAtlasPage_createTexture(__VA_ARGS__)
|
||||||
@ -112,6 +110,14 @@ char* _readFile (const char* path, int* length);
|
|||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
spAnimationState super;
|
||||||
|
spEvent** events;
|
||||||
|
|
||||||
|
spTrackEntry* (*createTrackEntry) (spAnimationState* self);
|
||||||
|
void (*disposeTrackEntry) (spAnimationState* self, spTrackEntry* entry);
|
||||||
|
} _spAnimationState;
|
||||||
|
|
||||||
spTrackEntry* _spTrackEntry_create ();
|
spTrackEntry* _spTrackEntry_create ();
|
||||||
void _spTrackEntry_dispose (spTrackEntry* entry);
|
void _spTrackEntry_dispose (spTrackEntry* entry);
|
||||||
|
|
||||||
|
|||||||
@ -47,12 +47,13 @@ void _spTrackEntry_dispose (spTrackEntry* entry) {
|
|||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
typedef struct {
|
spTrackEntry* _spAnimationState_createTrackEntry (spAnimationState* self) {
|
||||||
spAnimationState super;
|
return _spTrackEntry_create();
|
||||||
spEvent** events;
|
}
|
||||||
} _spAnimationState;
|
|
||||||
|
|
||||||
void _spAnimationState_setCurrent (spAnimationState* self, int index, spTrackEntry* entry);
|
void _spAnimationState_disposeTrackEntry (spAnimationState* self, spTrackEntry* entry) {
|
||||||
|
_spTrackEntry_dispose(entry);
|
||||||
|
}
|
||||||
|
|
||||||
spAnimationState* spAnimationState_create (spAnimationStateData* data) {
|
spAnimationState* spAnimationState_create (spAnimationStateData* data) {
|
||||||
_spAnimationState* internal = NEW(_spAnimationState);
|
_spAnimationState* internal = NEW(_spAnimationState);
|
||||||
@ -60,13 +61,16 @@ spAnimationState* spAnimationState_create (spAnimationStateData* data) {
|
|||||||
internal->events = MALLOC(spEvent*, 64);
|
internal->events = MALLOC(spEvent*, 64);
|
||||||
self->timeScale = 1;
|
self->timeScale = 1;
|
||||||
CONST_CAST(spAnimationStateData*, self->data) = data;
|
CONST_CAST(spAnimationStateData*, self->data) = data;
|
||||||
|
internal->createTrackEntry = _spAnimationState_createTrackEntry;
|
||||||
|
internal->disposeTrackEntry = _spAnimationState_disposeTrackEntry;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _spAnimationState_disposeAllEntries (spAnimationState* self, spTrackEntry* entry) {
|
void _spAnimationState_disposeAllEntries (spAnimationState* self, spTrackEntry* entry) {
|
||||||
|
_spAnimationState* internal = SUB_CAST(_spAnimationState, self);
|
||||||
while (entry) {
|
while (entry) {
|
||||||
spTrackEntry* next = entry->next;
|
spTrackEntry* next = entry->next;
|
||||||
_spAnimationState_disposeTrackEntry(self, entry);
|
internal->disposeTrackEntry(self, entry);
|
||||||
entry = next;
|
entry = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,6 +85,8 @@ void spAnimationState_dispose (spAnimationState* self) {
|
|||||||
FREE(self);
|
FREE(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _spAnimationState_setCurrent (spAnimationState* self, int index, spTrackEntry* entry);
|
||||||
|
|
||||||
void spAnimationState_update (spAnimationState* self, float delta) {
|
void spAnimationState_update (spAnimationState* self, float delta) {
|
||||||
int i;
|
int i;
|
||||||
float previousDelta;
|
float previousDelta;
|
||||||
@ -140,7 +146,7 @@ void spAnimationState_apply (spAnimationState* self, spSkeleton* skeleton) {
|
|||||||
|
|
||||||
if (alpha >= 1) {
|
if (alpha >= 1) {
|
||||||
alpha = 1;
|
alpha = 1;
|
||||||
_spAnimationState_disposeTrackEntry(self, current->previous);
|
internal->disposeTrackEntry(self, current->previous);
|
||||||
current->previous = 0;
|
current->previous = 0;
|
||||||
}
|
}
|
||||||
spAnimation_mix(current->animation, skeleton, current->lastTime, time,
|
spAnimation_mix(current->animation, skeleton, current->lastTime, time,
|
||||||
@ -193,6 +199,8 @@ void spAnimationState_clearTracks (spAnimationState* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spAnimationState_clearTrack (spAnimationState* self, int trackIndex) {
|
void spAnimationState_clearTrack (spAnimationState* self, int trackIndex) {
|
||||||
|
_spAnimationState* internal = SUB_CAST(_spAnimationState, self);
|
||||||
|
|
||||||
spTrackEntry* current;
|
spTrackEntry* current;
|
||||||
if (trackIndex >= self->trackCount) return;
|
if (trackIndex >= self->trackCount) return;
|
||||||
current = self->tracks[trackIndex];
|
current = self->tracks[trackIndex];
|
||||||
@ -203,7 +211,7 @@ void spAnimationState_clearTrack (spAnimationState* self, int trackIndex) {
|
|||||||
|
|
||||||
self->tracks[trackIndex] = 0;
|
self->tracks[trackIndex] = 0;
|
||||||
|
|
||||||
if (current->previous) _spAnimationState_disposeTrackEntry(self, current->previous);
|
if (current->previous) internal->disposeTrackEntry(self, current->previous);
|
||||||
_spAnimationState_disposeAllEntries(self, current);
|
_spAnimationState_disposeAllEntries(self, current);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +227,8 @@ spTrackEntry* _spAnimationState_expandToIndex (spAnimationState* self, int index
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _spAnimationState_setCurrent (spAnimationState* self, int index, spTrackEntry* entry) {
|
void _spAnimationState_setCurrent (spAnimationState* self, int index, spTrackEntry* entry) {
|
||||||
|
_spAnimationState* internal = SUB_CAST(_spAnimationState, self);
|
||||||
|
|
||||||
spTrackEntry* current = _spAnimationState_expandToIndex(self, index);
|
spTrackEntry* current = _spAnimationState_expandToIndex(self, index);
|
||||||
if (current) {
|
if (current) {
|
||||||
spTrackEntry* previous = current->previous;
|
spTrackEntry* previous = current->previous;
|
||||||
@ -237,9 +247,9 @@ void _spAnimationState_setCurrent (spAnimationState* self, int index, spTrackEnt
|
|||||||
} else
|
} else
|
||||||
entry->previous = current;
|
entry->previous = current;
|
||||||
} else
|
} else
|
||||||
_spAnimationState_disposeTrackEntry(self, current);
|
internal->disposeTrackEntry(self, current);
|
||||||
|
|
||||||
if (previous) _spAnimationState_disposeTrackEntry(self, previous);
|
if (previous) internal->disposeTrackEntry(self, previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->tracks[index] = entry;
|
self->tracks[index] = entry;
|
||||||
@ -258,11 +268,13 @@ spTrackEntry* spAnimationState_setAnimationByName (spAnimationState* self, int t
|
|||||||
}
|
}
|
||||||
|
|
||||||
spTrackEntry* spAnimationState_setAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop) {
|
spTrackEntry* spAnimationState_setAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop) {
|
||||||
|
_spAnimationState* internal = SUB_CAST(_spAnimationState, self);
|
||||||
|
|
||||||
spTrackEntry* entry;
|
spTrackEntry* entry;
|
||||||
spTrackEntry* current = _spAnimationState_expandToIndex(self, trackIndex);
|
spTrackEntry* current = _spAnimationState_expandToIndex(self, trackIndex);
|
||||||
if (current) _spAnimationState_disposeAllEntries(self, current->next);
|
if (current) _spAnimationState_disposeAllEntries(self, current->next);
|
||||||
|
|
||||||
entry = _spAnimationState_createTrackEntry(self);
|
entry = internal->createTrackEntry(self);
|
||||||
entry->animation = animation;
|
entry->animation = animation;
|
||||||
entry->loop = loop;
|
entry->loop = loop;
|
||||||
entry->endTime = animation->duration;
|
entry->endTime = animation->duration;
|
||||||
@ -278,9 +290,10 @@ spTrackEntry* spAnimationState_addAnimationByName (spAnimationState* self, int t
|
|||||||
|
|
||||||
spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop,
|
spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop,
|
||||||
float delay) {
|
float delay) {
|
||||||
|
_spAnimationState* internal = SUB_CAST(_spAnimationState, self);
|
||||||
spTrackEntry* last;
|
spTrackEntry* last;
|
||||||
|
|
||||||
spTrackEntry* entry = _spAnimationState_createTrackEntry(self);
|
spTrackEntry* entry = internal->createTrackEntry(self);
|
||||||
entry->animation = animation;
|
entry->animation = animation;
|
||||||
entry->loop = loop;
|
entry->loop = loop;
|
||||||
entry->endTime = animation->duration;
|
entry->endTime = animation->duration;
|
||||||
|
|||||||
@ -40,14 +40,19 @@ using std::vector;
|
|||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
static void animationCallback (spAnimationState* state, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
void animationCallback (spAnimationState* state, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||||
((SkeletonAnimation*)state->rendererObject)->onAnimationStateEvent(trackIndex, type, event, loopCount);
|
((SkeletonAnimation*)state->rendererObject)->onAnimationStateEvent(trackIndex, type, event, loopCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void trackEntryCallback (spAnimationState* state, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
void trackEntryCallback (spAnimationState* state, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||||
((SkeletonAnimation*)state->rendererObject)->onTrackEntryEvent(trackIndex, type, event, loopCount);
|
((SkeletonAnimation*)state->rendererObject)->onTrackEntryEvent(trackIndex, type, event, loopCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void disposeTrackEntry (spAnimationState* self, spTrackEntry* entry) {
|
||||||
|
if (entry->rendererObject) FREE(entry->rendererObject);
|
||||||
|
_spTrackEntry_dispose(entry);
|
||||||
|
}
|
||||||
|
|
||||||
SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonData) {
|
SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonData) {
|
||||||
SkeletonAnimation* node = new SkeletonAnimation(skeletonData);
|
SkeletonAnimation* node = new SkeletonAnimation(skeletonData);
|
||||||
node->autorelease();
|
node->autorelease();
|
||||||
@ -71,6 +76,9 @@ void SkeletonAnimation::initialize () {
|
|||||||
state = spAnimationState_create(spAnimationStateData_create(skeleton->data));
|
state = spAnimationState_create(spAnimationStateData_create(skeleton->data));
|
||||||
state->rendererObject = this;
|
state->rendererObject = this;
|
||||||
state->listener = animationCallback;
|
state->listener = animationCallback;
|
||||||
|
|
||||||
|
_spAnimationState* stateInternal = (_spAnimationState*)state;
|
||||||
|
stateInternal->disposeTrackEntry = disposeTrackEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonAnimation::SkeletonAnimation (spSkeletonData *skeletonData)
|
SkeletonAnimation::SkeletonAnimation (spSkeletonData *skeletonData)
|
||||||
|
|||||||
@ -55,15 +55,6 @@ char* _spUtil_readFile (const char* path, int* length) {
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
spTrackEntry* _spAnimationState_createTrackEntry (spAnimationState* self) {
|
|
||||||
return _spTrackEntry_create();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _spAnimationState_disposeTrackEntry (spAnimationState* self, spTrackEntry* entry) {
|
|
||||||
if (entry->rendererObject) FREE(entry->rendererObject);
|
|
||||||
_spTrackEntry_dispose(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user