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_CLIPANIMATOR_P_H
5#define QT3DANIMATION_ANIMATION_CLIPANIMATOR_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#include <Qt3DCore/qnodeid.h>
21
22QT_BEGIN_NAMESPACE
23
24namespace Qt3DAnimation {
25namespace Animation {
26
27struct Channel;
28class Handler;
29
30class Q_AUTOTEST_EXPORT ClipAnimator : public BackendNode
31{
32public:
33 ClipAnimator();
34
35 void cleanup();
36 void setClipId(Qt3DCore::QNodeId clipId);
37 Qt3DCore::QNodeId clipId() const { return m_clipId; }
38 void setMapperId(Qt3DCore::QNodeId mapperId);
39 Qt3DCore::QNodeId mapperId() const { return m_mapperId; }
40 void setClockId(Qt3DCore::QNodeId clockId);
41 Qt3DCore::QNodeId clockId() const { return m_clockId; }
42
43 void setRunning(bool running);
44 bool isRunning() const { return m_running; }
45 void setLoops(int loops) { m_loops = loops; }
46 int loops() const { return m_loops; }
47 void setNormalizedLocalTime(float normalizedLocalTime, bool allowMarkDirty = true);
48 float normalizedLocalTime() const { return m_normalizedLocalTime; }
49
50 void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
51 void setHandler(Handler *handler) { m_handler = handler; }
52
53 // Called by jobs
54 bool canRun() const { return !m_clipId.isNull() && !m_mapperId.isNull(); }
55 void setMappingData(const QVector<MappingData> &mappingData) { m_mappingData = mappingData; }
56 QVector<MappingData> mappingData() const { return m_mappingData; }
57
58 void setStartTime(qint64 globalTime) { m_lastGlobalTimeNS = globalTime; }
59
60 int currentLoop() const { return m_currentLoop; }
61 void setCurrentLoop(int currentLoop) { m_currentLoop = currentLoop; }
62
63 void animationClipMarkedDirty() { setDirty(Handler::ClipAnimatorDirty); }
64
65 void setClipFormat(const ClipFormat &clipFormat) { m_clipFormat = clipFormat; }
66 ClipFormat clipFormat() const { return m_clipFormat; }
67
68 qint64 nsSincePreviousFrame(qint64 currentGlobalTimeNS);
69 void setLastGlobalTimeNS(qint64 lastGlobalTimeNS);
70
71 double lastLocalTime() const;
72 void setLastLocalTime(double lastLocalTime);
73
74 float lastNormalizedLocalTime() { return m_lastNormalizedLocalTime; }
75 void setLastNormalizedLocalTime(float normalizedLocalTime);
76 bool isSeeking() const
77 {
78 return isValidNormalizedTime(t: m_normalizedLocalTime)
79 && !qFuzzyCompare(p1: m_lastNormalizedLocalTime, p2: m_normalizedLocalTime);
80 }
81
82private:
83 Qt3DCore::QNodeId m_clipId;
84 Qt3DCore::QNodeId m_mapperId;
85 Qt3DCore::QNodeId m_clockId;
86 bool m_running;
87 int m_loops;
88
89 // Working state
90 qint64 m_lastGlobalTimeNS;
91 double m_lastLocalTime;
92 QVector<MappingData> m_mappingData;
93
94 int m_currentLoop;
95 ClipFormat m_clipFormat;
96
97 float m_normalizedLocalTime;
98 float m_lastNormalizedLocalTime;
99};
100
101} // namespace Animation
102} // namespace Qt3DAnimation
103
104
105QT_END_NAMESPACE
106
107#endif // QT3DANIMATION_ANIMATION_CLIPANIMATOR_P_H
108

source code of qt3d/src/animation/backend/clipanimator_p.h