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

Commits on Nov 29, 2020

  1. Copy the full SHA
    dac4e6c View commit details
  2. 5° is more reasonable

    eggrobin committed Nov 29, 2020
    Copy the full SHA
    cbe2b41 View commit details
  3. width

    eggrobin committed Nov 29, 2020
    Copy the full SHA
    d792899 View commit details
  4. That’s not a test

    eggrobin committed Nov 29, 2020
    Copy the full SHA
    b4c5a89 View commit details
  5. Copy the full SHA
    9a63031 View commit details

Commits on Nov 30, 2020

  1. after pleroy’s review

    eggrobin committed Nov 30, 2020
    Copy the full SHA
    3965493 View commit details
  2. Merge pull request #2802 from eggrobin/orbit-analyser

    Describe the current orbit on the analyser button
    eggrobin authored Nov 30, 2020
    Copy the full SHA
    094f402 View commit details
4 changes: 2 additions & 2 deletions ksp_plugin/interface_vessel.cpp
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ XYZ __cdecl principia__VesselNormal(Plugin const* const plugin,
}

OrbitAnalysis* __cdecl principia__VesselRefreshAnalysis(
Plugin const* const plugin,
Plugin* const plugin,
char const* const vessel_guid,
double const mission_duration,
int const* const revolutions_per_cycle,
@@ -83,14 +83,14 @@ OrbitAnalysis* __cdecl principia__VesselRefreshAnalysis(
ground_track_revolution});
CHECK_NOTNULL(plugin);
Vessel& vessel = *plugin->GetVessel(vessel_guid);
plugin->ClearOrbitAnalysersOfVesselsOtherThan(vessel);
vessel.RefreshOrbitAnalysis(mission_duration * Second);
not_null<OrbitAnalysis*> analysis = NewOrbitAnalysis(vessel.orbit_analysis(),
*plugin,
revolutions_per_cycle,
days_per_cycle,
ground_track_revolution);
analysis->progress_of_next_analysis = vessel.progress_of_orbit_analysis();

return m.Return(analysis);
}

8 changes: 8 additions & 0 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1060,6 +1060,14 @@ not_null<Vessel*> Plugin::GetVessel(GUID const& vessel_guid) const {
return FindOrDie(vessels_, vessel_guid).get();
}

void Plugin::ClearOrbitAnalysersOfVesselsOtherThan(Vessel const& vessel) {
for (auto const& [guid, v] : vessels_) {
if (v.get() != &vessel) {
v->ClearOrbitAnalyser();
}
}
}

