From 949fb4f12e55afa3ccf72eb24a8b93e5b3a44e14 Mon Sep 17 00:00:00 2001 From: Jan Hanca Date: Wed, 13 Dec 2023 10:39:58 +0100 Subject: [PATCH] code review: add more comments Signed-off-by: Jan Hanca --- .../ROS2RobotImporterEditorSystemComponent.cpp | 4 ++-- .../ROS2RobotImporterEditorSystemComponent.h | 13 +++++++++---- .../Source/RobotImporter/URDF/URDFPrefabMaker.cpp | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.cpp b/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.cpp index 15aae8a75c..9cf025ff82 100644 --- a/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.cpp +++ b/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.cpp @@ -83,13 +83,13 @@ namespace ROS2 serializeContext->EnumerateAll( [&](const AZ::SerializeContext::ClassData* classData, const AZ::Uuid& typeId) -> bool { - return ParseAttributes(m_sensorHooks, classData, "SensorImporterHooks"); + return CopyHooksCallback(m_sensorHooks, classData, "SensorImporterHooks"); }); serializeContext->EnumerateAll( [&](const AZ::SerializeContext::ClassData* classData, const AZ::Uuid& typeId) -> bool { - return ParseAttributes( + return CopyHooksCallback( m_modelPluginHooks, classData, "ModelPluginImporterHooks"); }); } diff --git a/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.h b/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.h index 2e39084615..6c764189f6 100644 --- a/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.h +++ b/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.h @@ -47,14 +47,19 @@ namespace ROS2 const SDFormat::SensorImporterHooksStorage& GetSensorHooks() const override; const SDFormat::ModelPluginImporterHooksStorage& GetModelPluginHooks() const override; - // Method for parsing attributes used for both sensor importer hooks and model plugin importer hooks + //! Callback for finding hooks defined in class reflection for certain SerializeContext attribute. This callback should be used + //! with EnumerateAll method and it is meant to be called only once, as the search results are copied and can be reused. + //! @param outputBuffer output buffer where hooks are copied + //! @param classData serialization context in which queried attribute might exist. + //! @param attributeName name of the attribute used to store hooks. + //! @return true if not found; false if found (stop iterating) template - bool ParseAttributes(T& outputBuffer, const AZ::SerializeContext::ClassData* classData, const AZStd::string& attributeName) + bool CopyHooksCallback(T& outputBuffer, const AZ::SerializeContext::ClassData* classData, const AZStd::string& attributeName) { auto* attribute = AZ::FindAttribute(AZ::Crc32(attributeName.c_str()), classData->m_attributes); if (attribute == nullptr) { - return true; + return true; // attribute not found; keep iterating } AZ::AttributeReader reader(nullptr, attribute); @@ -64,7 +69,7 @@ namespace ROS2 outputBuffer.insert(outputBuffer.end(), readData.begin(), readData.end()); } - return false; + return false; // attribute found, hooks copied; stop iterating } // Timeout for loop waiting for assets to be built diff --git a/Gems/ROS2/Code/Source/RobotImporter/URDF/URDFPrefabMaker.cpp b/Gems/ROS2/Code/Source/RobotImporter/URDF/URDFPrefabMaker.cpp index c63719b8df..eadf5aa219 100644 --- a/Gems/ROS2/Code/Source/RobotImporter/URDF/URDFPrefabMaker.cpp +++ b/Gems/ROS2/Code/Source/RobotImporter/URDF/URDFPrefabMaker.cpp @@ -469,7 +469,7 @@ namespace ROS2 } } - // Use the first entity based on a link that is not parented to any other link + // Add control components to links that are not parented to any other link (first link of each model) based on SDFormat data. if (!linkEntityIdsWithoutParent.empty()) { for (const auto& [contentEntityId, modelPtr] : linkEntityIdsWithoutParent)