[cpp] Switch AnimationState.propertyIDs to a hash map.

This commit is contained in:
badlogic 2019-09-26 16:46:21 +02:00
parent 2c0881da61
commit 3821389cd7
4 changed files with 13 additions and 6 deletions

View File

@ -393,7 +393,7 @@ namespace spine {
Vector<Event*> _events; Vector<Event*> _events;
EventQueue* _queue; EventQueue* _queue;
Vector<int> _propertyIDs; HashMap<int, bool> _propertyIDs;
bool _animationsChanged; bool _animationsChanged;
AnimationStateListener _listener; AnimationStateListener _listener;

View File

@ -30,6 +30,7 @@
#ifndef Spine_Extension_h #ifndef Spine_Extension_h
#define Spine_Extension_h #define Spine_Extension_h
#include <stdlib.h> #include <stdlib.h>
#include <spine/dll.h> #include <spine/dll.h>

View File

@ -89,11 +89,17 @@ public:
} }
~HashMap() { ~HashMap() {
clear();
}
void clear() {
for (Entry *entry = _head; entry != NULL;) { for (Entry *entry = _head; entry != NULL;) {
Entry* next = entry->next; Entry* next = entry->next;
delete entry; delete entry;
entry = next; entry = next;
} }
_head = NULL;
_size = 0;
} }
size_t size() { size_t size() {

View File

@ -976,7 +976,7 @@ void AnimationState::computeHold(TrackEntry *entry) {
if (to != NULL && to->_holdPrevious) { if (to != NULL && to->_holdPrevious) {
for (size_t i = 0; i < timelinesCount; i++) { for (size_t i = 0; i < timelinesCount; i++) {
int id = timelines[i]->getPropertyId(); int id = timelines[i]->getPropertyId();
if (!_propertyIDs.contains(id)) _propertyIDs.add(id); if (!_propertyIDs.containsKey(id)) _propertyIDs.put(id, true);
timelineMode[i] = Hold; timelineMode[i] = Hold;
} }
return; return;
@ -988,10 +988,10 @@ void AnimationState::computeHold(TrackEntry *entry) {
for (; i < timelinesCount; ++i) { for (; i < timelinesCount; ++i) {
Timeline *timeline = timelines[i]; Timeline *timeline = timelines[i];
int id = timeline->getPropertyId(); int id = timeline->getPropertyId();
if (_propertyIDs.contains(id)) { if (_propertyIDs.containsKey(id)) {
timelineMode[i] = Subsequent; timelineMode[i] = Subsequent;
} else { } else {
_propertyIDs.add(id); _propertyIDs.put(id, true);
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) ||
@ -1022,8 +1022,8 @@ void AnimationState::computeNotLast(TrackEntry *entry) {
for (size_t i = 0; i < timelinesCount; i++) { for (size_t i = 0; i < timelinesCount; i++) {
if (timelines[i]->getRTTI().isExactly(AttachmentTimeline::rtti)) { if (timelines[i]->getRTTI().isExactly(AttachmentTimeline::rtti)) {
AttachmentTimeline *timeline = static_cast<AttachmentTimeline *>(timelines[i]); AttachmentTimeline *timeline = static_cast<AttachmentTimeline *>(timelines[i]);
if (!_propertyIDs.contains(timeline->getSlotIndex())) if (!_propertyIDs.containsKey(timeline->getSlotIndex()))
_propertyIDs.add(timeline->getSlotIndex()); _propertyIDs.put(timeline->getSlotIndex(), true);
else else
timelineMode[i] |= NotLast; timelineMode[i] |= NotLast;
} }