osrf / gazebo_experimental

Repo for Gazebo 9 development. Starting from entity_component_system_prototype branch on gazebo repo. This repo will be merged back into the gazebo repo in the future.
0 stars 1 forks source link

Add method to check if component changed since last time step #2

Closed osrf-migration closed 7 years ago

osrf-migration commented 7 years ago

Original report (archived issue) by Shane Loretz (Bitbucket: Shane Loretz, GitHub: sloretz).


Currently a system can query entities that have all required components. It gets a list of EntityId that match. This proposal is to add a way to see if a component on an entity has changed since the last update. It would mean :

The purpose is to enable a system to update its internal state only if there have been changes. For example, a physics system would only change the shape of an object if the shape changed, or stop simulating a body if the component describing it was removed.

Example

#!c++

void MySystemUpdate(const EntityQuery &_query)
{
  for (EntityId id : _query->EntityIds())
  {
    auto e = manager->Entity(id);
    switch (e.IsDifferent<components::WorldPose>())
      {
        case WAS_CREATED:
          // add thing
          break;
        case WAS_DELETED:
          // add thing
          break;
        case WAS_MODIFIED:
          // add thing
          break;
         default: break;
      }
      // ...
      if (needsChanging)
      {
        auto p = e.ComponentMutable<components::worldPose>();
        // ...  Do changes
      }
      else
      {
        auto p = e.Component<components::WorldPose>();
        // ... read only access to component
      }
  }
}
osrf-migration commented 7 years ago

Original comment by Shane Loretz (Bitbucket: Shane Loretz, GitHub: sloretz).


Created and modified are in pull request #7. I changed the name of WasModified() to IsDifferent(), and WAS_CHANGED to WAS_MODIFIED.

osrf-migration commented 7 years ago

Original comment by Shane Loretz (Bitbucket: Shane Loretz, GitHub: sloretz).


osrf-migration commented 7 years ago

Original comment by Shane Loretz (Bitbucket: Shane Loretz, GitHub: sloretz).


osrf-migration commented 7 years ago

Original comment by Shane Loretz (Bitbucket: Shane Loretz, GitHub: sloretz).


Fixed in pull request #7