[cpp] Store timeline ids inside set in Animation for O(1) lookup. See #1462.

This commit is contained in:
badlogic 2019-09-26 16:50:47 +02:00
parent 3821389cd7
commit caf1bd5b9a
4 changed files with 13 additions and 11 deletions

View File

@ -31,6 +31,7 @@
#define Spine_Animation_h
#include <spine/Vector.h>
#include <spine/HashMap.h>
#include <spine/MixBlend.h>
#include <spine/MixDirection.h>
#include <spine/SpineObject.h>
@ -94,6 +95,8 @@ public:
Vector<Timeline *> &getTimelines();
bool hasTimeline(int id);
float getDuration();
void setDuration(float inValue);
@ -102,6 +105,7 @@ public:
private:
Vector<Timeline *> _timelines;
HashMap<int, bool> _timelineIds;
float _duration;
String _name;

View File

@ -429,8 +429,6 @@ namespace spine {
void computeHold(TrackEntry *entry);
void computeNotLast(TrackEntry *entry);
bool hasTimeline(TrackEntry *entry, int inId);
};
}

View File

@ -44,9 +44,16 @@ using namespace spine;
Animation::Animation(const String &name, Vector<Timeline *> &timelines, float duration) :
_timelines(timelines),
_timelineIds(),
_duration(duration),
_name(name) {
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() {

View File

@ -995,11 +995,11 @@ void AnimationState::computeHold(TrackEntry *entry) {
if (to == NULL || timeline->getRTTI().isExactly(AttachmentTimeline::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;
} else {
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) {
timelineMode[i] = HoldMix;
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;
}