From 3b19068349297175c15f45b6972a76af7555e2cb Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Mon, 11 Jan 2021 15:42:11 +0800 Subject: [PATCH 1/5] Publish all periodic change components in Scene Broadcaster Signed-off-by: Luca Della Vedova --- include/ignition/gazebo/EntityComponentManager.hh | 6 ++++++ src/EntityComponentManager.cc | 12 ++++++++++++ src/systems/scene_broadcaster/SceneBroadcaster.cc | 5 +++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/ignition/gazebo/EntityComponentManager.hh b/include/ignition/gazebo/EntityComponentManager.hh index bc99cf7eb1..5a90552eda 100644 --- a/include/ignition/gazebo/EntityComponentManager.hh +++ b/include/ignition/gazebo/EntityComponentManager.hh @@ -487,6 +487,12 @@ namespace ignition /// \return True if there are any components with one-time changes. public: bool HasOneTimeComponentChanges() const; + /// \brief Get the components that are marked as periodic changes. + /// \return All the components that at least one entity marked as + /// periodic changes. + public: std::unordered_set + GetPeriodicChangedComponents() const; + /// \brief Set the absolute state of the ECM from a serialized message. /// Entities / components that are in the new state but not in the old /// one will be created. diff --git a/src/EntityComponentManager.cc b/src/EntityComponentManager.cc index 9946ccbaf8..2541a8dfc6 100644 --- a/src/EntityComponentManager.cc +++ b/src/EntityComponentManager.cc @@ -396,6 +396,18 @@ bool EntityComponentManager::HasOneTimeComponentChanges() const return !this->dataPtr->oneTimeChangedComponents.empty(); } +///////////////////////////////////////////////// +std::unordered_set + EntityComponentManager::GetPeriodicChangedComponents() const +{ + std::unordered_set periodicComponents; + for (const auto& compPair : this->dataPtr->periodicChangedComponents) + { + periodicComponents.insert(compPair.first); + } + return periodicComponents; +} + ///////////////////////////////////////////////// bool EntityComponentManager::HasEntity(const Entity _entity) const { diff --git a/src/systems/scene_broadcaster/SceneBroadcaster.cc b/src/systems/scene_broadcaster/SceneBroadcaster.cc index 9dde20341b..3f26514143 100644 --- a/src/systems/scene_broadcaster/SceneBroadcaster.cc +++ b/src/systems/scene_broadcaster/SceneBroadcaster.cc @@ -293,12 +293,13 @@ void SceneBroadcaster::PostUpdate(const UpdateInfo &_info, { _manager.State(*this->dataPtr->stepMsg.mutable_state(), {}, {}, true); } - // Otherwise publish just selected components + // Otherwise publish just periodic change components else { IGN_PROFILE("SceneBroadcast::PostUpdate UpdateState"); + auto periodicComponents = _manager.GetPeriodicChangedComponents(); _manager.State(*this->dataPtr->stepMsg.mutable_state(), - {}, {components::Pose::typeId}); + {}, periodicComponents); } // Full state on demand From 80ecacbb54597928ac00f76d3da357a641c866c0 Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Mon, 18 Jan 2021 10:03:58 +0800 Subject: [PATCH 2/5] Address feedback on function name Signed-off-by: Luca Della Vedova --- include/ignition/gazebo/EntityComponentManager.hh | 4 ++-- src/EntityComponentManager.cc | 2 +- src/systems/scene_broadcaster/SceneBroadcaster.cc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ignition/gazebo/EntityComponentManager.hh b/include/ignition/gazebo/EntityComponentManager.hh index 5a90552eda..326cdb1b8d 100644 --- a/include/ignition/gazebo/EntityComponentManager.hh +++ b/include/ignition/gazebo/EntityComponentManager.hh @@ -487,11 +487,11 @@ namespace ignition /// \return True if there are any components with one-time changes. public: bool HasOneTimeComponentChanges() const; - /// \brief Get the components that are marked as periodic changes. + /// \brief Get the components types that are marked as periodic changes. /// \return All the components that at least one entity marked as /// periodic changes. public: std::unordered_set - GetPeriodicChangedComponents() const; + ComponentTypesWithPeriodicChanges() const; /// \brief Set the absolute state of the ECM from a serialized message. /// Entities / components that are in the new state but not in the old diff --git a/src/EntityComponentManager.cc b/src/EntityComponentManager.cc index 2541a8dfc6..27a31d28f0 100644 --- a/src/EntityComponentManager.cc +++ b/src/EntityComponentManager.cc @@ -398,7 +398,7 @@ bool EntityComponentManager::HasOneTimeComponentChanges() const ///////////////////////////////////////////////// std::unordered_set - EntityComponentManager::GetPeriodicChangedComponents() const + EntityComponentManager::ComponentTypesWithPeriodicChanges() const { std::unordered_set periodicComponents; for (const auto& compPair : this->dataPtr->periodicChangedComponents) diff --git a/src/systems/scene_broadcaster/SceneBroadcaster.cc b/src/systems/scene_broadcaster/SceneBroadcaster.cc index 3f26514143..722d8f58ac 100644 --- a/src/systems/scene_broadcaster/SceneBroadcaster.cc +++ b/src/systems/scene_broadcaster/SceneBroadcaster.cc @@ -297,7 +297,7 @@ void SceneBroadcaster::PostUpdate(const UpdateInfo &_info, else { IGN_PROFILE("SceneBroadcast::PostUpdate UpdateState"); - auto periodicComponents = _manager.GetPeriodicChangedComponents(); + auto periodicComponents = _manager.ComponentTypesWithPeriodicChanges(); _manager.State(*this->dataPtr->stepMsg.mutable_state(), {}, periodicComponents); } From 931d58adaaa9ffddb6cce0dd35a7176c96b32893 Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Wed, 20 Jan 2021 17:49:47 +0800 Subject: [PATCH 3/5] Added unit test Signed-off-by: Luca Della Vedova --- src/EntityComponentManager_TEST.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/EntityComponentManager_TEST.cc b/src/EntityComponentManager_TEST.cc index a58a056e63..7e83d7de8b 100644 --- a/src/EntityComponentManager_TEST.cc +++ b/src/EntityComponentManager_TEST.cc @@ -2082,6 +2082,7 @@ TEST_P(EntityComponentManagerFixture, SetChanged) auto c2 = manager.CreateComponent(e2, IntComponent(456)); EXPECT_TRUE(manager.HasOneTimeComponentChanges()); + EXPECT_EQ(0u, manager.ComponentTypesWithPeriodicChanges().size()); EXPECT_EQ(ComponentState::OneTimeChange, manager.ComponentState(e1, c1.first)); EXPECT_EQ(ComponentState::OneTimeChange, @@ -2093,6 +2094,7 @@ TEST_P(EntityComponentManagerFixture, SetChanged) // updated manager.RunSetAllComponentsUnchanged(); EXPECT_FALSE(manager.HasOneTimeComponentChanges()); + EXPECT_EQ(0u, manager.ComponentTypesWithPeriodicChanges().size()); EXPECT_EQ(ComponentState::NoChange, manager.ComponentState(e1, c1.first)); EXPECT_EQ(ComponentState::NoChange, @@ -2103,6 +2105,9 @@ TEST_P(EntityComponentManagerFixture, SetChanged) manager.SetChanged(e2, c2.first, ComponentState::OneTimeChange); EXPECT_TRUE(manager.HasOneTimeComponentChanges()); + // Expect a single component type to be marked as PeriodicChange + ASSERT_EQ(1u, manager.ComponentTypesWithPeriodicChanges().size()); + EXPECT_EQ(IntComponent().TypeId(), *manager.ComponentTypesWithPeriodicChanges().begin()); EXPECT_EQ(ComponentState::PeriodicChange, manager.ComponentState(e1, c1.first)); EXPECT_EQ(ComponentState::OneTimeChange, @@ -2112,6 +2117,7 @@ TEST_P(EntityComponentManagerFixture, SetChanged) EXPECT_TRUE(manager.RemoveComponent(e1, c1.first)); EXPECT_TRUE(manager.HasOneTimeComponentChanges()); + EXPECT_EQ(0u, manager.ComponentTypesWithPeriodicChanges().size()); EXPECT_EQ(ComponentState::NoChange, manager.ComponentState(e1, c1.first)); From c7be702e3baa95124f8607ba04e4e70387dd77dd Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Wed, 20 Jan 2021 17:56:44 +0800 Subject: [PATCH 4/5] Codecheck Signed-off-by: Luca Della Vedova --- src/EntityComponentManager_TEST.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EntityComponentManager_TEST.cc b/src/EntityComponentManager_TEST.cc index 7e83d7de8b..f2a881693d 100644 --- a/src/EntityComponentManager_TEST.cc +++ b/src/EntityComponentManager_TEST.cc @@ -2107,7 +2107,8 @@ TEST_P(EntityComponentManagerFixture, SetChanged) EXPECT_TRUE(manager.HasOneTimeComponentChanges()); // Expect a single component type to be marked as PeriodicChange ASSERT_EQ(1u, manager.ComponentTypesWithPeriodicChanges().size()); - EXPECT_EQ(IntComponent().TypeId(), *manager.ComponentTypesWithPeriodicChanges().begin()); + EXPECT_EQ(IntComponent().TypeId(), + *manager.ComponentTypesWithPeriodicChanges().begin()); EXPECT_EQ(ComponentState::PeriodicChange, manager.ComponentState(e1, c1.first)); EXPECT_EQ(ComponentState::OneTimeChange, From fcd662b62b3fd560b2ac433be1b3900c925908bf Mon Sep 17 00:00:00 2001 From: Luca Della Vedova Date: Thu, 21 Jan 2021 10:11:00 +0800 Subject: [PATCH 5/5] Address feedback (expand unit test) Signed-off-by: Luca Della Vedova --- src/EntityComponentManager_TEST.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/EntityComponentManager_TEST.cc b/src/EntityComponentManager_TEST.cc index f2a881693d..0ef3587247 100644 --- a/src/EntityComponentManager_TEST.cc +++ b/src/EntityComponentManager_TEST.cc @@ -2102,6 +2102,24 @@ TEST_P(EntityComponentManagerFixture, SetChanged) // Mark as changed manager.SetChanged(e1, c1.first, ComponentState::PeriodicChange); + + // check that only e1 c1 is serialized into a message + msgs::SerializedStateMap stateMsg; + manager.State(stateMsg); + { + ASSERT_EQ(1, stateMsg.entities_size()); + + auto iter = stateMsg.entities().find(e1); + const auto &e1Msg = iter->second; + EXPECT_EQ(e1, e1Msg.id()); + ASSERT_EQ(1, e1Msg.components_size()); + + auto compIter = e1Msg.components().begin(); + const auto &e1c1Msg = compIter->second; + EXPECT_EQ(IntComponent::typeId, e1c1Msg.type()); + EXPECT_EQ(123, std::stoi(e1c1Msg.component())); + } + manager.SetChanged(e2, c2.first, ComponentState::OneTimeChange); EXPECT_TRUE(manager.HasOneTimeComponentChanges());