-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ECM's ChangedState gets message with modified components #742
Changes from 3 commits
0d10268
e6ffee0
b415c33
70c4320
a79e0cf
7fd5cb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,12 @@ class ignition::gazebo::EntityComponentManagerPrivate | |
msgs::SerializedStateMap &_msg, | ||
const std::unordered_set<ComponentTypeId> &_types = {}); | ||
|
||
/// \brief Add newly modified (created/modified/removed) components to | ||
/// modifiedComponents list. The entity is added to the list when it is not | ||
/// a newly created entity or is not an entity to be removed | ||
/// \param[in] _entity Entity that has component newly modified | ||
public: void AddModifiedComponent(const Entity &_entity); | ||
|
||
/// \brief Map of component storage classes. The key is a component | ||
/// type id, and the value is a pointer to the component storage. | ||
public: std::unordered_map<ComponentTypeId, | ||
|
@@ -93,6 +99,12 @@ class ignition::gazebo::EntityComponentManagerPrivate | |
/// \brief Entities that need to be removed. | ||
public: std::unordered_set<Entity> toRemoveEntities; | ||
|
||
/// \brief Entities that have components newly modified | ||
/// (created/modified/removed) but are not entities that have been | ||
/// newly created or removed (ie. newlyCreatedEntities or toRemoveEntities). | ||
/// This is used for the ChangedState functions | ||
public: std::unordered_set<Entity> modifiedComponents; | ||
|
||
/// \brief Flag that indicates if all entities should be removed. | ||
public: bool removeAllEntities{false}; | ||
|
||
|
@@ -199,6 +211,7 @@ void EntityComponentManager::ClearNewlyCreatedEntities() | |
{ | ||
std::lock_guard<std::mutex> lock(this->dataPtr->entityCreatedMutex); | ||
this->dataPtr->newlyCreatedEntities.clear(); | ||
this->dataPtr->modifiedComponents.clear(); | ||
|
||
for (auto &view : this->dataPtr->views) | ||
{ | ||
|
@@ -354,6 +367,8 @@ bool EntityComponentManager::RemoveComponent( | |
|
||
this->UpdateViews(_entity); | ||
|
||
this->dataPtr->AddModifiedComponent(_entity); | ||
|
||
// Add component to map of removed components | ||
{ | ||
std::lock_guard<std::mutex> lock(this->dataPtr->removedComponentsMutex); | ||
|
@@ -529,6 +544,8 @@ ComponentKey EntityComponentManager::CreateComponentImplementation( | |
} | ||
} | ||
|
||
this->dataPtr->AddModifiedComponent(_entity); | ||
|
||
// Instantiate the new component. | ||
std::pair<ComponentId, bool> componentIdPair = | ||
this->dataPtr->components[_componentTypeId]->Create(_data); | ||
|
@@ -1021,7 +1038,11 @@ ignition::msgs::SerializedState EntityComponentManager::ChangedState() const | |
this->AddEntityToMessage(stateMsg, entity); | ||
} | ||
|
||
// TODO(anyone) New / removed / changed components | ||
// New / removed / changed components | ||
for (const auto &entity : this->dataPtr->modifiedComponents) | ||
{ | ||
this->AddEntityToMessage(stateMsg, entity); | ||
} | ||
|
||
return stateMsg; | ||
} | ||
|
@@ -1042,7 +1063,11 @@ void EntityComponentManager::ChangedState( | |
this->AddEntityToMessage(_state, entity); | ||
} | ||
|
||
// TODO(anyone) New / removed / changed components | ||
// New / removed / changed components | ||
for (const auto &entity : this->dataPtr->modifiedComponents) | ||
{ | ||
this->AddEntityToMessage(_state, entity); | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
|
@@ -1257,6 +1282,7 @@ void EntityComponentManager::SetState( | |
// values. | ||
// igndbg << *comp << " " << *newComp.get() << std::endl; | ||
// *comp = *newComp.get(); | ||
this->dataPtr->AddModifiedComponent(entity); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this call needed here? Given that the above msg says internal error, I expect that something is wrong is it gets to this else block. Looking at the code, the component value is just being updated by removing the old component and creating a new one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not needed currently but I put the call there in case the above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, yeah you can comment it out and add a note here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 70c4320 |
||
} | ||
} | ||
} | ||
|
@@ -1367,6 +1393,7 @@ void EntityComponentManager::SetState( | |
} | ||
} | ||
this->SetChanged(entity, compIter.first, flag); | ||
this->dataPtr->AddModifiedComponent(entity); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, thanks 70c4320 |
||
} | ||
} | ||
} | ||
|
@@ -1433,6 +1460,8 @@ void EntityComponentManager::SetChanged( | |
this->dataPtr->periodicChangedComponents.erase(typeIter->second); | ||
this->dataPtr->oneTimeChangedComponents.erase(typeIter->second); | ||
} | ||
|
||
this->dataPtr->AddModifiedComponent(_entity); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
|
@@ -1465,3 +1494,19 @@ void EntityComponentManager::SetEntityCreateOffset(uint64_t _offset) | |
|
||
this->dataPtr->entityCount = _offset; | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void EntityComponentManagerPrivate::AddModifiedComponent(const Entity &_entity) | ||
{ | ||
if (this->newlyCreatedEntities.find(_entity) | ||
!= this->newlyCreatedEntities.end() || | ||
this->toRemoveEntities.find(_entity) != this->toRemoveEntities.end() || | ||
this->modifiedComponents.find(_entity) != this->modifiedComponents.end()) | ||
{ | ||
// modified component is already in newlyCreatedEntities | ||
// or toRemoveEntities list | ||
return; | ||
} | ||
|
||
this->modifiedComponents.insert(_entity); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this call be in
ClearNewlyCreatedEntities
or maybe it fits better inSetAllComponentsUnchanged
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to
SetAllComponentsUnchanged
70c4320