| 1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QT3DANIMATION_ANIMATION_BLENDEDCLIPANIMATOR_P_H |
| 5 | #define QT3DANIMATION_ANIMATION_BLENDEDCLIPANIMATOR_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of other Qt classes. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <Qt3DAnimation/private/backendnode_p.h> |
| 19 | #include <Qt3DAnimation/private/animationutils_p.h> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | namespace Qt3DAnimation { |
| 24 | namespace Animation { |
| 25 | |
| 26 | class Handler; |
| 27 | |
| 28 | class Q_AUTOTEST_EXPORT BlendedClipAnimator : public BackendNode |
| 29 | { |
| 30 | public: |
| 31 | BlendedClipAnimator(); |
| 32 | |
| 33 | void cleanup(); |
| 34 | void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; |
| 35 | |
| 36 | Qt3DCore::QNodeId blendTreeRootId() const; |
| 37 | Qt3DCore::QNodeId mapperId() const { return m_mapperId; } |
| 38 | Qt3DCore::QNodeId clockId() const { return m_clockId; } |
| 39 | bool isRunning() const { return m_running; } |
| 40 | void setNormalizedLocalTime(float normalizedTime, bool allowMarkDirty = true); |
| 41 | float normalizedLocalTime() const { return m_normalizedLocalTime; } |
| 42 | |
| 43 | // Called by BuildBlendTreeJob |
| 44 | bool canRun() const { return !m_mapperId.isNull() && !m_blendTreeRootId.isNull(); } |
| 45 | |
| 46 | void setBlendTreeRootId(Qt3DCore::QNodeId blendTreeRootId); |
| 47 | void setMapperId(Qt3DCore::QNodeId mapperId); |
| 48 | void setClockId(Qt3DCore::QNodeId clockId); |
| 49 | void setRunning(bool running); |
| 50 | |
| 51 | void setStartTime(qint64 globalTime) { m_lastGlobalTimeNS = globalTime; } |
| 52 | |
| 53 | void setLoops(int loops) { m_loops = loops; } |
| 54 | int loops() const { return m_loops; } |
| 55 | |
| 56 | int currentLoop() const { return m_currentLoop; } |
| 57 | void setCurrentLoop(int currentLoop) { m_currentLoop = currentLoop; } |
| 58 | |
| 59 | void setMappingData(const QVector<MappingData> &mappingData) { m_mappingData = mappingData; } |
| 60 | QVector<MappingData> mappingData() const { return m_mappingData; } |
| 61 | |
| 62 | void animationClipMarkedDirty() { setDirty(Handler::BlendedClipAnimatorDirty); } |
| 63 | |
| 64 | qint64 nsSincePreviousFrame(qint64 currentGlobalTimeNS); |
| 65 | void setLastGlobalTimeNS(const qint64 &lastGlobalTimeNS); |
| 66 | |
| 67 | double lastLocalTime() const; |
| 68 | void setLastLocalTime(double lastLocalTime); |
| 69 | |
| 70 | float lastNormalizedLocalTime() { return m_lastNormalizedLocalTime; } |
| 71 | void setLastNormalizedLocalTime(float normalizedTime); |
| 72 | bool isSeeking() const |
| 73 | { |
| 74 | return isValidNormalizedTime(t: m_normalizedLocalTime) |
| 75 | && !qFuzzyCompare(p1: m_lastNormalizedLocalTime, p2: m_normalizedLocalTime); |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | Qt3DCore::QNodeId m_blendTreeRootId; |
| 80 | Qt3DCore::QNodeId m_mapperId; |
| 81 | Qt3DCore::QNodeId m_clockId; |
| 82 | bool m_running; |
| 83 | |
| 84 | qint64 m_lastGlobalTimeNS; |
| 85 | double m_lastLocalTime; |
| 86 | |
| 87 | int m_currentLoop; |
| 88 | int m_loops; |
| 89 | |
| 90 | float m_normalizedLocalTime; |
| 91 | float m_lastNormalizedLocalTime; |
| 92 | |
| 93 | QVector<MappingData> m_mappingData; |
| 94 | }; |
| 95 | |
| 96 | } // namespace Animation |
| 97 | } // namespace Qt3DAnimation |
| 98 | |
| 99 | |
| 100 | QT_END_NAMESPACE |
| 101 | |
| 102 | #endif // QT3DANIMATION_ANIMATION_BLENDEDCLIPANIMATOR_P_H |
| 103 | |