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

Commits on Apr 18, 2020

  1. Make the display logic in OrbitAnalyser similar to that in FlightPlan…

    …ner. This avoids creating a little window stump in the tracking station.
    pleroy committed Apr 18, 2020
    Copy the full SHA
    aa1917e View commit details
  2. Copy the full SHA
    ec545bb View commit details
  3. Cleanup.

    pleroy committed Apr 18, 2020
    Copy the full SHA
    d7f57f8 View commit details
  4. Typo.

    pleroy committed Apr 18, 2020
    Copy the full SHA
    83941d4 View commit details
  5. After egg's review.

    pleroy committed Apr 18, 2020
    Copy the full SHA
    c2b9bc6 View commit details
  6. Merge pull request #2536 from pleroy/2531

    Display the flight planner and the orbit analyser in the tracking station
    pleroy authored Apr 18, 2020
    Copy the full SHA
    c640b09 View commit details
56 changes: 26 additions & 30 deletions ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -7,8 +7,10 @@
namespace principia {
namespace ksp_plugin_adapter {

class FlightPlanner : SupervisedWindowRenderer {
public FlightPlanner(PrincipiaPluginAdapter adapter) : base(adapter) {
class FlightPlanner : VesselSupervisedWindowRenderer {
public FlightPlanner(PrincipiaPluginAdapter adapter,
PredictedVessel predicted_vessel)
: base(adapter, predicted_vessel) {
adapter_ = adapter;
final_time_ = new DifferentialSlider(
label : "Plan length",
@@ -23,15 +25,7 @@ public FlightPlanner(PrincipiaPluginAdapter adapter) : base(adapter) {
}

public void RenderButton() {
if (UnityEngine.GUILayout.Button("Flight plan...")) {
Toggle();
}
// Override the state of the toggle if there is no active vessel.
string vessel_guid = vessel_?.id.ToString();
if (vessel_guid == null || !plugin.HasVessel(vessel_guid)) {
Hide();
vessel_ = FlightGlobals.ActiveVessel;
}
RenderButton("Flight plan...");
}

public bool show_guidance => show_guidance_;
@@ -68,8 +62,8 @@ protected override void RenderWindow(int window_id) {
// The UI code proper, executed identically for Layout and Repaint. We
// can freely change the state in events like clicks (e.g., in if statements
// for buttons) as these don't happen between Layout and Repaint.
string vessel_guid = vessel_?.id.ToString();
if (vessel_guid == null || !plugin.HasVessel(vessel_guid)) {
string vessel_guid = predicted_vessel?.id.ToString();
if (vessel_guid == null) {
return;
}

@@ -78,7 +72,7 @@ protected override void RenderWindow(int window_id) {
} else if (UnityEngine.GUILayout.Button("Create flight plan")) {
plugin.FlightPlanCreate(vessel_guid,
plugin.CurrentTime() + 3600,
vessel_.GetTotalMass());
predicted_vessel.GetTotalMass());
final_time_.value = plugin.FlightPlanGetDesiredFinalTime(vessel_guid);
Shrink();
}
@@ -87,10 +81,9 @@ protected override void RenderWindow(int window_id) {

private void UpdateVesselAndBurnEditors() {
{
string vessel_guid = vessel_?.id.ToString();
string vessel_guid = predicted_vessel?.id.ToString();
if (vessel_guid == null ||
vessel_ != FlightGlobals.ActiveVessel ||
!plugin.HasVessel(vessel_guid) ||
previous_predicted_vessel_ != predicted_vessel ||
!plugin.FlightPlanExists(vessel_guid) ||
plugin.FlightPlanNumberOfManoeuvres(vessel_guid) !=
burn_editors_?.Count) {
@@ -101,14 +94,13 @@ private void UpdateVesselAndBurnEditors() {
burn_editors_ = null;
Shrink();
}
vessel_ = FlightGlobals.ActiveVessel;
previous_predicted_vessel_ = predicted_vessel;
}
}

if (burn_editors_ == null) {
string vessel_guid = vessel_?.id.ToString();
string vessel_guid = predicted_vessel?.id.ToString();
if (vessel_guid != null &&
plugin.HasVessel(vessel_guid) &&
plugin.FlightPlanExists(vessel_guid)) {
burn_editors_ = new List<BurnEditor>();
final_time_.value = plugin.FlightPlanGetDesiredFinalTime(vessel_guid);
@@ -118,7 +110,7 @@ private void UpdateVesselAndBurnEditors() {
// Dummy initial time, we call |Reset| immediately afterwards.
burn_editors_.Add(
new BurnEditor(adapter_,
vessel_,
predicted_vessel,
initial_time : 0,
index : burn_editors_.Count,
previous_burn : burn_editors_.LastOrDefault()));
@@ -129,7 +121,7 @@ private void UpdateVesselAndBurnEditors() {
}

if (burn_editors_ != null) {
string vessel_guid = vessel_?.id.ToString();
string vessel_guid = predicted_vessel?.id.ToString();
double current_time = plugin.CurrentTime();
first_future_manœuvre_ = null;
for (int i = 0; i < burn_editors_.Count; ++i) {
@@ -291,7 +283,7 @@ private void RenderFlightPlan(string vessel_guid) {
}
var editor =
new BurnEditor(adapter_,
vessel_,
predicted_vessel,
initial_time,
index : burn_editors_.Count,
previous_burn : burn_editors_.LastOrDefault());
@@ -318,7 +310,7 @@ private void RenderFlightPlan(string vessel_guid) {
}

private void RenderUpcomingEvents() {
string vessel_guid = vessel_.id.ToString();
string vessel_guid = predicted_vessel.id.ToString();
double current_time = plugin.CurrentTime();

Style.HorizontalLine();
@@ -350,7 +342,7 @@ private void RenderUpcomingEvents() {
// even though the flight planner is still available to plan it.
// TODO(egg): We may want to consider setting the burn vector directly
// rather than going through the solver.
if (vessel_.patchedConicSolver != null) {
if (predicted_vessel.patchedConicSolver != null) {
using (new UnityEngine.GUILayout.HorizontalScope()) {
show_guidance_ =
UnityEngine.GUILayout.Toggle(show_guidance_, "Show on navball");
@@ -441,8 +433,8 @@ internal static bool TryParseTimeSpan(string str, out TimeSpan value) {

internal string FormatPlanLength(double value) {
return FormatPositiveTimeSpan(TimeSpanFromSeconds(
value -
plugin.FlightPlanGetInitialTime(vessel_.id.ToString())));
value - plugin.FlightPlanGetInitialTime(
predicted_vessel.id.ToString())));
}

internal bool TryParsePlanLength(string str, out double value) {
@@ -451,7 +443,7 @@ internal bool TryParsePlanLength(string str, out double value) {
return false;
}
value = ts.TotalSeconds +
plugin.FlightPlanGetInitialTime(vessel_.id.ToString());
plugin.FlightPlanGetInitialTime(predicted_vessel.id.ToString());
return true;
}

@@ -472,7 +464,7 @@ private void UpdateStatus(Status status, int? error_manœuvre) {
}

private string GetStatusMessage() {
string vessel_guid = vessel_?.id.ToString();
string vessel_guid = predicted_vessel?.id.ToString();
string message = "";
if (vessel_guid != null && !status_.ok()) {
int anomalous_manœuvres =
@@ -550,7 +542,11 @@ private string GetStatusMessage() {
private IntPtr plugin => adapter_.Plugin();

private readonly PrincipiaPluginAdapter adapter_;
private Vessel vessel_;

// Because this class is stateful (it holds the burn_editors_) we must detect
// if the vessel changed. Hence the caching of the vessel.
private Vessel previous_predicted_vessel_;

private List<BurnEditor> burn_editors_;
private readonly DifferentialSlider final_time_;
private int? first_future_manœuvre_;
26 changes: 15 additions & 11 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -300,8 +300,8 @@ private readonly Dictionary<uint, PartCentredForceHolder[]>
}

map_node_pool_ = new MapNodePool();
flight_planner_ = new FlightPlanner(this);
orbit_analyser_ = new OrbitAnalyser(this);
flight_planner_ = new FlightPlanner(this, PredictedVessel);
orbit_analyser_ = new OrbitAnalyser(this, PredictedVessel);
plotting_frame_selector_ = new ReferenceFrameSelector(this,
UpdateRenderingFrame,
"Plotting frame");
@@ -322,7 +322,17 @@ public bool PluginRunning() {
}

private Vessel PredictedVessel() {
return FlightGlobals.ActiveVessel ?? space_tracking?.SelectedVessel;
if (!PluginRunning()) {
return null;
}
Vessel vessel =
FlightGlobals.ActiveVessel ?? space_tracking?.SelectedVessel;
string vessel_guid = vessel?.id.ToString();
if (vessel_guid != null && plugin_.HasVessel(vessel_guid)) {
return vessel;
} else {
return null;
}
}

private delegate void BodyProcessor(CelestialBody body);
@@ -392,9 +402,7 @@ private void UpdateBody(CelestialBody body, double universal_time) {
private void UpdatePredictions() {
Vessel main_vessel = PredictedVessel();
bool ready_to_draw_active_vessel_trajectory =
main_vessel != null &&
MapView.MapIsEnabled &&
plugin_.HasVessel(main_vessel.id.ToString());
main_vessel != null && MapView.MapIsEnabled;

if (ready_to_draw_active_vessel_trajectory) {
plugin_.UpdatePrediction(main_vessel.id.ToString());
@@ -1586,8 +1594,7 @@ private void BetterLateThanNeverLateUpdate() {
// The only timing that satisfies these constraints is BetterLateThanNever
// in LateUpdate.
string main_vessel_guid = PredictedVessel()?.id.ToString();
if (MapView.MapIsEnabled && main_vessel_guid != null &&
PluginRunning() && plugin_.HasVessel(main_vessel_guid)) {
if (MapView.MapIsEnabled && main_vessel_guid != null) {
XYZ sun_world_position = (XYZ)Planetarium.fetch.Sun.position;
RenderPredictionMarkers(main_vessel_guid, sun_world_position);
string target_id =
@@ -1967,9 +1974,6 @@ private void RenderTrajectories() {
RemoveStockTrajectoriesIfNeeded(vessel);
}
string main_vessel_guid = PredictedVessel()?.id.ToString();
if (main_vessel_guid != null && !plugin_.HasVessel(main_vessel_guid)) {
main_vessel_guid = null;
}
if (MapView.MapIsEnabled) {
XYZ sun_world_position = (XYZ)Planetarium.fetch.Sun.position;
using (DisposablePlanetarium planetarium =
16 changes: 4 additions & 12 deletions ksp_plugin_adapter/main_window.cs
Original file line number Diff line number Diff line change
@@ -3,26 +3,23 @@
namespace principia {
namespace ksp_plugin_adapter {

internal class MainWindow : SupervisedWindowRenderer {
internal class MainWindow : VesselSupervisedWindowRenderer {
// Update this section before each release.
private const string next_release_name_ = "Fubini";
private const int next_release_lunation_number_ = 251;
private readonly DateTimeOffset next_release_date_ =
new DateTimeOffset(2020, 04, 23, 02, 26, 00, TimeSpan.Zero);

public delegate Vessel PredictedVessel();

public MainWindow(PrincipiaPluginAdapter adapter,
FlightPlanner flight_planner,
OrbitAnalyser orbit_analyser,
ReferenceFrameSelector plotting_frame_selector,
PredictedVessel predicted_vessel)
: base(adapter) {
: base(adapter, predicted_vessel) {
adapter_ = adapter;
flight_planner_ = flight_planner;
orbit_analyser_ = orbit_analyser;
plotting_frame_selector_ = plotting_frame_selector;
predicted_vessel_ = predicted_vessel;
Show();
}

@@ -391,11 +388,9 @@ private void RenderLoggingSettings() {
}

private void RenderPredictionSettings() {
vessel_ = predicted_vessel_();

AdaptiveStepParameters? adaptive_step_parameters = null;
string vessel_guid = vessel_?.id.ToString();
if (vessel_guid != null && plugin.HasVessel(vessel_guid)) {
string vessel_guid = predicted_vessel?.id.ToString();
if (vessel_guid != null) {
adaptive_step_parameters =
plugin.VesselGetPredictionAdaptiveStepParameters(vessel_guid);
prediction_length_tolerance_index_ = Array.FindIndex(
@@ -535,7 +530,6 @@ private void RenderToggleableSection(string name,
private readonly FlightPlanner flight_planner_;
private readonly OrbitAnalyser orbit_analyser_;
private readonly ReferenceFrameSelector plotting_frame_selector_;
private readonly PredictedVessel predicted_vessel_;

private bool selecting_target_celestial_ = false;

@@ -558,8 +552,6 @@ private void RenderToggleableSection(string name,
private bool must_record_journal_ = false;
// Whether a journal is currently being recorded.
private static bool journaling_ = false;

private Vessel vessel_;
}

} // namespace ksp_plugin_adapter
30 changes: 14 additions & 16 deletions ksp_plugin_adapter/orbit_analyser.cs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public static string FormatInterval(this Interval interval) {
string formatted_half_width = half_width.FormatN(fractional_digits);
return $"{formatted_midpoint}±{formatted_half_width}";
}

// Displays an interval of lengths as midpoint±half-width, in km if the
// half-width is 100 m or more.
public static string FormatLengthInterval(this Interval interval) {
@@ -171,28 +171,26 @@ public static bool TryParseMissionDuration(string str, out double value) {
}
}

internal class OrbitAnalyser : SupervisedWindowRenderer {
public OrbitAnalyser(PrincipiaPluginAdapter adapter)
: base(adapter, UnityEngine.GUILayout.MinWidth(0)) {
internal class OrbitAnalyser : VesselSupervisedWindowRenderer {
public OrbitAnalyser(PrincipiaPluginAdapter adapter,
PredictedVessel predicted_vessel)
: base(adapter, predicted_vessel, UnityEngine.GUILayout.MinWidth(0)) {
adapter_ = adapter;
}

public void RenderButton() {
if (UnityEngine.GUILayout.Button("Orbit analysis...")) {
Toggle();
}
RenderButton("Orbit analysis...");
}

protected override string Title => "Orbit analysis";

protected override void RenderWindow(int window_id) {
string vessel_guid = predicted_vessel?.id.ToString();
if (vessel_guid == null) {
return;
}

using (new UnityEngine.GUILayout.VerticalScope(GUILayoutWidth(8))) {
Vessel vessel = FlightGlobals.ActiveVessel;
if (plugin == IntPtr.Zero || vessel == null ||
!plugin.HasVessel(vessel.id.ToString())) {
Hide();
return;
}
CelestialBody primary =
adapter_.plotting_frame_selector_.selected_celestial;

@@ -203,13 +201,13 @@ protected override void RenderWindow(int window_id) {
float five_lines = multiline_style.CalcHeight(
new UnityEngine.GUIContent("1\n2\n3\n4\n5"), Width(1));
UnityEngine.GUILayout.Label(
$@"Analysing orbit of {vessel.vesselName} with respect to {
$@"Analysing orbit of {predicted_vessel.vesselName} with respect to {
primary.NameWithArticle()}...",
multiline_style,
UnityEngine.GUILayout.Height(two_lines));

OrbitAnalysis analysis = plugin.VesselRefreshAnalysis(
vessel.id.ToString(),
predicted_vessel.id.ToString(),
primary.flightGlobalsIndex,
mission_duration_.value,
autodetect_recurrence_ ? null : (int?)revolutions_per_cycle_,
@@ -270,7 +268,7 @@ protected override void RenderWindow(int window_id) {
multiline_style = Style.Warning(multiline_style);
}
string analysis_description =
$@"Orbit of {vessel.vesselName} with respect to {
$@"Orbit of {predicted_vessel.vesselName} with respect to {
primary.NameWithArticle()} over {
mission_duration.FormatDuration(show_seconds : false)}:{"\n"}{
duration_in_revolutions}";
Loading