Skip to content

Commit

Permalink
Support spawning during log playback (#346)
Browse files Browse the repository at this point in the history
Signed-off-by: Nate Koenig <[email protected]>
  • Loading branch information
nkoenig authored Sep 11, 2020
1 parent 5c151bf commit fed09fc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
6 changes: 6 additions & 0 deletions include/ignition/gazebo/EntityComponentManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,12 @@ namespace ignition
const Entity _entity, const ComponentTypeId _type,
gazebo::ComponentState _c = ComponentState::OneTimeChange);

/// \brief All future entities will have an id that starts at _offset.
/// This can be used to avoid entity id collisions, such as during log
/// playback.
/// \param[in] _offset Offset value.
public: void SetEntityCreateOffset(uint64_t _offset);

/// \brief Mark all components as not changed.
protected: void SetAllComponentsUnchanged();

Expand Down
13 changes: 13 additions & 0 deletions src/EntityComponentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1224,3 +1224,16 @@ std::unordered_set<ComponentTypeId> EntityComponentManager::ComponentTypes(

return result;
}

/////////////////////////////////////////////////
void EntityComponentManager::SetEntityCreateOffset(uint64_t _offset)
{
if (_offset < this->dataPtr->entityCount)
{
ignwarn << "Setting an entity offset of [" << _offset << "] is less than "
<< "the current entity count of [" << this->dataPtr->entityCount << "]. "
<< "Incorrect behavior should be expected.\n";
}

this->dataPtr->entityCount = _offset;
}
13 changes: 13 additions & 0 deletions src/EntityComponentManager_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,19 @@ TEST_P(EntityComponentManagerFixture, SetChanged)
manager.ComponentState(e2, c2.first));
}

//////////////////////////////////////////////////
TEST_P(EntityComponentManagerFixture, SetEntityCreateOffset)
{
// First entity should have a value of 1.
Entity entity = manager.CreateEntity();
EXPECT_EQ(1u, entity);

// Apply an offset.
manager.SetEntityCreateOffset(1000);
Entity entity2 = manager.CreateEntity();
EXPECT_EQ(1001u, entity2);
}

// Run multiple times. We want to make sure that static globals don't cause
// problems.
INSTANTIATE_TEST_CASE_P(EntityComponentManagerRepeat,
Expand Down
11 changes: 7 additions & 4 deletions src/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ struct DefaultWorld
std::string("<plugin filename='libignition-gazebo") +
IGNITION_GAZEBO_MAJOR_VERSION_STR + "-scene-broadcaster-system.so' "
"name='ignition::gazebo::systems::SceneBroadcaster'></plugin>"
}};
},
{
std::string("<plugin filename='libignition-gazebo") +
IGNITION_GAZEBO_MAJOR_VERSION_STR + "-user-commands-system.so' " +
"name='ignition::gazebo::systems::UserCommands'></plugin>"
}
};

// The set of default gazebo plugins.
if (_config.LogPlaybackPath().empty())
{
pluginsV.push_back(std::string("<plugin filename='libignition-gazebo") +
IGNITION_GAZEBO_MAJOR_VERSION_STR + "-physics-system.so' "
"name='ignition::gazebo::systems::Physics'></plugin>");
pluginsV.push_back(std::string("<plugin filename='libignition-gazebo") +
IGNITION_GAZEBO_MAJOR_VERSION_STR + "-user-commands-system.so' " +
"name='ignition::gazebo::systems::UserCommands'></plugin>");
}

// Playback plugin
Expand Down
4 changes: 4 additions & 0 deletions src/systems/log/LogPlayback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ void LogPlayback::Configure(const Entity &,
// Prepend working directory if path is relative
this->dataPtr->logPath = common::absPath(this->dataPtr->logPath);

// Set the entity offset.
// \todo This number should be included in the log file.
_ecm.SetEntityCreateOffset(math::MAX_I64 / 2);

// If path is a file, assume it is a compressed file
// (Otherwise assume it is a directory containing recorded files.)
if (common::isFile(this->dataPtr->logPath))
Expand Down

0 comments on commit fed09fc

Please sign in to comment.