diff --git a/rmf_traffic/include/rmf_traffic/schedule/Participant.hpp b/rmf_traffic/include/rmf_traffic/schedule/Participant.hpp index bae9b2e5..950e3de8 100644 --- a/rmf_traffic/include/rmf_traffic/schedule/Participant.hpp +++ b/rmf_traffic/include/rmf_traffic/schedule/Participant.hpp @@ -100,6 +100,9 @@ class Participant // TODO(MXG): This function needs to be unit tested. ItineraryVersion version() const; + /// Get the current progress version for this participant. + ProgressVersion progress_version() const; + /// Get the description of this participant. const ParticipantDescription& description() const; diff --git a/rmf_traffic/src/rmf_traffic/schedule/Database.cpp b/rmf_traffic/src/rmf_traffic/schedule/Database.cpp index 35db7448..3f6dd48c 100644 --- a/rmf_traffic/src/rmf_traffic/schedule/Database.cpp +++ b/rmf_traffic/src/rmf_traffic/schedule/Database.cpp @@ -1488,10 +1488,10 @@ auto Database::changes( } std::vector part_patches; - for (const auto& p : changes) + for (const auto p : _pimpl->participant_ids) { - const auto& changeset = p.second; - const auto& state = _pimpl->states.at(p.first); + const auto& changeset = changes[p]; + const auto& state = _pimpl->states.at(p); std::vector delays; for (const auto& d : changeset.delays) @@ -1502,15 +1502,6 @@ auto Database::changes( }); } - if (changeset.erasures.empty() - && delays.empty() - && changeset.additions.empty()) - { - // There aren't actually any changes for this participant, so we will - // leave it out of the patch. - continue; - } - std::optional progress; if (state.schedule_version_of_progress.has_value()) { @@ -1522,13 +1513,23 @@ auto Database::changes( } } + if (changeset.erasures.empty() + && delays.empty() + && changeset.additions.empty() + && !progress.has_value()) + { + // There aren't actually any changes for this participant, so we will + // leave it out of the patch. + continue; + } + part_patches.emplace_back( Patch::Participant{ - p.first, + p, state.tracker->last_known_version(), - Change::Erase(std::move(p.second.erasures)), + Change::Erase(std::move(changeset.erasures)), std::move(delays), - Change::Add(state.latest_plan_id, std::move(p.second.additions)), + Change::Add(state.latest_plan_id, std::move(changeset.additions)), std::move(progress) }); } diff --git a/rmf_traffic/src/rmf_traffic/schedule/Participant.cpp b/rmf_traffic/src/rmf_traffic/schedule/Participant.cpp index 2743a792..ffdd4695 100644 --- a/rmf_traffic/src/rmf_traffic/schedule/Participant.cpp +++ b/rmf_traffic/src/rmf_traffic/schedule/Participant.cpp @@ -482,6 +482,12 @@ ItineraryVersion Participant::version() const return _pimpl->_shared->_version; } +//============================================================================== +ProgressVersion Participant::progress_version() const +{ + return _pimpl->_shared->_progress.version; +} + //============================================================================== const ParticipantDescription& Participant::description() const {