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: 5a2afd6bd09b
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f7541f8080a3
Choose a head ref
  • 12 commits
  • 9 files changed
  • 1 contributor

Commits on Mar 6, 2017

  1. don't serialize

    eggrobin committed Mar 6, 2017
    Copy the full SHA
    e238d62 View commit details
  2. horrifying destruction

    eggrobin committed Mar 6, 2017
    Copy the full SHA
    a97e909 View commit details
  3. logs

    eggrobin committed Mar 6, 2017
    Copy the full SHA
    eb3687c View commit details
  4. use-after-move!

    eggrobin committed Mar 6, 2017
    Copy the full SHA
    fbed469 View commit details
  5. Copy the full SHA
    4895950 View commit details
  6. sob

    eggrobin committed Mar 6, 2017
    Copy the full SHA
    13e7b99 View commit details
  7. Copy the full SHA
    9ccaf09 View commit details
  8. some dummy left

    eggrobin committed Mar 6, 2017
    Copy the full SHA
    9a39428 View commit details
  9. more dummy

    eggrobin committed Mar 6, 2017
    Copy the full SHA
    01f5208 View commit details
  10. Copy the full SHA
    e6e5697 View commit details
  11. after pleroy's review

    eggrobin committed Mar 6, 2017
    Copy the full SHA
    604774c View commit details
  12. Merge pull request #1230 from eggrobin/test-the-things

    Test the things
    eggrobin authored Mar 6, 2017
    Copy the full SHA
    f7541f8 View commit details
Showing with 62 additions and 32 deletions.
  1. +1 −1 ksp_plugin/interface.cpp
  2. +2 −1 ksp_plugin/part.cpp
  3. +2 −2 ksp_plugin/part.hpp
  4. +18 −1 ksp_plugin/plugin.cpp
  5. +1 −1 ksp_plugin/plugin.hpp
  6. +5 −9 ksp_plugin/vessel.cpp
  7. +5 −4 ksp_plugin/vessel.hpp
  8. +28 −12 ksp_plugin_adapter/ksp_plugin_adapter.cs
  9. +0 −1 serialization/ksp_plugin.proto
