diff options
author | Mike Krus <mike.krus@kdab.com> | 2020-09-25 10:41:24 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2020-09-25 11:57:54 +0100 |
commit | bbecb4a4ffe06e7f96c108995bc5e75614eaa963 (patch) | |
tree | 677712233d56bdc9ec29a2be3380fcd8a0b78c81 | |
parent | 96e9d67e40f1410f41cd9bae401948f10e448893 (diff) |
Fix animation not running
Previous fix for compile issue forgot to account for the fact that
the data changes after being registered with the class.
Change-Id: Ice5238221f190f758ec3f25d883c56877c185e1c
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
6 files changed, 30 insertions, 29 deletions
diff --git a/src/animation/backend/fcurve.cpp b/src/animation/backend/fcurve.cpp index 18f1f427e..37c50bf15 100644 --- a/src/animation/backend/fcurve.cpp +++ b/src/animation/backend/fcurve.cpp @@ -47,7 +47,7 @@ namespace Qt3DAnimation { namespace Animation { FCurve::FCurve() - : m_rangeFinder(m_localTimes) + : m_rangeFinder(&m_localTimes) { } diff --git a/src/animation/backend/functionrangefinder.cpp b/src/animation/backend/functionrangefinder.cpp index ed0ce1bea..84800b865 100644 --- a/src/animation/backend/functionrangefinder.cpp +++ b/src/animation/backend/functionrangefinder.cpp @@ -69,7 +69,7 @@ namespace Animation { If the previous results are uncorrelated, a simple bisection is used. */ -FunctionRangeFinder::FunctionRangeFinder(const QList<float> &x) +FunctionRangeFinder::FunctionRangeFinder(QList<float> *x) : m_x(x) , m_previousLowerBound(0) , m_correlated(0) @@ -78,8 +78,8 @@ FunctionRangeFinder::FunctionRangeFinder(const QList<float> &x) , m_ascending(true) { updateAutomaticCorrelationThreshold(); - if (!m_x.isEmpty()) - m_ascending = (m_x.last() >= m_x.first()); + if (!m_x->isEmpty()) + m_ascending = (m_x->last() >= m_x->first()); } /*! @@ -88,14 +88,14 @@ FunctionRangeFinder::FunctionRangeFinder(const QList<float> &x) */ int FunctionRangeFinder::locate(float x) const { - if (m_x.size() < 2 || m_rangeSize < 2 || m_rangeSize > m_x.size()) + if (m_x->size() < 2 || m_rangeSize < 2 || m_rangeSize > m_x->size()) return -1; int jLower = 0; - int jUpper = m_x.size() - 1; + int jUpper = m_x->size() - 1; while (jUpper - jLower > 1) { int jMid = (jUpper + jLower) >> 1; - if ((x >= m_x[jMid]) == m_ascending) + if ((x >= m_x->at(jMid)) == m_ascending) jLower = jMid; else jUpper = jMid; @@ -104,7 +104,7 @@ int FunctionRangeFinder::locate(float x) const m_correlated = std::abs(jLower - m_previousLowerBound) <= m_correlationThreshold; m_previousLowerBound = jLower; - return qMax(0, qMin(m_x.size() - m_rangeSize, jLower - ((m_rangeSize - 2) >> 1))); + return qMax(0, qMin(m_x->size() - m_rangeSize, jLower - ((m_rangeSize - 2) >> 1))); } /*! @@ -113,24 +113,24 @@ int FunctionRangeFinder::locate(float x) const */ int FunctionRangeFinder::hunt(float x) const { - if (m_x.size() < 2 || m_rangeSize < 2 || m_rangeSize > m_x.size()) + if (m_x->size() < 2 || m_rangeSize < 2 || m_rangeSize > m_x->size()) return -1; int jLower = m_previousLowerBound; int jMid; int jUpper; - if (jLower < 0 || jLower > (m_x.size() - 1)) { + if (jLower < 0 || jLower > (m_x->size() - 1)) { jLower = 0; - jUpper = m_x.size() - 1; + jUpper = m_x->size() - 1; } else { int increment = 1; - if ((x >= m_x[jLower]) == m_ascending) { + if ((x >= m_x->at(jLower)) == m_ascending) { for (;;) { jUpper = jLower + increment; - if (jUpper >= m_x.size() - 1) { - jUpper = m_x.size() - 1; + if (jUpper >= m_x->size() - 1) { + jUpper = m_x->size() - 1; break; - } else if ((x < m_x[jUpper]) == m_ascending) { + } else if ((x < m_x->at(jUpper)) == m_ascending) { break; } else { jLower = jUpper; @@ -144,7 +144,7 @@ int FunctionRangeFinder::hunt(float x) const if (jLower <= 0) { jLower = 0; break; - } else if ((x >= m_x[jLower]) == m_ascending) { + } else if ((x >= m_x->at(jLower)) == m_ascending) { break; } else { jUpper = jLower; @@ -156,7 +156,7 @@ int FunctionRangeFinder::hunt(float x) const while (jUpper - jLower > 1) { jMid = (jUpper + jLower) >> 1; - if ((x >= m_x[jMid]) == m_ascending) + if ((x >= m_x->at(jMid)) == m_ascending) jLower = jMid; else jUpper = jMid; @@ -165,7 +165,7 @@ int FunctionRangeFinder::hunt(float x) const m_correlated = std::abs(jLower - m_previousLowerBound) <= m_correlationThreshold; m_previousLowerBound = jLower; - return qMax(0, qMin(m_x.size() - m_rangeSize, jLower - ((m_rangeSize - 2) >> 1))); + return qMax(0, qMin(m_x->size() - m_rangeSize, jLower - ((m_rangeSize - 2) >> 1))); } } // namespace Animation diff --git a/src/animation/backend/functionrangefinder_p.h b/src/animation/backend/functionrangefinder_p.h index 004bea4b8..fc379a311 100644 --- a/src/animation/backend/functionrangefinder_p.h +++ b/src/animation/backend/functionrangefinder_p.h @@ -61,7 +61,7 @@ namespace Animation { class Q_AUTOTEST_EXPORT FunctionRangeFinder { public: - FunctionRangeFinder(const QList<float> &x); + FunctionRangeFinder(QList<float> *x); inline int findLowerBound(float x) const { return m_correlated ? hunt(x) : locate(x); } @@ -74,14 +74,14 @@ public: int correlationThreshold() const { return m_correlationThreshold; } void updateAutomaticCorrelationThreshold() { - m_correlationThreshold = std::max(1, int(std::pow(float(m_x.size()), 0.25))); + m_correlationThreshold = std::max(1, int(std::pow(float(m_x->size()), 0.25))); } private: int locate(float x) const; int hunt(float x) const; - QList<float> m_x; + QList<float> *m_x; mutable int m_previousLowerBound; mutable bool m_correlated; int m_rangeSize; diff --git a/tests/auto/animation/functionrangefinder/tst_functionrangefinder.cpp b/tests/auto/animation/functionrangefinder/tst_functionrangefinder.cpp index 62d519b20..05e05ab98 100644 --- a/tests/auto/animation/functionrangefinder/tst_functionrangefinder.cpp +++ b/tests/auto/animation/functionrangefinder/tst_functionrangefinder.cpp @@ -42,7 +42,7 @@ private Q_SLOTS: QList<float> data; // WHEN - FunctionRangeFinder finder(data); + FunctionRangeFinder finder(&data); // THEN QCOMPARE(finder.rangeSize(), 2); @@ -87,7 +87,7 @@ private Q_SLOTS: QFETCH(bool, ascending); // WHEN - FunctionRangeFinder finder(x); + FunctionRangeFinder finder(&x); // THEN QCOMPARE(finder.rangeSize(), 2); @@ -156,7 +156,7 @@ private Q_SLOTS: QFETCH(QList<float>, x); QFETCH(QList<float>, needles); QFETCH(QList<int>, lowerBounds); - FunctionRangeFinder finder(x); + FunctionRangeFinder finder(&x); for (int i = 0; i < needles.size(); ++i) { // WHEN diff --git a/tests/manual/animation-keyframe-simple/CMakeLists.txt b/tests/manual/animation-keyframe-simple/CMakeLists.txt index 2769f5fa0..b15ee1b9f 100644 --- a/tests/manual/animation-keyframe-simple/CMakeLists.txt +++ b/tests/manual/animation-keyframe-simple/CMakeLists.txt @@ -29,7 +29,7 @@ qt_add_resource(animation-keyframe-simple "main" FILES ${main_resource_files} ) - +target_sources(animation-keyframe-simple PRIVATE ${main_resource_files}) #### Keys ignored in scope 1:.:.:animation-keyframe-simple.pro:<TRUE>: # OTHER_FILES = "main.qml" "DefaultSceneEntity.qml" diff --git a/tests/manual/animation-keyframe-simple/main.qml b/tests/manual/animation-keyframe-simple/main.qml index 9246f2467..b75b99c54 100644 --- a/tests/manual/animation-keyframe-simple/main.qml +++ b/tests/manual/animation-keyframe-simple/main.qml @@ -77,14 +77,15 @@ DefaultSceneEntity { ObjectPicker { onClicked: { if (animator.running == false) { - animator.running = true; + animator.normalizedTime = 0 + animator.running = true } else { switch (pick.button) { case PickEvent.RightButton: - animationClock.playbackRate *= 2.0; + animationClock.playbackRate *= 2.0 break; case PickEvent.LeftButton: - animationClock.playbackRate /= 2.0; + animationClock.playbackRate /= 2.0 break; default: break; @@ -103,7 +104,7 @@ DefaultSceneEntity { } clip: AnimationClipLoader { - source: "cubeanimation.json" + source: "qrc:///cubeanimation.json" onDurationChanged: console.log("duration = " + duration) } |