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: 8b337e791b72
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 57169e68d275
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 28, 2021

  1. Copy the full SHA
    22dbaa8 View commit details
  2. Merge pull request #3119 from pleroy/Deserialization

    Serialization and deserialization of vessel checkpoints
    pleroy authored Aug 28, 2021
    Copy the full SHA
    57169e6 View commit details
Showing with 27 additions and 10 deletions.
  1. +9 −2 ksp_plugin/vessel.cpp
  2. +17 −8 ksp_plugin_test/vessel_test.cpp
  3. +1 −0 serialization/ksp_plugin.proto
11 changes: 9 additions & 2 deletions ksp_plugin/vessel.cpp
Original file line number Diff line number Diff line change
@@ -473,6 +473,8 @@ void Vessel::WriteToMessage(not_null<serialization::Vessel*> const message,
if (flight_plan_ != nullptr) {
flight_plan_->WriteToMessage(message->mutable_flight_plan());
}
message->set_is_collapsible(is_collapsible_);
checkpointer_->WriteToMessage(message->mutable_checkpoint());
}

not_null<std::unique_ptr<Vessel>> Vessel::ReadFromMessage(
@@ -484,7 +486,7 @@ not_null<std::unique_ptr<Vessel>> Vessel::ReadFromMessage(
bool const is_pre_chasles = message.has_prediction();
bool const is_pre_陈景润 = !message.history().has_downsampling();
// TODO(phl): Decide in which version it goes.
bool const is_pre_zermelo = !message.history().has_tracked_position();
bool const is_pre_zermelo = !message.has_is_collapsible();
LOG_IF(WARNING, is_pre_zermelo)
<< "Reading pre-"
<< (is_pre_cesàro ? u8"Cesàro"
@@ -559,7 +561,12 @@ not_null<std::unique_ptr<Vessel>> Vessel::ReadFromMessage(
/*tracked=*/{&vessel->backstory_,
&vessel->psychohistory_});
vessel->prediction_ = vessel->psychohistory_->NewForkAtLast();
// TODO(phl): Need to restore is_collapsible_ somehow.
vessel->is_collapsible_ = message.is_collapsible();
vessel->checkpointer_ =
Checkpointer<serialization::Vessel>::ReadFromMessage(
vessel->MakeCheckpointerWriter(),
vessel->MakeCheckpointerReader(),
message.checkpoint());
}

// Necessary after Εὔδοξος because the ephemeris has not been prolonged
25 changes: 17 additions & 8 deletions ksp_plugin_test/vessel_test.cpp
Original file line number Diff line number Diff line change
@@ -494,6 +494,12 @@ TEST_F(VesselTest, IsCollapsible) {
}

TEST_F(VesselTest, Checkpointing) {
MockFunction<int(not_null<PileUp const*>)>
serialization_index_for_pile_up;
EXPECT_CALL(serialization_index_for_pile_up, Call(_))
.Times(2)
.WillRepeatedly(Return(0));

EXPECT_CALL(ephemeris_, t_max())
.WillRepeatedly(Return(astronomy::J2000 + 30 * Second));
EXPECT_CALL(
@@ -609,16 +615,19 @@ TEST_F(VesselTest, Checkpointing) {
vessel_.AdvanceTime();

serialization::Vessel message;
WriteCheckpointToMessage(&message);
CHECK_EQ(2, message.checkpoint_size());
CHECK_EQ(0, message.checkpoint(0).time().scalar().magnitude());
CHECK_EQ(0, message.checkpoint(0).non_collapsible_segment().children_size());
CHECK_EQ(
vessel_.WriteToMessage(&message,
serialization_index_for_pile_up.AsStdFunction());
EXPECT_TRUE(message.has_is_collapsible());
EXPECT_TRUE(message.is_collapsible());
EXPECT_EQ(2, message.checkpoint_size());
EXPECT_EQ(0, message.checkpoint(0).time().scalar().magnitude());
EXPECT_EQ(0, message.checkpoint(0).non_collapsible_segment().children_size());
EXPECT_EQ(
1,
message.checkpoint(0).non_collapsible_segment().zfp().timeline_size());
CHECK_EQ(25, message.checkpoint(1).time().scalar().magnitude());
CHECK_EQ(0, message.checkpoint(1).non_collapsible_segment().children_size());
CHECK_EQ(
EXPECT_EQ(25, message.checkpoint(1).time().scalar().magnitude());
EXPECT_EQ(0, message.checkpoint(1).non_collapsible_segment().children_size());
EXPECT_EQ(
16,
message.checkpoint(1).non_collapsible_segment().zfp().timeline_size());
}
1 change: 1 addition & 0 deletions serialization/ksp_plugin.proto
Original file line number Diff line number Diff line change
@@ -178,6 +178,7 @@ message Vessel {
optional bool psychohistory_is_authoritative = 17; // Pre-Cesàro.
optional DiscreteTrajectory prediction = 18; // Pre-Chasles.
optional FlightPlan flight_plan = 4;
optional bool is_collapsible = 22; // Added in Zermelo.
repeated Checkpoint checkpoint = 21; // Added in Zermelo.

// Pre-Буняковский.