mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[cpp] Store timeline ids inside set in Animation for O(1) lookup. See #1462.
This commit is contained in:
parent
3821389cd7
commit
caf1bd5b9a
@ -31,6 +31,7 @@
|
|||||||
#define Spine_Animation_h
|
#define Spine_Animation_h
|
||||||
|
|
||||||
#include <spine/Vector.h>
|
#include <spine/Vector.h>
|
||||||
|
#include <spine/HashMap.h>
|
||||||
#include <spine/MixBlend.h>
|
#include <spine/MixBlend.h>
|
||||||
#include <spine/MixDirection.h>
|
#include <spine/MixDirection.h>
|
||||||
#include <spine/SpineObject.h>
|
#include <spine/SpineObject.h>
|
||||||
@ -94,6 +95,8 @@ public:
|
|||||||
|
|
||||||
Vector<Timeline *> &getTimelines();
|
Vector<Timeline *> &getTimelines();
|
||||||
|
|
||||||
|
bool hasTimeline(int id);
|
||||||
|
|
||||||
float getDuration();
|
float getDuration();
|
||||||
|
|
||||||
void setDuration(float inValue);
|
void setDuration(float inValue);
|
||||||
@ -102,6 +105,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Timeline *> _timelines;
|
Vector<Timeline *> _timelines;
|
||||||
|
HashMap<int, bool> _timelineIds;
|
||||||
float _duration;
|
float _duration;
|
||||||
String _name;
|
String _name;
|
||||||
|
|
||||||
|
|||||||
@ -429,8 +429,6 @@ namespace spine {
|
|||||||
void computeHold(TrackEntry *entry);
|
void computeHold(TrackEntry *entry);
|
||||||
|
|
||||||
void computeNotLast(TrackEntry *entry);
|
void computeNotLast(TrackEntry *entry);
|
||||||
|
|
||||||
bool hasTimeline(TrackEntry *entry, int inId);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,9 +44,16 @@ using namespace spine;
|
|||||||
|
|
||||||
Animation::Animation(const String &name, Vector<Timeline *> &timelines, float duration) :
|
Animation::Animation(const String &name, Vector<Timeline *> &timelines, float duration) :
|
||||||
_timelines(timelines),
|
_timelines(timelines),
|
||||||
|
_timelineIds(),
|
||||||
_duration(duration),
|
_duration(duration),
|
||||||
_name(name) {
|
_name(name) {
|
||||||
assert(_name.length() > 0);
|
assert(_name.length() > 0);
|
||||||
|
for (int i = 0; i < (int)timelines.size(); i++)
|
||||||
|
_timelineIds.put(timelines[i]->getPropertyId(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Animation::hasTimeline(int id) {
|
||||||
|
return _timelineIds.containsKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation::~Animation() {
|
Animation::~Animation() {
|
||||||
|
|||||||
@ -995,11 +995,11 @@ void AnimationState::computeHold(TrackEntry *entry) {
|
|||||||
|
|
||||||
if (to == NULL || timeline->getRTTI().isExactly(AttachmentTimeline::rtti) ||
|
if (to == NULL || timeline->getRTTI().isExactly(AttachmentTimeline::rtti) ||
|
||||||
timeline->getRTTI().isExactly(DrawOrderTimeline::rtti) ||
|
timeline->getRTTI().isExactly(DrawOrderTimeline::rtti) ||
|
||||||
timeline->getRTTI().isExactly(EventTimeline::rtti) || !hasTimeline(to, id)) {
|
timeline->getRTTI().isExactly(EventTimeline::rtti) || !to->_animation->hasTimeline(id)) {
|
||||||
timelineMode[i] = First;
|
timelineMode[i] = First;
|
||||||
} else {
|
} else {
|
||||||
for (TrackEntry *next = to->_mixingTo; next != NULL; next = next->_mixingTo) {
|
for (TrackEntry *next = to->_mixingTo; next != NULL; next = next->_mixingTo) {
|
||||||
if (hasTimeline(next, id)) continue;
|
if (next->_animation->hasTimeline(id)) continue;
|
||||||
if (entry->_mixDuration > 0) {
|
if (entry->_mixDuration > 0) {
|
||||||
timelineMode[i] = HoldMix;
|
timelineMode[i] = HoldMix;
|
||||||
timelineHoldMix[i] = entry;
|
timelineHoldMix[i] = entry;
|
||||||
@ -1029,10 +1029,3 @@ void AnimationState::computeNotLast(TrackEntry *entry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnimationState::hasTimeline(TrackEntry* entry, int inId) {
|
|
||||||
Vector<Timeline *> &timelines = entry->_animation->_timelines;
|
|
||||||
for (size_t i = 0, n = timelines.size(); i < n; ++i)
|
|
||||||
if (timelines[i]->getPropertyId() == inId) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user