diff --git a/spine-cpp/spine-cpp/include/spine/Animation.h b/spine-cpp/spine-cpp/include/spine/Animation.h index 7c9355c35..247b5e020 100644 --- a/spine-cpp/spine-cpp/include/spine/Animation.h +++ b/spine-cpp/spine-cpp/include/spine/Animation.h @@ -40,6 +40,7 @@ namespace spine { class Timeline; + class BoneTimeline; class Skeleton; @@ -104,12 +105,14 @@ namespace spine { /// Applies all the animation's timelines to the specified skeleton. /// See also Timeline::apply(Skeleton&, float, float, Vector, float, MixPose, MixDirection) void apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction); + MixBlend blend, MixDirection direction, bool appliedPose); const String &getName(); Vector &getTimelines(); + void setTimelines(Vector &timelines); + bool hasTimeline(Vector &ids); float getDuration(); @@ -123,6 +126,7 @@ namespace spine { private: Vector _timelines; HashMap _timelineIds; + Vector _bones; float _duration; String _name; }; diff --git a/spine-cpp/spine-cpp/src/spine/Animation.cpp b/spine-cpp/spine-cpp/src/spine/Animation.cpp index 21fafac6f..0319271fa 100644 --- a/spine-cpp/spine-cpp/src/spine/Animation.cpp +++ b/spine-cpp/spine-cpp/src/spine/Animation.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -38,16 +39,13 @@ using namespace spine; -Animation::Animation(const String &name, Vector &timelines, float duration) : _timelines(timelines), +Animation::Animation(const String &name, Vector &timelines, float duration) : _timelines(), _timelineIds(), + _bones(), _duration(duration), _name(name) { assert(_name.length() > 0); - for (size_t i = 0; i < timelines.size(); i++) { - Vector propertyIds = timelines[i]->getPropertyIds(); - for (size_t ii = 0; ii < propertyIds.size(); ii++) - _timelineIds.put(propertyIds[ii], true); - } + setTimelines(timelines); } bool Animation::hasTimeline(Vector &ids) { @@ -62,7 +60,7 @@ Animation::~Animation() { } void Animation::apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction, bool appliedPose) { if (loop && _duration != 0) { time = MathUtil::fmod(time, _duration); if (lastTime > 0) { @@ -71,7 +69,7 @@ void Animation::apply(Skeleton &skeleton, float lastTime, float time, bool loop, } for (size_t i = 0, n = _timelines.size(); i < n; ++i) { - _timelines[i]->apply(skeleton, lastTime, time, pEvents, alpha, blend, direction); + _timelines[i]->apply(skeleton, lastTime, time, pEvents, alpha, blend, direction, appliedPose); } } @@ -105,3 +103,35 @@ int Animation::search(Vector &frames, float target, int step) { if (frames[i] > target) return (int) (i - step); return (int) (n - step); } + +void Animation::setTimelines(Vector &timelines) { + _timelines = timelines; + + size_t n = timelines.size(); + _timelineIds.clear(); + _bones.clear(); + + HashMap boneSet; + for (size_t i = 0; i < n; i++) { + Timeline *timeline = timelines[i]; + Vector propertyIds = timeline->getPropertyIds(); + for (size_t ii = 0; ii < propertyIds.size(); ii++) { + _timelineIds.put(propertyIds[ii], true); + } + + BoneTimeline *boneTimeline = nullptr; + if (timeline->getRTTI().instanceOf(BoneTimeline1::rtti)) { + boneTimeline = static_cast(timeline); + } else if (timeline->getRTTI().instanceOf(BoneTimeline2::rtti)) { + boneTimeline = static_cast(timeline); + } + + if (boneTimeline) { + int boneIndex = boneTimeline->getBoneIndex(); + if (!boneSet.containsKey(boneIndex)) { + boneSet.put(boneIndex, true); + _bones.add(boneIndex); + } + } + } +}