diff options
author | Janne Kangas <janne.kangas@qt.io> | 2019-08-13 09:51:41 +0300 |
---|---|---|
committer | Janne Kangas <janne.kangas@qt.io> | 2019-08-13 12:37:01 +0300 |
commit | 12e4c533b0e7cabd9676f4f767f221aea1343102 (patch) | |
tree | d784d15535e1afa22945e07350dfde5c54c54007 | |
parent | 7ea21a4315b1c6df104d80a700680dd1f9d204dc (diff) |
Batch setDataInputValue calls also on C++ side
Collect/cache all set value calls to a batch within a frame, effectively
discarding all except the most recent value(s) within a frame period.
This decreases the performance impact of high-frequency value setter calls
from external sources.
Also, remove deprecated functionality from internal datainput setValue
interface.
Change-Id: I4165c97f96a4fe25796eb27d53802fbee507aa6c
Task-id: QT3DS-3857
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r-- | src/api/studio3d/q3dsdatainput.cpp | 6 | ||||
-rw-r--r-- | src/api/studio3d/q3dsdatainput.h | 6 | ||||
-rw-r--r-- | src/api/studio3d/q3dsdatainput_p.h | 3 | ||||
-rw-r--r-- | src/api/studio3d/q3dspresentation.cpp | 40 | ||||
-rw-r--r-- | src/api/studio3d/q3dspresentation.h | 3 | ||||
-rw-r--r-- | src/api/studio3d/q3dspresentation_p.h | 2 | ||||
-rw-r--r-- | src/api/studio3d/q3dssurfaceviewer.cpp | 7 |
7 files changed, 41 insertions, 26 deletions
diff --git a/src/api/studio3d/q3dsdatainput.cpp b/src/api/studio3d/q3dsdatainput.cpp index bfd8b43..f3a1bad 100644 --- a/src/api/studio3d/q3dsdatainput.cpp +++ b/src/api/studio3d/q3dsdatainput.cpp @@ -348,7 +348,7 @@ void Q3DSDataInput::setValue(const QVariant &value) // For example, when controlling timeline, the value set to DataInput will only be // the current value for one frame if presentation has a running animation. // In order to track an element property, see DataOutput API. - d_ptr->setValue(value, ValueRole::Value); + d_ptr->setValue(value); Q_EMIT valueChanged(); } @@ -373,13 +373,13 @@ Q3DSDataInputPrivate::~Q3DSDataInputPrivate() m_presentation->unregisterDataInput(q_ptr); } -void Q3DSDataInputPrivate::setValue(const QVariant &value, Q3DSDataInput::ValueRole valueRole) +void Q3DSDataInputPrivate::setValue(const QVariant &value) { m_value = value; setDirty(true); if (m_presentation) - m_presentation->setDataInputValue(m_name, m_value, valueRole); + m_presentation->setDataInputValue(m_name, m_value); } void Q3DSDataInputPrivate::setViewerApp(Q3DSViewer::Q3DSViewerApp *app) diff --git a/src/api/studio3d/q3dsdatainput.h b/src/api/studio3d/q3dsdatainput.h index 3f81c65..e358e77 100644 --- a/src/api/studio3d/q3dsdatainput.h +++ b/src/api/studio3d/q3dsdatainput.h @@ -57,12 +57,6 @@ public: virtual ~Q3DSDataInput(); - enum class ValueRole { - Value = 0, - Min = 1, - Max = 2 - }; - QString name() const; QVariant value() const; float min() const; diff --git a/src/api/studio3d/q3dsdatainput_p.h b/src/api/studio3d/q3dsdatainput_p.h index b5e0cc5..94384a5 100644 --- a/src/api/studio3d/q3dsdatainput_p.h +++ b/src/api/studio3d/q3dsdatainput_p.h @@ -56,8 +56,7 @@ public: explicit Q3DSDataInputPrivate(Q3DSDataInput *parent); virtual ~Q3DSDataInputPrivate(); - void setValue(const QVariant &value, - Q3DSDataInput::ValueRole valueRole = Q3DSDataInput::ValueRole::Value); + void setValue(const QVariant &value); void setViewerApp(Q3DSViewer::Q3DSViewerApp *app); void setCommandQueue(CommandQueue *queue); void setPresentation(Q3DSPresentation *presentation); diff --git a/src/api/studio3d/q3dspresentation.cpp b/src/api/studio3d/q3dspresentation.cpp index 3863fa3..2e1aeab 100644 --- a/src/api/studio3d/q3dspresentation.cpp +++ b/src/api/studio3d/q3dspresentation.cpp @@ -845,17 +845,13 @@ void Q3DSPresentation::setGlobalAnimationTime(qint64 milliseconds) \sa DataInput */ -void Q3DSPresentation::setDataInputValue(const QString &name, const QVariant &value, - Q3DSDataInput::ValueRole valueRole) +void Q3DSPresentation::setDataInputValue(const QString &name, const QVariant &value) { - // If we do not have viewerApp i.e. if this is a QML client context, do not send - // datainput set commands to the queue. They are batched and sent out at frameUpdate signal. - if (d_ptr->m_viewerApp) { - d_ptr->m_viewerApp->SetDataInputValue(name, value, - (qt3ds::runtime::DataInputValueRole)valueRole); - } else { - d_ptr->m_dataInputsChanged = true; - } + Q_UNUSED(name) // TODO: need these again when adding "force set" flag to this API + Q_UNUSED(value) + // We batch datainput changes within a frame, so just tell the presentation that one + // or more datainputs have changed value. + d_ptr->m_dataInputsChanged = true; } /*! @@ -1633,6 +1629,11 @@ void Q3DSPresentationPrivate::setDelayedLoading(bool enable) } } +void Q3DSPresentationPrivate::setDataInputsChanged(bool changed) +{ + m_dataInputsChanged = changed; +} + void Q3DSPresentationPrivate::requestResponseHandler(CommandType commandType, void *requestData) { switch (commandType) { @@ -1919,9 +1920,13 @@ bool Q3DSPresentationPrivate::isValidDataOutput(const Q3DSDataOutput *dataOutput return m_viewerApp->dataOutputs().contains(dataOutput->name()); } +bool Q3DSPresentationPrivate::dataInputsChanged() const +{ + return m_dataInputsChanged; +} + void Q3DSPresentationPrivate::setDataInputValueBatch() { - // Allocated here, deleted after queue command has been processed. QVector<QPair<QString, QVariant>> *theProperties = new QVector<QPair<QString, QVariant>>(); for (const auto &di : qAsConst(m_dataInputs)) { if (di->d_ptr->m_dirty) { @@ -1930,8 +1935,17 @@ void Q3DSPresentationPrivate::setDataInputValueBatch() } } - if (!theProperties->empty() && m_commandQueue) - m_commandQueue->queueCommand({}, CommandType_SetDataInputBatch, {}, theProperties); + if (!theProperties->empty()) { + if (m_commandQueue) { // QML context + m_commandQueue->queueCommand({}, CommandType_SetDataInputBatch, {}, theProperties); + return; // Get out, queue will handle property list deletion. + } else if (m_viewerApp) { // C++ API access + for (const auto &change : qAsConst(*theProperties)) + m_viewerApp->SetDataInputValue(change.first, change.second); + } + } + + delete theProperties; // Delete immediately, we do not have queue to take care of deletion. } Q3DStudio::EKeyCode Q3DSPresentationPrivate::getScanCode(QKeyEvent *e) diff --git a/src/api/studio3d/q3dspresentation.h b/src/api/studio3d/q3dspresentation.h index 04faf0d..535ba40 100644 --- a/src/api/studio3d/q3dspresentation.h +++ b/src/api/studio3d/q3dspresentation.h @@ -130,8 +130,7 @@ public Q_SLOTS: void setPresentationActive(const QString &id, bool active); void fireEvent(const QString &elementPath, const QString &eventName); void setGlobalAnimationTime(qint64 milliseconds); - void setDataInputValue(const QString &name, const QVariant &value, - Q3DSDataInput::ValueRole valueRole = Q3DSDataInput::ValueRole::Value); + void setDataInputValue(const QString &name, const QVariant &value); Q_SIGNALS: void variantListChanged(const QStringList &variantList); diff --git a/src/api/studio3d/q3dspresentation_p.h b/src/api/studio3d/q3dspresentation_p.h index a68d0ee..51317bd 100644 --- a/src/api/studio3d/q3dspresentation_p.h +++ b/src/api/studio3d/q3dspresentation_p.h @@ -71,6 +71,7 @@ public: void setViewerApp(Q3DSViewer::Q3DSViewerApp *app, bool connectApp = true); void setCommandQueue(CommandQueue *queue); void setDelayedLoading(bool enable); + void setDataInputsChanged(bool changed); void registerElement(Q3DSElement *element); void unregisterElement(Q3DSElement *element); @@ -89,6 +90,7 @@ public: QHash<QString, QString> dataInputMetadata(const QString &name) const; QVector<Q3DSDataInput *> dataInputs(const QString &key) const; bool isValidDataOutput(const Q3DSDataOutput *dataOutput) const; + bool dataInputsChanged() const; void setDataInputValueBatch(); diff --git a/src/api/studio3d/q3dssurfaceviewer.cpp b/src/api/studio3d/q3dssurfaceviewer.cpp index d8a9756..a79597f 100644 --- a/src/api/studio3d/q3dssurfaceviewer.cpp +++ b/src/api/studio3d/q3dssurfaceviewer.cpp @@ -523,6 +523,13 @@ void Q3DSSurfaceViewerPrivate::update() if (m_autoSize) setSize(m_surface->size()); + + // Fire off a batch change with the most recently set values for this frame period. + if (m_presentation->d_ptr->dataInputsChanged()) { + m_presentation->d_ptr->setDataInputValueBatch(); + m_presentation->d_ptr->setDataInputsChanged(false); + } + m_viewerApp->Render(); const uint defaultFbo = m_context->defaultFramebufferObject(); |