Skip to content

Commit

Permalink
fixed particle emitter forward playback (#745)
Browse files Browse the repository at this point in the history
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
  • Loading branch information
jennuine authored Apr 9, 2021
1 parent 9b24362 commit 0eb4514
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit 0eb4514

Please sign in to comment.