diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-05-11 14:34:55 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-05-14 07:44:08 +0000 |
commit | d8951711c3f5a2f52c24715f15f9a446ca7ae755 (patch) | |
tree | 247fbb9a2ec323d6d7a825c86131b1ab4a15a797 /src/Authoring/Studio | |
parent | 4f3612e4c2c79ec61269de8581138b44267608b5 (diff) |
Optimize iterating through child objects
GetAssetChildrenInTimeParent was getting called unnecessarily much,
as it was called every time GetChildrenCount or GetChild was called.
According to profiling it was responsible for vast majority of the time
spent when changing a slide. Optimized various loops that iterate
through object's children to only call this function once.
Task-number: QT3DS-1601
Change-Id: Ia006acb76bd818c390a36f6fe9f1656660974c0e
Reviewed-by: Antti Määttä <antti.maatta@qt.io>
Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io>
Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Authoring/Studio')
9 files changed, 154 insertions, 94 deletions
diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h index 9469981d..9a5f7e3e 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h @@ -99,6 +99,7 @@ public: // Hierarchy virtual long GetChildrenCount() = 0; virtual ITimelineItemBinding *GetChild(long inIndex) = 0; + virtual QList<ITimelineItemBinding *> GetChildren() = 0; virtual ITimelineItemBinding *GetParent() = 0; virtual void SetParent(ITimelineItemBinding *parent) = 0; // Properties diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp index 7cd9bfe6..9b11c389 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp @@ -131,9 +131,6 @@ EStudioObjectType CLayerTimelineItemBinding::GetObjectType() const ITimelineItemBinding *CLayerTimelineItemBinding::GetChild(long inIndex) { - static const TCharStr theLayerPrefix(L"Layer_"); - qt3dsdm::IPropertySystem *thePropertySystem = m_TransMgr->GetStudioSystem()->GetPropertySystem(); - qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance(); if (theInstance.Valid()) { Q3DStudio::CGraphIterator theChildren; @@ -141,74 +138,29 @@ ITimelineItemBinding *CLayerTimelineItemBinding::GetChild(long inIndex) GetAssetChildrenInTimeParent(theInstance, m_TransMgr->GetDoc(), AmITimeParent(), theChildren, theActiveSlide); theChildren += inIndex; + return GetOrCreateBinding(theChildren.GetCurrent()); + } + return nullptr; +} - qt3dsdm::Qt3DSDMInstanceHandle theChildInstance = theChildren.GetCurrent(); - if (theChildInstance.Valid()) { - std::shared_ptr<IDataCore> theDataCore = - m_TransMgr->GetStudioSystem()->GetFullSystem()->GetCoreSystem()->GetDataCore(); - ISlideSystem *theSlideSystem = m_TransMgr->GetStudioSystem()->GetSlideSystem(); - ISlideCore *theSlideCore = m_TransMgr->GetStudioSystem()->GetSlideCore(); - - size_t theSlotCursor = (size_t)-1; - { - - qt3dsdm::IPropertySystem *thePropertySystem = - m_TransMgr->GetStudioSystem()->GetPropertySystem(); - qt3dsdm::SLong4 theGuid; - { - Qt3DSDMPropertyHandle theTypeProperty = - thePropertySystem->GetAggregateInstancePropertyByName(theChildInstance, - L"id"); - SValue theIdValue; - thePropertySystem->GetInstancePropertyValue(theChildInstance, theTypeProperty, - theIdValue); - theGuid = qt3dsdm::get<qt3dsdm::SLong4>(theIdValue); - } - for (size_t theSlotIndex = 0, theSlotCount = m_ImageNameFormalNamePairs.size(); - theSlotIndex < theSlotCount; ++theSlotIndex) { - bool theIsMatch = false; - qt3dsdm::Qt3DSDMPropertyHandle theProperty = - std::get<2>(m_ImageNameFormalNamePairs[theSlotIndex]); - SValue theValue; - const Qt3DSDMPropertyDefinition &theDefinition( - theDataCore->GetProperty(theProperty)); - if (theDefinition.m_Type == DataModelDataType::Long4) { - SValue theDCValue; - if (theDataCore->GetInstancePropertyValue(theInstance, theProperty, - theDCValue)) { - SLong4 thePropGuid = get<SLong4>(theDCValue); - if (thePropGuid == theGuid) - theIsMatch = true; - } - Qt3DSDMSlideHandle theSlide = - theSlideSystem->GetAssociatedSlide(theChildInstance); - Qt3DSDMSlideHandle theMasterSlide = theSlideSystem->GetMasterSlide(theSlide); - if (theIsMatch == false && theSlide.Valid() - && theSlideCore->GetSpecificInstancePropertyValue( - theSlide, theInstance, theProperty, theValue)) { - SLong4 thePropGuid = get<SLong4>(theValue); - if (thePropGuid == theGuid) - theIsMatch = true; - } - } - if (theIsMatch) { - theSlotCursor = theSlotIndex; - break; - } - } - } - if (theSlotCursor != (size_t)-1) { - Qt3DSDMPropertyHandle theImageProperty = - thePropertySystem->GetAggregateInstancePropertyByName( - m_DataHandle, std::get<0>(m_ImageNameFormalNamePairs[theSlotCursor])); - return GetOrCreateImageBinding( - theImageProperty, - std::get<1>(m_ImageNameFormalNamePairs[theSlotCursor]).wide_str()); - } else - return m_TransMgr->GetOrCreate(theChildInstance); +QList<ITimelineItemBinding *> CLayerTimelineItemBinding::GetChildren() +{ + QList<ITimelineItemBinding *> retlist; + qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance(); + if (theInstance.Valid()) { + Q3DStudio::CGraphIterator theChildren; + Qt3DSDMSlideHandle theActiveSlide = m_TransMgr->GetDoc()->GetActiveSlide(); + GetAssetChildrenInTimeParent(theInstance, m_TransMgr->GetDoc(), AmITimeParent(), + theChildren, theActiveSlide); + int childCount = int(theChildren.GetCount()); + retlist.reserve(childCount); + for (int i = 0; i < childCount; ++i) { + retlist.append(GetOrCreateBinding(theChildren.GetCurrent())); + ++theChildren; } } - return nullptr; + + return retlist; } void CLayerTimelineItemBinding::OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance) @@ -315,3 +267,71 @@ CLayerTimelineItemBinding::GetOrCreateImageBinding(qt3dsdm::Qt3DSDMPropertyHandl } return theImageTimelineRow; } + +ITimelineItemBinding *CLayerTimelineItemBinding::GetOrCreateBinding(Qt3DSDMInstanceHandle instance) +{ + if (instance.Valid()) { + qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance(); + qt3dsdm::IPropertySystem *thePropertySystem = + m_TransMgr->GetStudioSystem()->GetPropertySystem(); + std::shared_ptr<IDataCore> theDataCore = + m_TransMgr->GetStudioSystem()->GetFullSystem()->GetCoreSystem()->GetDataCore(); + ISlideSystem *theSlideSystem = m_TransMgr->GetStudioSystem()->GetSlideSystem(); + ISlideCore *theSlideCore = m_TransMgr->GetStudioSystem()->GetSlideCore(); + + size_t theSlotCursor = (size_t)-1; + { + qt3dsdm::IPropertySystem *thePropertySystem = + m_TransMgr->GetStudioSystem()->GetPropertySystem(); + qt3dsdm::SLong4 theGuid; + { + Qt3DSDMPropertyHandle theTypeProperty = + thePropertySystem->GetAggregateInstancePropertyByName(instance, L"id"); + SValue theIdValue; + thePropertySystem->GetInstancePropertyValue(instance, theTypeProperty, theIdValue); + theGuid = qt3dsdm::get<qt3dsdm::SLong4>(theIdValue); + } + for (size_t theSlotIndex = 0, theSlotCount = m_ImageNameFormalNamePairs.size(); + theSlotIndex < theSlotCount; ++theSlotIndex) { + bool theIsMatch = false; + qt3dsdm::Qt3DSDMPropertyHandle theProperty = + std::get<2>(m_ImageNameFormalNamePairs[theSlotIndex]); + SValue theValue; + const Qt3DSDMPropertyDefinition &theDefinition( + theDataCore->GetProperty(theProperty)); + if (theDefinition.m_Type == DataModelDataType::Long4) { + SValue theDCValue; + if (theDataCore->GetInstancePropertyValue(theInstance, theProperty, + theDCValue)) { + SLong4 thePropGuid = get<SLong4>(theDCValue); + if (thePropGuid == theGuid) + theIsMatch = true; + } + Qt3DSDMSlideHandle theSlide = + theSlideSystem->GetAssociatedSlide(instance); + Qt3DSDMSlideHandle theMasterSlide = theSlideSystem->GetMasterSlide(theSlide); + if (theIsMatch == false && theSlide.Valid() + && theSlideCore->GetSpecificInstancePropertyValue( + theSlide, theInstance, theProperty, theValue)) { + SLong4 thePropGuid = get<SLong4>(theValue); + if (thePropGuid == theGuid) + theIsMatch = true; + } + } + if (theIsMatch) { + theSlotCursor = theSlotIndex; + break; + } + } + } + if (theSlotCursor != (size_t)-1) { + Qt3DSDMPropertyHandle theImageProperty = + thePropertySystem->GetAggregateInstancePropertyByName( + m_DataHandle, std::get<0>(m_ImageNameFormalNamePairs[theSlotCursor])); + return GetOrCreateImageBinding( + theImageProperty, + std::get<1>(m_ImageNameFormalNamePairs[theSlotCursor]).wide_str()); + } else + return m_TransMgr->GetOrCreate(instance); + } +} diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h index 3d74625e..74630a64 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h @@ -64,6 +64,7 @@ public: // Qt3DSDMTimelineItemBinding EStudioObjectType GetObjectType() const override; // Hierarchy ITimelineItemBinding *GetChild(long inIndex) override; + QList<ITimelineItemBinding *> GetChildren() override; void OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance) override; // Event callback void OnPropertyChanged(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle) override; @@ -72,6 +73,7 @@ protected: qt3dsdm::Qt3DSDMInstanceHandle GetImage(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle); ITimelineItemBinding *GetOrCreateImageBinding(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle, const wchar_t *inName); + ITimelineItemBinding *GetOrCreateBinding(qt3dsdm::Qt3DSDMInstanceHandle instance); }; #endif // INCLUDED_LAYER_TIMELINEITEM_BINDING_H diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp index 0d4bfde5..55598353 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp @@ -160,6 +160,17 @@ ITimelineItemBinding *CMaterialTimelineItemBinding::GetChild(long inIndex) theImageProperty, std::get<1>(m_ImageNameFormalNamePairs[theSlotCursor]).wide_str()); } +QList<ITimelineItemBinding *> CMaterialTimelineItemBinding::GetChildren() +{ + int childCount = GetChildrenCount(); + QList<ITimelineItemBinding *> retlist; + retlist.reserve(childCount); + for (int i = 0; i < childCount; ++i) + retlist.append(GetChild(i)); + + return retlist; +} + void CMaterialTimelineItemBinding::OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance) { using namespace qt3dsdm; diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h index 252363e2..80e7bc47 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h @@ -69,6 +69,7 @@ public: // Qt3DSDMTimelineItemBinding // Hierarchy long GetChildrenCount() override; ITimelineItemBinding *GetChild(long inIndex) override; + QList<ITimelineItemBinding *> GetChildren() override; void OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance) override; // Event callback void OnPropertyChanged(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle) override; diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp index dd2989fa..9592b8ba 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp @@ -180,13 +180,10 @@ void ToggleChildrenLock(Q3DStudio::ScopedDocumentEditor &scopedDocEditor, { scopedDocEditor->SetInstancePropertyValue(inTimelineItemBinding->GetInstanceHandle(), inSceneAsset.m_Locked, inLocked); - long childrenCount = inTimelineItemBinding->GetChildrenCount(); - if (childrenCount == 0) - return; - for (long i = 0; i < childrenCount; ++i) { - Qt3DSDMTimelineItemBinding *child = - static_cast<Qt3DSDMTimelineItemBinding *>(inTimelineItemBinding->GetChild(i)); - ToggleChildrenLock(scopedDocEditor, child, inSceneAsset, inLocked); + const QList<ITimelineItemBinding *> children = inTimelineItemBinding->GetChildren(); + for (auto child : children) { + ToggleChildrenLock(scopedDocEditor, static_cast<Qt3DSDMTimelineItemBinding *>(child), + inSceneAsset, inLocked); } } @@ -466,6 +463,29 @@ ITimelineItemBinding *Qt3DSDMTimelineItemBinding::GetChild(long inIndex) return nullptr; } +QList<ITimelineItemBinding *> Qt3DSDMTimelineItemBinding::GetChildren() +{ + QList<ITimelineItemBinding *> retlist; + qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance(); + if (theInstance.Valid()) { + Q3DStudio::CGraphIterator theChildren; + Qt3DSDMSlideHandle theActiveSlide = m_TransMgr->GetDoc()->GetActiveSlide(); + GetAssetChildrenInTimeParent(theInstance, m_TransMgr->GetDoc(), AmITimeParent(), + theChildren, theActiveSlide); + int childCount = int(theChildren.GetCount()); + retlist.reserve(childCount); + + for (int i = 0; i < childCount; ++i) { + qt3dsdm::Qt3DSDMInstanceHandle theChildInstance = theChildren.GetCurrent(); + if (theChildInstance.Valid()) + retlist.append(m_TransMgr->GetOrCreate(theChildInstance)); + ++theChildren; + } + } + + return retlist; +} + ITimelineItemBinding *Qt3DSDMTimelineItemBinding::GetParent() { return m_Parent; @@ -890,11 +910,10 @@ void Qt3DSDMTimelineItemBinding::RefreshStateRow(bool inRefreshChildren) theRow->OnTimeChange(); theRow->setDirty(false); if (inRefreshChildren) { - long theChildrenCount = GetChildrenCount(); - for (long theIndex = 0; theIndex < theChildrenCount; ++theIndex) { - ITimelineItemBinding *theChild = GetChild(theIndex); + const QList<ITimelineItemBinding *> children = GetChildren(); + for (auto child : children) { Qt3DSDMTimelineItemBinding *theBinding = - dynamic_cast<Qt3DSDMTimelineItemBinding *>(theChild); + static_cast<Qt3DSDMTimelineItemBinding *>(child); if (theBinding) theBinding->RefreshStateRow(inRefreshChildren); } diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h index b79d1a96..2e253fbe 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h @@ -135,6 +135,7 @@ public: // Hierarchy long GetChildrenCount() override; ITimelineItemBinding *GetChild(long inIndex) override; + QList<ITimelineItemBinding *> GetChildren() override; ITimelineItemBinding *GetParent() override; void SetParent(ITimelineItemBinding *parent) override; // Properties diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp index 6cba83c2..18bdfc72 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowManager.cpp @@ -121,8 +121,9 @@ void RowManager::createRowsFromBindingRecursive(ITimelineItemBinding *binding, R { RowTree *newRow = createRowFromBinding(binding, parentRow); // create child rows recursively - for (int i = 0; i < binding->GetChildrenCount(); i++) - createRowsFromBindingRecursive(binding->GetChild(i), newRow); + const QList<ITimelineItemBinding *> children = binding->GetChildren(); + for (auto child : children) + createRowsFromBindingRecursive(child, newRow); } RowTree *RowManager::getOrCreatePropertyRow(RowTree *masterRow, const QString &propType, int index) diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.cpp index 01ed11a9..d56b7f46 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineWidget.cpp @@ -96,8 +96,9 @@ void printBinding(ITimelineItemBinding *binding, QString padding = " ") padding = padding.append("-"); // create child rows recursively - for (int i = 0; i < binding->GetChildrenCount(); i++) - printBinding(binding->GetChild(i), padding); + const QList<ITimelineItemBinding *> children = binding->GetChildren(); + for (auto child : children) + printBinding(child, padding); } // Mahmoud_TODO: debug func, to be removed @@ -430,10 +431,9 @@ void TimelineWidget::insertToHandlesMapRecursive(Qt3DSDMTimelineItemBinding *bin if (binding->GetObjectType() != OBJTYPE_MATERIAL) { m_handlesMap.insert(std::make_pair(binding->GetInstance(), binding->getRowTree())); - for (int i = 0; i < binding->GetChildrenCount(); i++) { - insertToHandlesMapRecursive( - static_cast<Qt3DSDMTimelineItemBinding *>(binding->GetChild(i))); - } + const QList<ITimelineItemBinding *> children = binding->GetChildren(); + for (auto child : children) + insertToHandlesMapRecursive(static_cast<Qt3DSDMTimelineItemBinding *>(child)); } } @@ -587,15 +587,18 @@ void TimelineWidget::onPropertyChanged(qt3dsdm::Qt3DSDMInstanceHandle inInstance { const SDataModelSceneAsset &asset = g_StudioApp.GetCore()->GetDoc()->GetStudioSystem() ->GetClientDataModelBridge()->GetSceneAsset(); - if (inProperty == asset.m_Eyeball || inProperty == asset.m_Locked || inProperty == asset.m_Shy - || inProperty == asset.m_StartTime || inProperty == asset.m_EndTime) { + const bool filterProperty = inProperty == asset.m_Eyeball || inProperty == asset.m_Locked + || inProperty == asset.m_Shy; + const bool timeProperty = inProperty == asset.m_StartTime || inProperty == asset.m_EndTime; + if (filterProperty || timeProperty) { Qt3DSDMTimelineItemBinding *binding = getBindingForHandle(inInstance, m_binding); if (binding) { - binding->OnPropertyChanged(inProperty); RowTree *row = binding->getRowTree(); if (row) { - row->rowTimeline()->updateDurationFromBinding(); - row->updateFromBinding(); + if (timeProperty) + row->rowTimeline()->updateDurationFromBinding(); + if (filterProperty) + row->updateFromBinding(); } } } @@ -743,9 +746,10 @@ Qt3DSDMTimelineItemBinding *TimelineWidget::getBindingForHandle(int handle, if (binding->GetInstance().GetHandleValue() == handle) return binding; - for (int i = 0; i < binding->GetChildrenCount(); i++) { + const QList<ITimelineItemBinding *> children = binding->GetChildren(); + for (auto child : children) { Qt3DSDMTimelineItemBinding *b = getBindingForHandle(handle, - static_cast<Qt3DSDMTimelineItemBinding *>(binding->GetChild(i))); + static_cast<Qt3DSDMTimelineItemBinding *>(child)); if (b) return b; |