Skip to content

Commit

Permalink
Merge pull request #2189 from pleroy/2188
Browse files Browse the repository at this point in the history
Remove the last manœuvre when it leads to an integration error
pleroy authored Jun 1, 2019
2 parents ee42d9e + a04d38f commit da53560
Showing 4 changed files with 14 additions and 10 deletions.
7 changes: 4 additions & 3 deletions journal/player.cpp
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ Player::Player(std::filesystem::path const& path)
CHECK(!stream_.fail());
}

bool Player::Play() {
bool Player::Play(int const index) {
std::unique_ptr<serialization::Method> method_in = Read();
if (method_in == nullptr) {
// End of input file.
@@ -39,8 +39,9 @@ bool Player::Play() {
}

#if 0
LOG(ERROR) << "\n" << method_in->ShortDebugString() << "\n"
<< method_out_return->ShortDebugString();
LOG_IF(ERROR, index > 3170000) << "index: " << index << "\n"
<< method_in->ShortDebugString() << "\n"
<< method_out_return->ShortDebugString();
#endif

auto const before = std::chrono::system_clock::now();
3 changes: 2 additions & 1 deletion journal/player.hpp
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@ class Player final {
explicit Player(std::filesystem::path const& path);

// Replays the next message in the journal. Returns false at end of journal.
bool Play();
// |index| is the 0-based index of the message in the journal.
bool Play(int index);

// Return the last replayed messages.
serialization::Method const& last_method_in() const;
12 changes: 6 additions & 6 deletions journal/player_test.cpp
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ void BM_PlayForReal(benchmark::State& state) {
Player player(
R"(P:\Public Mockingbird\Principia\Journals\JOURNAL.20180311-192733)");
int count = 0;
while (player.Play()) {
while (player.Play(count)) {
++count;
LOG_IF(ERROR, (count % 100'000) == 0)
<< count << " journal entries replayed";
@@ -74,7 +74,7 @@ TEST_F(PlayerTest, PlayTiny) {

// Replay the journal.
int count = 0;
while (player.Play()) {
while (player.Play(count)) {
++count;
}
EXPECT_EQ(2, count);
@@ -88,10 +88,10 @@ TEST_F(PlayerTest, DISABLED_Debug) {
// An example of how journaling may be used for debugging. You must set
// |path| and fill the |method_in| and |method_out_return| protocol buffers.
std::string path =
R"(C:\Program Files\Kerbal Space Program\1.6.1\glog\Principia\JOURNAL.20190520-205625)"; // NOLINT
R"(C:\Program Files\Kerbal Space Program\1.7.0\glog\Principia\JOURNAL.20190601-174743)"; // NOLINT
Player player(path);
int count = 0;
while (player.Play()) {
while (player.Play(count)) {
++count;
LOG_IF(ERROR, (count % 100'000) == 0) << count
<< " journal entries replayed";
@@ -108,8 +108,8 @@ TEST_F(PlayerTest, DISABLED_Debug) {
auto* extension = method_in.MutableExtension(
serialization::FlightPlanGetManoeuvreFrenetTrihedron::extension);
auto* in = extension->mutable_in();
in->set_plugin(2634828656);
in->set_vessel_guid("88d741d3-600c-4f4b-9567-8109cecab2bd");
in->set_plugin(2312193072);
in->set_vessel_guid("bedd9d23-de56-4fb8-881c-f647e22f848f");
in->set_index(0);
}
serialization::Method method_out_return;
2 changes: 2 additions & 0 deletions ksp_plugin/interface_flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -476,6 +476,8 @@ bool principia__FlightPlanReplaceLast(Plugin const* const plugin,
} else if (status.ok() || flight_plan.number_of_anomalous_manœuvres() == 0) {
return m.Return(true);
} else {
// The last manœuvre is broken. Roll it back.
flight_plan.RemoveLast();
flight_plan.Append(manœuvre.burn());
return m.Return(false);
}

0 comments on commit da53560

Please sign in to comment.