not_null<std::unique_ptr<Planetarium>> Plugin::NewPlanetarium(
Planetarium::Parameters const& parameters,
Perspective<Navigation, Camera> const& perspective)
2 changes: 2 additions & 0 deletions ksp_plugin/plugin.hpp
Original file line number Diff line number Diff line change
@@ -378,6 +378,8 @@ class Plugin {
virtual bool HasVessel(GUID const& vessel_guid) const;
virtual not_null<Vessel*> GetVessel(GUID const& vessel_guid) const;

virtual void ClearOrbitAnalysersOfVesselsOtherThan(Vessel const& vessel);

virtual not_null<std::unique_ptr<Planetarium>> NewPlanetarium(
Planetarium::Parameters const& parameters,
Perspective<Navigation, Camera> const& perspective) const;
4 changes: 4 additions & 0 deletions ksp_plugin/vessel.cpp
Original file line number Diff line number Diff line change
@@ -525,6 +525,10 @@ void Vessel::RefreshOrbitAnalysis(Time const& mission_duration) {
orbit_analyser_->RefreshAnalysis();
}

void Vessel::ClearOrbitAnalyser() {
orbit_analyser_.reset();
}

double Vessel::progress_of_orbit_analysis() const {
if (!orbit_analyser_.has_value()) {
return 0;
1 change: 1 addition & 0 deletions ksp_plugin/vessel.hpp
Original file line number Diff line number Diff line change
@@ -188,6 +188,7 @@ class Vessel {
pile_up_for_serialization_index);

void RefreshOrbitAnalysis(Time const& mission_duration);
void ClearOrbitAnalyser();

double progress_of_orbit_analysis() const;
OrbitAnalyser::Analysis* orbit_analysis();
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public FlightPlanner(PrincipiaPluginAdapter adapter,
}

public void RenderButton() {
RenderButton("Flight plan...");
RenderButton("Flight plan...", GUILayoutWidth(4));
}

public bool show_guidance => show_guidance_;
118 changes: 109 additions & 9 deletions ksp_plugin_adapter/orbit_analyser.cs
Original file line number Diff line number Diff line change
@@ -144,10 +144,36 @@ public OrbitAnalyser(PrincipiaPluginAdapter adapter,
}

public void RenderButton() {
RenderButton("Orbit analysis...");
string vessel_guid = predicted_vessel?.id.ToString();
if (vessel_guid == null) {
orbit_description_ = null;
} else if (!Shown()) {
// Keep refreshing the analysis even when the analyser is not shown, so
// that the analysis button can display an up-to-date one-line summary.
OrbitAnalysis analysis = plugin.VesselRefreshAnalysis(
vessel_guid,
mission_duration_.value,
autodetect_recurrence_ ? null : (int?)revolutions_per_cycle_,
autodetect_recurrence_ ? null : (int?)days_per_cycle_,
ground_track_revolution_);
CelestialBody primary = analysis.primary_index.HasValue
? FlightGlobals.Bodies[analysis.primary_index.Value]
: null;
orbit_description_ = OrbitDescription(
primary,
analysis.elements,
analysis.recurrence,
analysis.ground_track,
(int?)(analysis.mission_duration / analysis.elements?.nodal_period));
}
RenderButton(orbit_description_ == null
? "Orbit analysis..."
: $"Analysis: {orbit_description_}...");
}

protected override string Title => "Orbit analysis";
protected override string Title => orbit_description_ == null
? "Orbit analysis"
: orbit_description_[0].ToString().ToUpper() +
orbit_description_.Substring(1);

protected override void RenderWindow(int window_id) {
string vessel_guid = predicted_vessel?.id.ToString();
@@ -167,12 +193,13 @@ protected override void RenderWindow(int window_id) {
multiline_style,
UnityEngine.GUILayout.Height(two_lines));

OrbitAnalysis analysis = plugin.VesselRefreshAnalysis(
predicted_vessel.id.ToString(),
mission_duration_.value,
autodetect_recurrence_ ? null : (int?)revolutions_per_cycle_,
autodetect_recurrence_ ? null : (int?)days_per_cycle_,
ground_track_revolution_);
OrbitAnalysis analysis = plugin.VesselRefreshAnalysis(
predicted_vessel.id.ToString(),
mission_duration_.value,
autodetect_recurrence_ ? null : (int?)revolutions_per_cycle_,
autodetect_recurrence_ ? null : (int?)days_per_cycle_,
ground_track_revolution_);

if (autodetect_recurrence_ &&
analysis.recurrence.HasValue &&
analysis.recurrence.Value.number_of_revolutions != 0 &&
@@ -195,6 +222,10 @@ protected override void RenderWindow(int window_id) {
analysis.primary_index.HasValue ? FlightGlobals.Bodies[analysis.primary_index.Value]
: null;

orbit_description_ = OrbitDescription(
primary, elements, recurrence, ground_track,
(int?)(mission_duration / elements?.nodal_period));

Style.HorizontalLine();
string duration_in_revolutions;
if (elements.HasValue) {
@@ -247,6 +278,73 @@ protected override void RenderWindow(int window_id) {
UnityEngine.GUI.DragWindow();
}

private string OrbitDescription(
CelestialBody primary,
OrbitalElements? elements,
OrbitRecurrence? recurrence,
OrbitGroundTrack? ground_track,
int? nodal_revolutions) {
if (!elements.HasValue) {
return null;
}
string properties = "";
bool circular = false;
bool equatorial = false;
if (elements.Value.mean_eccentricity.max < 0.01) {
circular = true;
properties += "circular ";
} else if (elements.Value.mean_eccentricity.min > 0.5) {
circular = true;
properties += "highly elliptical ";
}
const double degree = Math.PI / 180;
if (elements.Value.mean_inclination.max < 5 * degree ||
elements.Value.mean_inclination.min > 175 * degree) {
equatorial = true;
properties += "equatorial ";
} else if (elements.Value.mean_inclination.min > 80 * degree &&
elements.Value.mean_inclination.max < 100 * degree) {
properties += "polar ";
} else if (elements.Value.mean_inclination.min > 90 * degree) {
properties += "retrograde ";
}
if (recurrence.HasValue && ground_track.HasValue) {
Interval ascending_longitudes = ground_track.Value.equatorial_crossings.
longitudes_reduced_to_ascending_pass;
Interval descending_longitudes = ground_track.Value.equatorial_crossings.
longitudes_reduced_to_descending_pass;
double drift = Math.Max(
ascending_longitudes.max - ascending_longitudes.min,
descending_longitudes.max - descending_longitudes.min);
double revolutions_per_day =
(double)recurrence.Value.number_of_revolutions / recurrence.Value.cto;
double days = nodal_revolutions.Value / revolutions_per_day;
// We ignore 0 drift as it means that there was only one pass, which is
// insufficient to assess synchronicity.
if (drift > 0 && drift / days < 0.1 * degree) {
if (recurrence.Value.cto == 1) {
switch(recurrence.Value.nuo) {
case 1:
properties += "synchronous ";
if (circular && equatorial) {
properties = "stationary ";
}
break;
case 2:
properties += "semisynch. ";
break;
default:
properties += "subsynch. ";
break;
}
} else if (recurrence.Value.dto == 0) {
properties += "supersynch. ";
}
}
}
return $"{properties}{primary.name} orbit";
}

private void RenderOrbitalElements(OrbitalElements? elements,
CelestialBody primary) {
double? lowest_distance = elements?.radial_distance.min;
@@ -405,6 +503,8 @@ private void LabeledField(string label, string value) {
private int revolutions_per_cycle_ = 1;
private int days_per_cycle_ = 1;
private int ground_track_revolution_ = 1;

private string orbit_description_ = null;
}


4 changes: 2 additions & 2 deletions ksp_plugin_adapter/window_renderer.cs
Original file line number Diff line number Diff line change
@@ -284,8 +284,8 @@ params UnityEngine.GUILayoutOption[]
}

// A helper for implementing the RenderButton() method of the subclasses.
protected void RenderButton(string text) {
if (UnityEngine.GUILayout.Button(text)) {
protected void RenderButton(string text, params UnityEngine.GUILayoutOption[] options) {
if (UnityEngine.GUILayout.Button(text, options)) {
Toggle();
}
// Override the state of the toggle if there is no predicted vessel.
2 changes: 1 addition & 1 deletion serialization/journal.proto
Original file line number Diff line number Diff line change
@@ -2256,7 +2256,7 @@ message VesselRefreshAnalysis {
optional VesselRefreshAnalysis extension = 5160;
}
message In {
required fixed64 plugin = 1 [(pointer_to) = "Plugin const",
required fixed64 plugin = 1 [(pointer_to) = "Plugin",
(is_subject) = true];
required string vessel_guid = 2;
required double mission_duration = 4;