Skip to content
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

Fix log playback for particle emitters #745

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/systems/log/LogPlayback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "ignition/gazebo/components/Geometry.hh"
#include "ignition/gazebo/components/LogPlaybackStatistics.hh"
#include "ignition/gazebo/components/Material.hh"
#include "ignition/gazebo/components/ParticleEmitter.hh"
#include "ignition/gazebo/components/Pose.hh"
#include "ignition/gazebo/components/World.hh"

Expand Down Expand Up @@ -124,6 +125,9 @@ class ignition::gazebo::systems::LogPlaybackPrivate
/// \brief Saves which entity poses have changed according to the latest
/// LogPlaybackPrivate::Parse call.
public: std::unordered_map<Entity, msgs::Pose> recentEntityPoseUpdates;

// \brief Saves which particle emitter emitting components have changed
public: std::unordered_map<Entity, bool> prevParticleEmitterCmds;
};

bool LogPlaybackPrivate::started{false};
Expand Down Expand Up @@ -636,6 +640,31 @@ void LogPlayback::Update(const UpdateInfo &_info, EntityComponentManager &_ecm)
return true;
});

// particle emitters
_ecm.Each<components::ParticleEmitterCmd>(
[&](const Entity &_entity,
const components::ParticleEmitterCmd *_emitter) -> bool
{
if (this->dataPtr->prevParticleEmitterCmds.find(_entity) ==
this->dataPtr->prevParticleEmitterCmds.end())
{
this->dataPtr->prevParticleEmitterCmds[_entity]
= _emitter->Data().emitting().data();
return true;
}

if (this->dataPtr->prevParticleEmitterCmds[_entity] !=
_emitter->Data().emitting().data())
{
this->dataPtr->prevParticleEmitterCmds[_entity]
= _emitter->Data().emitting().data();
_ecm.SetChanged(_entity, components::ParticleEmitterCmd::typeId,
ComponentState::OneTimeChange);
}

return true;
});

// for seek back in time only
// remove entities that should not be present in the current time step
for (auto entity : entitiesToRemove)
Expand Down