mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[cpp] Making the callbacks also object oriented
This commit is contained in:
parent
930d4b4015
commit
4542dc9a82
@ -58,6 +58,17 @@ namespace spine {
|
|||||||
class RotateTimeline;
|
class RotateTimeline;
|
||||||
|
|
||||||
typedef void (*AnimationStateListener) (AnimationState* state, EventType type, TrackEntry* entry, Event* event);
|
typedef void (*AnimationStateListener) (AnimationState* state, EventType type, TrackEntry* entry, Event* event);
|
||||||
|
|
||||||
|
/// Abstract class to inherit from to create a callback object
|
||||||
|
class SP_API AnimationStateListenerClass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AnimationStateListenerClass() = default;
|
||||||
|
virtual ~AnimationStateListenerClass() = default;
|
||||||
|
public:
|
||||||
|
/// The callback function to be called
|
||||||
|
virtual void callback(AnimationState* state, EventType type, TrackEntry* entry, Event* event) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/// State for the playback of an animation
|
/// State for the playback of an animation
|
||||||
class SP_API TrackEntry : public SpineObject, public HasRendererObject {
|
class SP_API TrackEntry : public SpineObject, public HasRendererObject {
|
||||||
@ -241,6 +252,8 @@ namespace spine {
|
|||||||
|
|
||||||
void setListener(AnimationStateListener listener);
|
void setListener(AnimationStateListener listener);
|
||||||
|
|
||||||
|
void setListener(AnimationStateListenerClass* listener);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Animation* _animation;
|
Animation* _animation;
|
||||||
|
|
||||||
@ -259,6 +272,7 @@ namespace spine {
|
|||||||
Vector<TrackEntry*> _timelineHoldMix;
|
Vector<TrackEntry*> _timelineHoldMix;
|
||||||
Vector<float> _timelinesRotation;
|
Vector<float> _timelinesRotation;
|
||||||
AnimationStateListener _listener;
|
AnimationStateListener _listener;
|
||||||
|
AnimationStateListenerClass* _listenerObj;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
};
|
};
|
||||||
@ -396,6 +410,7 @@ namespace spine {
|
|||||||
void setTimeScale(float inValue);
|
void setTimeScale(float inValue);
|
||||||
|
|
||||||
void setListener(AnimationStateListener listener);
|
void setListener(AnimationStateListener listener);
|
||||||
|
void setListener(AnimationStateListenerClass* listener);
|
||||||
|
|
||||||
void disableQueue();
|
void disableQueue();
|
||||||
void enableQueue();
|
void enableQueue();
|
||||||
@ -413,6 +428,7 @@ namespace spine {
|
|||||||
bool _animationsChanged;
|
bool _animationsChanged;
|
||||||
|
|
||||||
AnimationStateListener _listener;
|
AnimationStateListener _listener;
|
||||||
|
AnimationStateListenerClass* _listenerObj;
|
||||||
|
|
||||||
float _timeScale;
|
float _timeScale;
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,7 @@ TrackEntry::TrackEntry() : _animation(NULL), _next(NULL), _mixingFrom(NULL), _mi
|
|||||||
_animationEnd(0), _animationLast(0), _nextAnimationLast(0), _delay(0), _trackTime(0),
|
_animationEnd(0), _animationLast(0), _nextAnimationLast(0), _delay(0), _trackTime(0),
|
||||||
_trackLast(0), _nextTrackLast(0), _trackEnd(0), _timeScale(1.0f), _alpha(0), _mixTime(0),
|
_trackLast(0), _nextTrackLast(0), _trackEnd(0), _timeScale(1.0f), _alpha(0), _mixTime(0),
|
||||||
_mixDuration(0), _interruptAlpha(0), _totalAlpha(0), _mixBlend(MixBlend_Replace),
|
_mixDuration(0), _interruptAlpha(0), _totalAlpha(0), _mixBlend(MixBlend_Replace),
|
||||||
_listener(dummyOnAnimationEventFunc) {
|
_listener(dummyOnAnimationEventFunc), _listenerObj(NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackEntry::~TrackEntry() { }
|
TrackEntry::~TrackEntry() { }
|
||||||
@ -165,17 +165,24 @@ void TrackEntry::setListener(AnimationStateListener inValue) {
|
|||||||
_listener = inValue;
|
_listener = inValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackEntry::setListener(AnimationStateListenerClass* inValue) {
|
||||||
|
_listenerObj = inValue;
|
||||||
|
}
|
||||||
|
|
||||||
void TrackEntry::reset() {
|
void TrackEntry::reset() {
|
||||||
_animation = NULL;
|
_animation = NULL;
|
||||||
_next = NULL;
|
_next = NULL;
|
||||||
_mixingFrom = NULL;
|
_mixingFrom = NULL;
|
||||||
_mixingTo = NULL;
|
_mixingTo = NULL;
|
||||||
|
|
||||||
|
setRendererObject(NULL);
|
||||||
|
|
||||||
_timelineMode.clear();
|
_timelineMode.clear();
|
||||||
_timelineHoldMix.clear();
|
_timelineHoldMix.clear();
|
||||||
_timelinesRotation.clear();
|
_timelinesRotation.clear();
|
||||||
|
|
||||||
_listener = dummyOnAnimationEventFunc;
|
_listener = dummyOnAnimationEventFunc;
|
||||||
|
_listenerObj = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Event *event) :
|
EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Event *event) :
|
||||||
@ -245,22 +252,48 @@ void EventQueue::drain() {
|
|||||||
case EventType_Start:
|
case EventType_Start:
|
||||||
case EventType_Interrupt:
|
case EventType_Interrupt:
|
||||||
case EventType_Complete:
|
case EventType_Complete:
|
||||||
trackEntry->_listener(&state, queueEntry->_type, trackEntry, NULL);
|
if (NULL == trackEntry->_listener)
|
||||||
state._listener(&state, queueEntry->_type, trackEntry, NULL);
|
trackEntry->_listener(&state, queueEntry->_type, trackEntry, NULL);
|
||||||
|
else
|
||||||
|
trackEntry->_listenerObj->callback(&state, queueEntry->_type, trackEntry, NULL);
|
||||||
|
if (NULL == state._listenerObj)
|
||||||
|
state._listener(&state, queueEntry->_type, trackEntry, NULL);
|
||||||
|
else
|
||||||
|
state._listenerObj->callback(&state, queueEntry->_type, trackEntry, NULL);
|
||||||
break;
|
break;
|
||||||
case EventType_End:
|
case EventType_End:
|
||||||
trackEntry->_listener(&state, queueEntry->_type, trackEntry, NULL);
|
if (NULL == trackEntry->_listener)
|
||||||
state._listener(&state, queueEntry->_type, trackEntry, NULL);
|
trackEntry->_listener(&state, queueEntry->_type, trackEntry, NULL);
|
||||||
|
else
|
||||||
|
trackEntry->_listenerObj->callback(&state, queueEntry->_type, trackEntry, NULL);
|
||||||
|
if (NULL == state._listenerObj)
|
||||||
|
state._listener(&state, queueEntry->_type, trackEntry, NULL);
|
||||||
|
else
|
||||||
|
state._listenerObj->callback(&state, queueEntry->_type, trackEntry, NULL);
|
||||||
/* Yes, we want to fall through here */
|
/* Yes, we want to fall through here */
|
||||||
case EventType_Dispose:
|
case EventType_Dispose:
|
||||||
trackEntry->_listener(&state, EventType_Dispose, trackEntry, NULL);
|
|
||||||
state._listener(&state, EventType_Dispose, trackEntry, NULL);
|
if (NULL == trackEntry->_listener)
|
||||||
|
trackEntry->_listener(&state, EventType_Dispose, trackEntry, NULL);
|
||||||
|
else
|
||||||
|
trackEntry->_listenerObj->callback(&state, EventType_Dispose, trackEntry, NULL);
|
||||||
|
if (NULL == state._listenerObj)
|
||||||
|
state._listener(&state, EventType_Dispose, trackEntry, NULL);
|
||||||
|
else
|
||||||
|
state._listenerObj->callback(&state, EventType_Dispose, trackEntry, NULL);
|
||||||
|
|
||||||
trackEntry->reset();
|
trackEntry->reset();
|
||||||
_trackEntryPool.free(trackEntry);
|
_trackEntryPool.free(trackEntry);
|
||||||
break;
|
break;
|
||||||
case EventType_Event:
|
case EventType_Event:
|
||||||
trackEntry->_listener(&state, queueEntry->_type, trackEntry, queueEntry->_event);
|
if (NULL == trackEntry->_listener)
|
||||||
state._listener(&state, queueEntry->_type, trackEntry, queueEntry->_event);
|
trackEntry->_listener(&state, queueEntry->_type, trackEntry, queueEntry->_event);
|
||||||
|
else
|
||||||
|
trackEntry->_listenerObj->callback(&state, queueEntry->_type, trackEntry, queueEntry->_event);
|
||||||
|
if (NULL == state._listenerObj)
|
||||||
|
state._listener(&state, queueEntry->_type, trackEntry, queueEntry->_event);
|
||||||
|
else
|
||||||
|
state._listenerObj->callback(&state, queueEntry->_type, trackEntry, queueEntry->_event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,6 +312,7 @@ AnimationState::AnimationState(AnimationStateData *data) :
|
|||||||
_queue(EventQueue::newEventQueue(*this, _trackEntryPool)),
|
_queue(EventQueue::newEventQueue(*this, _trackEntryPool)),
|
||||||
_animationsChanged(false),
|
_animationsChanged(false),
|
||||||
_listener(dummyOnAnimationEventFunc),
|
_listener(dummyOnAnimationEventFunc),
|
||||||
|
_listenerObj(NULL),
|
||||||
_timeScale(1) {
|
_timeScale(1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,6 +650,10 @@ void AnimationState::setListener(AnimationStateListener inValue) {
|
|||||||
_listener = inValue;
|
_listener = inValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AnimationState::setListener(AnimationStateListenerClass* inValue) {
|
||||||
|
_listenerObj = inValue;
|
||||||
|
}
|
||||||
|
|
||||||
void AnimationState::disableQueue() {
|
void AnimationState::disableQueue() {
|
||||||
_queue->_drainDisabled = true;
|
_queue->_drainDisabled = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user