| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: http://www.qt-project.org/legal |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #include "loadanimationclipjob_p.h" |
| 38 | |
| 39 | #include <Qt3DCore/private/qaspectmanager_p.h> |
| 40 | #include <Qt3DAnimation/qanimationcliploader.h> |
| 41 | #include <Qt3DAnimation/private/qanimationcliploader_p.h> |
| 42 | #include <Qt3DAnimation/private/animationclip_p.h> |
| 43 | #include <Qt3DAnimation/private/qabstractanimationclip_p.h> |
| 44 | #include <Qt3DAnimation/private/handler_p.h> |
| 45 | #include <Qt3DAnimation/private/managers_p.h> |
| 46 | #include <Qt3DAnimation/private/job_common_p.h> |
| 47 | |
| 48 | QT_BEGIN_NAMESPACE |
| 49 | |
| 50 | namespace Qt3DAnimation { |
| 51 | namespace Animation { |
| 52 | |
| 53 | class LoadAnimationClipJobPrivate : public Qt3DCore::QAspectJobPrivate |
| 54 | { |
| 55 | public: |
| 56 | LoadAnimationClipJobPrivate() { } |
| 57 | ~LoadAnimationClipJobPrivate() override { } |
| 58 | |
| 59 | void postFrame(Qt3DCore::QAspectManager *manager) override; |
| 60 | |
| 61 | QVector<AnimationClip *> m_updatedNodes; |
| 62 | }; |
| 63 | |
| 64 | LoadAnimationClipJob::LoadAnimationClipJob() |
| 65 | : Qt3DCore::QAspectJob(*new LoadAnimationClipJobPrivate) |
| 66 | , m_animationClipHandles() |
| 67 | , m_handler(nullptr) |
| 68 | { |
| 69 | SET_JOB_RUN_STAT_TYPE(this, JobTypes::LoadAnimationClip, 0) |
| 70 | } |
| 71 | |
| 72 | void LoadAnimationClipJob::addDirtyAnimationClips(const QVector<HAnimationClip> &animationClipHandles) |
| 73 | { |
| 74 | for (const auto &handle : animationClipHandles) { |
| 75 | if (!m_animationClipHandles.contains(t: handle)) |
| 76 | m_animationClipHandles.push_back(t: handle); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void LoadAnimationClipJob::clearDirtyAnimationClips() |
| 81 | { |
| 82 | m_animationClipHandles.clear(); |
| 83 | } |
| 84 | |
| 85 | void LoadAnimationClipJob::run() |
| 86 | { |
| 87 | Q_ASSERT(m_handler); |
| 88 | Q_D(LoadAnimationClipJob); |
| 89 | |
| 90 | d->m_updatedNodes.reserve(asize: m_animationClipHandles.size()); |
| 91 | AnimationClipLoaderManager *animationClipManager = m_handler->animationClipLoaderManager(); |
| 92 | for (const auto &animationClipHandle : qAsConst(t&: m_animationClipHandles)) { |
| 93 | AnimationClip *animationClip = animationClipManager->data(handle: animationClipHandle); |
| 94 | Q_ASSERT(animationClip); |
| 95 | animationClip->loadAnimation(); |
| 96 | d->m_updatedNodes.push_back(t: animationClip); |
| 97 | } |
| 98 | |
| 99 | clearDirtyAnimationClips(); |
| 100 | } |
| 101 | |
| 102 | void LoadAnimationClipJobPrivate::postFrame(Qt3DCore::QAspectManager *manager) |
| 103 | { |
| 104 | for (AnimationClip *clip: qAsConst(t&: m_updatedNodes)) { |
| 105 | QAbstractAnimationClip *node = qobject_cast<QAbstractAnimationClip *>(object: manager->lookupNode(id: clip->peerId())); |
| 106 | if (!node) |
| 107 | continue; |
| 108 | |
| 109 | QAbstractAnimationClipPrivate *dnode = static_cast<QAbstractAnimationClipPrivate *>(Qt3DCore::QNodePrivate::get(q: node)); |
| 110 | dnode->setDuration(clip->duration()); |
| 111 | |
| 112 | QAnimationClipLoader *loader = qobject_cast<QAnimationClipLoader *>(object: node); |
| 113 | if (loader) { |
| 114 | QAnimationClipLoaderPrivate *dloader = static_cast<QAnimationClipLoaderPrivate *>(dnode); |
| 115 | dloader->setStatus(clip->status()); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | m_updatedNodes.clear(); |
| 120 | } |
| 121 | |
| 122 | } // namespace Animation |
| 123 | } // namespace Qt3DAnimation |
| 124 | |
| 125 | QT_END_NAMESPACE |
| 126 |