2 changes: 1 addition & 1 deletion ksp_plugin/interface.cpp
Original file line number Diff line number Diff line change
@@ -708,7 +708,7 @@ void principia__RenderedPredictionApsides(Plugin const* const plugin,
std::unique_ptr<DiscreteTrajectory<World>> rendered_apoapsides;
std::unique_ptr<DiscreteTrajectory<World>> rendered_periapsides;
plugin->ComputeAndRenderApsides(celestial_index,
prediction.Fork(),
prediction.Begin(),
prediction.End(),
q_sun,
rendered_apoapsides,
3 changes: 2 additions & 1 deletion ksp_plugin/part.cpp
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@ Part::Part(
deletion_callback_(std::move(deletion_callback)) {}

Part::~Part() {
clear_pile_up();
LOG(INFO) << "Destroying part " << part_id_;
CHECK(!is_piled_up());
if (deletion_callback_ != nullptr) {
deletion_callback_();
}
4 changes: 2 additions & 2 deletions ksp_plugin/part.hpp
Original file line number Diff line number Diff line change
@@ -43,8 +43,8 @@ class Part final {
DegreesOfFreedom<Barycentric> const& degrees_of_freedom,
std::function<void()> deletion_callback);

// Calls the deletion callback passed at construction, if any. Calls
// |clear_pile_up|.
// Calls the deletion callback passed at construction, if any. This part must
// not be piled up.
~Part();

virtual PartId part_id() const;
19 changes: 18 additions & 1 deletion ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -141,6 +141,21 @@ void Plugin::InsertCelestialAbsoluteCartesian(
initial_state);
}

Plugin::~Plugin() {
// If we simply let the destructor of |Part| deal with removing itself from
// pile-ups, by calling |clear_pile_up|, it will try to access the other
// parts, which may have been already destroyed...
for (auto const& pair : vessels_) {
pair.second->ForAllParts([](Part& part) {
part.clear_pile_up();
});
}
// We must manually destroy the vessels, triggering the destruction of the
// parts, which have callbacks to remove themselves from |part_id_to_vessel_|,
// which must therefore still exist.
vessels_.clear();
}

void Plugin::InsertCelestialJacobiKeplerian(
Index const celestial_index,
std::experimental::optional<Index> const& parent_index,
@@ -472,6 +487,8 @@ void Plugin::FreeVesselsAndPartsAndCollectPileUps() {
} else {
CHECK(!is_loaded(vessel));
LOG(INFO) << "Removing vessel with GUID " << it->first;
// See the destructor.
vessel->ForAllParts([](Part& part) { part.clear_pile_up(); });
it = vessels_.erase(it);
}
}
@@ -688,7 +705,7 @@ not_null<std::unique_ptr<DiscreteTrajectory<World>>> Plugin::RenderedPrediction(
Position<World> const& sun_world_position) const {
CHECK(!initializing_);
Vessel const& vessel = *find_vessel_by_guid_or_die(vessel_guid);
return RenderedTrajectoryFromIterators(vessel.prediction().Fork(),
return RenderedTrajectoryFromIterators(vessel.prediction().Begin(),
vessel.prediction().End(),
sun_world_position);
}
2 changes: 1 addition & 1 deletion ksp_plugin/plugin.hpp
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ class Plugin {
Plugin(Plugin&&) = delete;
Plugin& operator=(Plugin const&) = delete;
Plugin& operator=(Plugin&&) = delete;
virtual ~Plugin() = default;
virtual ~Plugin();

// Constructs a |Plugin|. The current time of that instance is
// |solar_system_epoch|. The angle between the axes of |World| and
14 changes: 5 additions & 9 deletions ksp_plugin/vessel.cpp
Original file line number Diff line number Diff line change
@@ -52,11 +52,13 @@ void Vessel::set_parent(not_null<Celestial const*> const parent) {

void Vessel::AddPart(not_null<std::unique_ptr<Part>> part) {
PartId const id = part->part_id();
parts_.emplace(id, std::move(part));
LOG(INFO) << "Adding part " << id << " to vessel at " << this;
kept_parts_.insert(part.get());
parts_.emplace(id, std::move(part));
}

not_null<std::unique_ptr<Part>> Vessel::ExtractPart(PartId const id) {
LOG(INFO) << "Extracting part " << id << " from vessel at " << this;
auto const it = parts_.find(id);
CHECK(it != parts_.end()) << id;
auto result = std::move(it->second);
@@ -69,7 +71,6 @@ void Vessel::KeepPart(PartId const id) {
}

void Vessel::FreeParts() {
dummy_part_.reset();
for (auto it = parts_.begin(); it != parts_.end();) {
not_null<Part const*> part = it->second.get();
if (kept_parts_.count(part) == 0) {
@@ -163,6 +164,8 @@ void Vessel::AdvanceTime(Instant const& time) {
}

void Vessel::ForgetBefore(Instant const& time) {
// TODO(egg): do something about the psychohistory. I think bad things happen
// if it becomes empty though.
prediction_->ForgetBefore(time);
if (flight_plan_ != nullptr) {
flight_plan_->ForgetBefore(time, [this]() { flight_plan_.reset(); });
@@ -209,9 +212,6 @@ void Vessel::WriteToMessage(
body_.WriteToMessage(message->mutable_body());
prediction_adaptive_step_parameters_.WriteToMessage(
message->mutable_prediction_adaptive_step_parameters());
if (dummy_part_ != nullptr) {
dummy_part_->WriteToMessage(message->mutable_dummy_part());
}
for (auto const& pair : parts_) {
auto const& part = pair.second;
part->WriteToMessage(message->add_parts());
@@ -241,10 +241,6 @@ not_null<std::unique_ptr<Vessel>> Vessel::ReadFromMessage(
ephemeris,
Ephemeris<Barycentric>::AdaptiveStepParameters::ReadFromMessage(
message.prediction_adaptive_step_parameters()));
if (message.has_dummy_part()) {
vessel->dummy_part_ = Part::ReadFromMessage(message.dummy_part(),
/*deletion_callback=*/nullptr);
}
for (auto const& serialized_part : message.parts()) {
PartId const part_id = serialized_part.part_id();
auto part = Part::ReadFromMessage(
9 changes: 5 additions & 4 deletions ksp_plugin/vessel.hpp
Original file line number Diff line number Diff line change
@@ -76,9 +76,9 @@ class Vessel {
// |AddPart|.
virtual not_null<Part*> part(PartId id) const;

// Calls |action| on one (non-dummy) part.
// Calls |action| on one part.
virtual void ForSomePart(std::function<void(Part&)> action) const;
// Calls |action| on all non-dummy parts.
// Calls |action| on all parts.
virtual void ForAllParts(std::function<void(Part&)> action) const;

virtual DiscreteTrajectory<Barycentric> const& prediction() const;
@@ -145,13 +145,14 @@ class Vessel {
not_null<Celestial const*> parent_;
not_null<Ephemeris<Barycentric>*> const ephemeris_;

std::unique_ptr<Part> dummy_part_;
std::map<PartId, not_null<std::unique_ptr<Part>>> parts_;
std::set<not_null<Part const*>> kept_parts_;

// The new implementation of history, also encompasses the prolongation.
not_null<std::unique_ptr<DiscreteTrajectory<Barycentric>>> psychohistory_;
bool psychohistory_is_authoritative_;
// TODO(egg): this is nonsensical, we start with an empty psychohistory, how
// can that be authoritative? This class needs saner invariants.
bool psychohistory_is_authoritative_ = true;

not_null<std::unique_ptr<DiscreteTrajectory<Barycentric>>> prediction_;

40 changes: 28 additions & 12 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -233,12 +233,13 @@ private void UpdateBody(CelestialBody body, double universal_time) {
}

private void UpdateVessel(Vessel vessel, double universal_time) {
QP from_parent = plugin_.VesselFromParent(vessel.id.ToString());
vessel.orbit.UpdateFromStateVectors(
pos : (Vector3d)from_parent.q,
vel : (Vector3d)from_parent.p,
refBody : vessel.orbit.referenceBody,
UT : universal_time);
if (plugin_.HasVessel(vessel.id.ToString())) {
QP from_parent = plugin_.VesselFromParent(vessel.id.ToString());
vessel.orbit.UpdateFromStateVectors(pos : (Vector3d)from_parent.q,
vel : (Vector3d)from_parent.p,
refBody : vessel.orbit.referenceBody,
UT : universal_time);
}
}

private bool is_in_space(Vessel vessel) {
@@ -353,6 +354,7 @@ public override void OnAwake() {

public override void OnSave(ConfigNode node) {
base.OnSave(node);
#if THE_SERIALIZATION_WORKS_AGAIN
if (PluginRunning()) {
String serialization;
IntPtr serializer = IntPtr.Zero;
@@ -364,13 +366,15 @@ public override void OnSave(ConfigNode node) {
node.AddValue(principia_key, serialization);
}
}
#endif
}

public override void OnLoad(ConfigNode node) {
base.OnLoad(node);
if (must_record_journal_) {
Log.ActivateRecorder(true);
}
#if THE_SERIALIZATION_WORKS_AGAIN
if (node.HasValue(principia_key)) {
Cleanup();
SetRotatingFrameThresholds();
@@ -403,9 +407,12 @@ public override void OnLoad(ConfigNode node) {
plugin_construction_ = DateTime.Now;
plugin_source_ = PluginSource.SAVED_STATE;
} else {
#endif
Log.Warning("No principia state found, creating one");
ResetPlugin();
#if THE_SERIALIZATION_WORKS_AGAIN
}
#endif
}

#endregion
@@ -759,9 +766,6 @@ private System.Collections.IEnumerator

plugin_.FreeVesselsAndPartsAndCollectPileUps();

var apparent_world_positions = new Dictionary<Vessel, Vector3d>();
var apparent_world_velocities = new Dictionary<Vessel, Vector3d>();

foreach (Vessel vessel in FlightGlobals.VesselsLoaded) {
if (vessel.packed || !plugin_.HasVessel(vessel.id.ToString())) {
continue;
@@ -801,16 +805,25 @@ private System.Collections.IEnumerator
plugin_.GetPartActualDegreesOfFreedom(part.flightID);
// TODO(egg): use the centre of mass. Here it's a bit tedious, some
// transform nonsense must probably be done.
Log.Error(
"q correction " +
((Vector3d)part_actual_degrees_of_freedom.q - part.rb.position));
Log.Error(
"v correction " +
((Vector3d)part_actual_degrees_of_freedom.p - part.rb.velocity));
part.rb.position = (Vector3d)part_actual_degrees_of_freedom.q;
part.rb.velocity = (Vector3d)part_actual_degrees_of_freedom.p;
}
}
if (has_active_vessel_in_space() && FlightGlobals.ActiveVessel.loaded) {
QP main_body_dof = plugin_.CelestialWorldDegreesOfFreedom(
FlightGlobals.ActiveVessel.mainBody.flightGlobalsIndex);
krakensbane.FrameVel = (Vector3d)main_body_dof.p;
Log.Error("change in framevel: " +
(-(Vector3d)main_body_dof.p - krakensbane.FrameVel));
krakensbane.FrameVel = -(Vector3d)main_body_dof.p;
Vector3d offset = (Vector3d)main_body_dof.q -
FlightGlobals.ActiveVessel.mainBody.position;
Log.Error("shifting the world by " + offset);
// We cannot use FloatingOrigin.SetOffset to move the world here, because
// as far as I can tell, that does not move the bubble relative to the
// rest of the universe.
@@ -854,11 +867,14 @@ private void ReportVesselsAndParts() {
if (PluginRunning()) {
foreach (Vessel vessel in FlightGlobals.Vessels.Where(is_in_space)) {
bool inserted;
// WTF? or should I use !packed?
bool actually_loaded_with_real_parts =
vessel.loaded && !vessel.parts.TrueForAll(part => part.rb == null);
plugin_.InsertOrKeepVessel(vessel.id.ToString(),
vessel.mainBody.flightGlobalsIndex,
vessel.loaded,
actually_loaded_with_real_parts,
out inserted);
if (vessel.loaded) {
if (actually_loaded_with_real_parts) {
QP main_body_degrees_of_freedom =
new QP{q = (XYZ)vessel.mainBody.position,
p = (XYZ)(-krakensbane.FrameVel)};
1 change: 0 additions & 1 deletion serialization/ksp_plugin.proto
Original file line number Diff line number Diff line change
@@ -119,7 +119,6 @@ message Vessel {
required MasslessBody body = 1;
required Ephemeris.AdaptiveStepParameters
prediction_adaptive_step_parameters = 10;
optional Part dummy_part = 13;
repeated Part parts = 14;
repeated uint32 kept_parts = 15;
required DiscreteTrajectory psychohistory = 16;