Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a834b4b1d49c
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 97dce1eb58de
Choose a head ref
  • 4 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 20, 2020

  1. Add new map.

    pleroy committed Jan 20, 2020
    Copy the full SHA
    1585b4d View commit details
  2. Serialization of the zombies.

    pleroy committed Jan 20, 2020
    Copy the full SHA
    cbd2b26 View commit details

Commits on Jan 21, 2020

  1. After egg's review.

    pleroy committed Jan 21, 2020
    Copy the full SHA
    7bf8b3e View commit details
  2. Merge pull request #2455 from pleroy/2443

    Keep the prediction parameters of the vessels that have disappeared
    pleroy authored Jan 21, 2020
    Copy the full SHA
    97dce1e View commit details
Showing with 40 additions and 10 deletions.
  1. +23 −5 ksp_plugin/plugin.cpp
  2. +7 −0 ksp_plugin/plugin.hpp
  3. +10 −5 serialization/ksp_plugin.proto
28 changes: 23 additions & 5 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -370,20 +370,28 @@ void Plugin::InsertOrKeepVessel(GUID const& vessel_guid,
CHECK(!initializing_);
not_null<Celestial const*> parent =
FindOrDie(celestials_, parent_index).get();
auto it = vessels_.find(vessel_guid);
if (it == vessels_.end()) {
std::tie(it, inserted) =
auto vit = vessels_.find(vessel_guid);
if (vit == vessels_.end()) {
// Restore the zombie parameters if we have some, otherwise use the default.
auto prediction_parameters = DefaultPredictionParameters();
auto const pit =
zombie_prediction_adaptive_step_parameters_.find(vessel_guid);
if (pit != zombie_prediction_adaptive_step_parameters_.end()) {
prediction_parameters = pit->second;
zombie_prediction_adaptive_step_parameters_.erase(pit);
}
std::tie(vit, inserted) =
vessels_.emplace(
vessel_guid,
make_not_null_unique<Vessel>(vessel_guid,
vessel_name,
parent,
ephemeris_.get(),
DefaultPredictionParameters()));
prediction_parameters));
} else {
inserted = false;
}
not_null<Vessel*> const vessel = it->second.get();
not_null<Vessel*> const vessel = vit->second.get();
if (vessel->name() != vessel_name) {
vessel->set_name(vessel_name);
}
@@ -538,6 +546,8 @@ void Plugin::FreeVesselsAndPartsAndCollectPileUps(Time const& Δt) {
loaded_vessels_.erase(vessel);
LOG(INFO) << "Removing vessel " << vessel->ShortDebugString();
renderer_->ClearTargetVesselIf(vessel);
zombie_prediction_adaptive_step_parameters_.insert_or_assign(
vessel->guid(), vessel->prediction_adaptive_step_parameters());
it = vessels_.erase(it);
}
}
@@ -579,6 +589,8 @@ void Plugin::FreeVesselsAndPartsAndCollectPileUps(Time const& Δt) {
loaded_vessels_.erase(vessel);
LOG(INFO) << "Removing grounded vessel " << vessel->ShortDebugString();
renderer_->ClearTargetVesselIf(vessel);
zombie_prediction_adaptive_step_parameters_.insert_or_assign(
vessel->guid(), vessel->prediction_adaptive_step_parameters());
CHECK_EQ(vessels_.erase(vessel->guid()), 1);
}
}
@@ -1272,6 +1284,12 @@ void Plugin::WriteToMessage(
not_null<Vessel*> const vessel = pair.second;
(*message->mutable_part_id_to_vessel())[part_id] = vessel_to_guid[vessel];
}
for (auto const& [guid, parameters] :
zombie_prediction_adaptive_step_parameters_) {
auto* const zombie_message = message->add_zombie();
zombie_message->set_guid(guid);
parameters.WriteToMessage(zombie_message->mutable_prediction_parameters());
}

ephemeris_->WriteToMessage(message->mutable_ephemeris());

7 changes: 7 additions & 0 deletions ksp_plugin/plugin.hpp
Original file line number Diff line number Diff line change
@@ -527,6 +527,13 @@ class Plugin {
VesselSet loaded_vessels_;
// The vessels that will be kept during the next call to |AdvanceTime|.
VesselConstSet kept_vessels_;
// Contains the adaptive step parameters for the vessel that existed in the
// past but are no longer known to the plugin. Useful to avoid losing the
// parameters, e.g., when a vessel hits the ground.
// NOTE(phl): This is a leaky map, in the sense that we don't remove deleted
// vessels from it. Hopefully it's small enough that we don't care.
std::map<GUID, Ephemeris<Barycentric>::AdaptiveStepParameters>
zombie_prediction_adaptive_step_parameters_;

friend class NavballFrameField;
friend class TestablePlugin;
15 changes: 10 additions & 5 deletions serialization/ksp_plugin.proto
Original file line number Diff line number Diff line change
@@ -91,6 +91,12 @@ message PileUp {
}

message Plugin {
message CelestialParenthood {
required int32 index = 1;
optional int32 parent_index = 2;
// Added in Catalan.
optional int32 ephemeris_index = 3;
}
message VesselAndProperties {
required string guid = 1;
required Vessel vessel = 2;
@@ -101,11 +107,9 @@ message Plugin {
reserved 4;
reserved "dirty";
}
message CelestialParenthood {
required int32 index = 1;
optional int32 parent_index = 2;
// Added in Catalan.
optional int32 ephemeris_index = 3;
message ZombieAndProperties {
required string guid = 1;
required Ephemeris.AdaptiveStepParameters prediction_parameters = 2;
}
repeated VesselAndProperties vessel = 1;
map<fixed32, string> part_id_to_vessel = 16;
@@ -120,6 +124,7 @@ message Plugin {
optional DynamicFrame pre_cauchy_plotting_frame = 11;
repeated PileUp pile_up = 17;
optional Renderer renderer = 18; // Added in Cauchy.
repeated ZombieAndProperties zombie = 19; // Added in Frege.

// Pre-Cardano.
reserved 3;