1// Copyright (C) 2016 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#include "axisaccumulatorjob_p.h"
5#include <Qt3DCore/private/qaspectmanager_p.h>
6#include <Qt3DInput/qaxisaccumulator.h>
7#include <Qt3DInput/private/qaxisaccumulator_p.h>
8#include <Qt3DInput/private/axisaccumulator_p.h>
9#include <Qt3DInput/private/job_common_p.h>
10#include <Qt3DInput/private/inputmanagers_p.h>
11
12QT_BEGIN_NAMESPACE
13
14namespace Qt3DInput {
15namespace Input {
16
17class AxisAccumulatorJobPrivate : public Qt3DCore::QAspectJobPrivate
18{
19public:
20 AxisAccumulatorJobPrivate() { }
21 ~AxisAccumulatorJobPrivate() override { }
22
23 void postFrame(Qt3DCore::QAspectManager *manager) override;
24
25 QList<AxisAccumulator *> updates;
26};
27
28AxisAccumulatorJob::AxisAccumulatorJob(AxisAccumulatorManager *axisAccumulatormanager,
29 AxisManager *axisManager)
30 : Qt3DCore::QAspectJob(*new AxisAccumulatorJobPrivate)
31 , m_axisAccumulatorManager(axisAccumulatormanager)
32 , m_axisManager(axisManager)
33 , m_dt(0.0f)
34{
35 SET_JOB_RUN_STAT_TYPE(this, JobTypes::AxisAccumulatorIntegration, 0)
36}
37
38void AxisAccumulatorJob::run()
39{
40 Q_D(AxisAccumulatorJob);
41 // Iterate over the accumulators and ask each to step the integrations
42 const auto activeHandles = m_axisAccumulatorManager->activeHandles();
43 d->updates.reserve(asize: activeHandles.size());
44
45 for (const auto &accumulatorHandle : activeHandles) {
46 AxisAccumulator *accumulator = m_axisAccumulatorManager->data(handle: accumulatorHandle);
47 if (accumulator->isEnabled()) {
48 accumulator->stepIntegration(axisManager: m_axisManager, dt: m_dt);
49 d->updates.push_back(t: accumulator);
50 }
51 }
52}
53
54void AxisAccumulatorJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
55{
56 for (auto backend: std::as_const(t&: updates)) {
57 QAxisAccumulator *node = qobject_cast<QAxisAccumulator *>(object: manager->lookupNode(id: backend->peerId()));
58 if (!node)
59 continue;
60
61 QAxisAccumulatorPrivate *dnode = static_cast<QAxisAccumulatorPrivate *>(QAxisAccumulatorPrivate::get(q: node));
62 dnode->setValue(backend->value());
63 dnode->setVelocity(backend->velocity());
64 }
65}
66
67} // namespace Input
68} // namespace Qt3DInput
69
70QT_END_NAMESPACE
71

source code of qt3d/src/input/backend/axisaccumulatorjob.cpp