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: 5b1da5935d2e
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ba3c0d8cbbab
Choose a head ref
  • 5 commits
  • 2 files changed
  • 2 contributors

Commits on Jul 28, 2019

  1. Commit the prediction parameters when they are changed in the UI, not…

    … at a random point where we are going to draw.
    pleroy committed Jul 28, 2019
    Copy the full SHA
    810cc3f View commit details
  2. Comment.

    pleroy committed Jul 28, 2019
    Copy the full SHA
    ba77bdd View commit details
  3. After egg's review.

    pleroy committed Jul 28, 2019
    Copy the full SHA
    4033b18 View commit details
  4. Compilation error.

    pleroy committed Jul 28, 2019
    Copy the full SHA
    404072a View commit details
  5. Merge pull request #2254 from pleroy/2239

    Save the prediction parameters when they are modified in the UI
    pleroy authored Jul 28, 2019
    Copy the full SHA
    ba3c0d8 View commit details
Showing with 62 additions and 58 deletions.
  1. +0 −16 ksp_plugin_adapter/ksp_plugin_adapter.cs
  2. +62 −42 ksp_plugin_adapter/main_window.cs
16 changes: 0 additions & 16 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -312,27 +312,11 @@ private void UpdatePredictions() {
plugin_.HasVessel(main_vessel.id.ToString());

if (ready_to_draw_active_vessel_trajectory) {
// TODO(egg): make the speed tolerance independent. Also max_steps.
AdaptiveStepParameters adaptive_step_parameters =
plugin_.VesselGetPredictionAdaptiveStepParameters(
main_vessel.id.ToString());
adaptive_step_parameters =
new AdaptiveStepParameters {
integrator_kind = adaptive_step_parameters.integrator_kind,
max_steps = main_window_.prediction_steps,
length_integration_tolerance =
main_window_.prediction_length_tolerance,
speed_integration_tolerance =
main_window_.prediction_length_tolerance};
plugin_.VesselSetPredictionAdaptiveStepParameters(
main_vessel.id.ToString(), adaptive_step_parameters);
plugin_.UpdatePrediction(main_vessel.id.ToString());
string target_id =
FlightGlobals.fetch.VesselTarget?.GetVessel()?.id.ToString();
if (!plotting_frame_selector_.target_override &&
target_id != null && plugin_.HasVessel(target_id)) {
plugin_.VesselSetPredictionAdaptiveStepParameters(
target_id, adaptive_step_parameters);
plugin_.UpdatePrediction(target_id);
}
}
104 changes: 62 additions & 42 deletions ksp_plugin_adapter/main_window.cs
Original file line number Diff line number Diff line change
@@ -49,9 +49,6 @@ public void SelectActiveVesselTarget(MapObject map_object,
public bool display_patched_conics { get; private set; } = false;

public double history_length => history_lengths_[history_length_index_];
public double prediction_length_tolerance =>
prediction_length_tolerances_[prediction_length_tolerance_index_];
public long prediction_steps => prediction_steps_[prediction_steps_index_];

public void LoadCompatibilityDataIfNeeded(int history_length_index) {
if (should_load_compatibility_data_) {
@@ -190,11 +187,11 @@ protected override void RenderWindow(int window_id) {
UnityEngine.GUILayout.Label(
version,
style : Style.Info(UnityEngine.GUI.skin.label));
RenderSelector(enabled: true,
history_lengths_,
RenderSelector(history_lengths_,
ref history_length_index_,
"Max history length",
"{0:0.00e00} s");
"{0:0.00e00} s",
enabled: true);
if (MapView.MapIsEnabled &&
FlightGlobals.ActiveVessel?.orbitTargeter != null) {
show_selection_ui_ = true;
@@ -377,51 +374,68 @@ private void RenderLoggingSettings() {
}

private void RenderPredictionSettings() {
bool enabled = vessel_ != null;
if (vessel_ != predicted_vessel_()) {
vessel_ = predicted_vessel_();
string vessel_guid = vessel_?.id.ToString();
if (vessel_guid != null && plugin.HasVessel(vessel_guid)) {
enabled = true;
AdaptiveStepParameters adaptive_step_parameters =
plugin.VesselGetPredictionAdaptiveStepParameters(vessel_guid);
prediction_length_tolerance_index_ = Array.FindIndex(
prediction_length_tolerances_,
(double tolerance) =>
tolerance >=
adaptive_step_parameters.length_integration_tolerance);
if (prediction_length_tolerance_index_ < 0) {
prediction_length_tolerance_index_ =
default_prediction_length_tolerance_index_;
}
prediction_steps_index_ = Array.FindIndex(
prediction_steps_,
(long step) => step >= adaptive_step_parameters.max_steps);
if (prediction_steps_index_ < 0) {
prediction_steps_index_ = default_prediction_steps_index_;
}
} else {
enabled = false;
}
AdaptiveStepParameters? adaptive_step_parameters = null;
string vessel_guid = vessel_?.id.ToString();
if (vessel_guid != null && plugin.HasVessel(vessel_guid)) {
adaptive_step_parameters =
plugin.VesselGetPredictionAdaptiveStepParameters(vessel_guid);
prediction_length_tolerance_index_ = Array.FindIndex(
prediction_length_tolerances_,
(double tolerance) =>
tolerance >=
adaptive_step_parameters.Value.length_integration_tolerance);
if (prediction_length_tolerance_index_ < 0) {
prediction_length_tolerance_index_ =
default_prediction_length_tolerance_index_;
}
prediction_steps_index_ = Array.FindIndex(
prediction_steps_,
(long step) => step >= adaptive_step_parameters.Value.max_steps);
if (prediction_steps_index_ < 0) {
prediction_steps_index_ = default_prediction_steps_index_;
}
}

RenderSelector(enabled,
prediction_length_tolerances_,
ref prediction_length_tolerance_index_,
"Tolerance",
"{0:0.0e0} m");
RenderSelector(enabled,
prediction_steps_,
ref prediction_steps_index_,
"Steps",
"{0:0.00e0}");
// TODO(egg): make the speed tolerance independent.
if (RenderSelector(prediction_length_tolerances_,
ref prediction_length_tolerance_index_,
"Tolerance",
"{0:0.0e0} m",
enabled: adaptive_step_parameters.HasValue)) {
AdaptiveStepParameters new_adaptive_step_parameters =
new AdaptiveStepParameters{
integrator_kind = adaptive_step_parameters.Value.integrator_kind,
max_steps = prediction_steps,
length_integration_tolerance = prediction_length_tolerance,
speed_integration_tolerance = prediction_length_tolerance};
plugin.VesselSetPredictionAdaptiveStepParameters(
vessel_guid, new_adaptive_step_parameters);
}
if (RenderSelector(prediction_steps_,
ref prediction_steps_index_,
"Steps",
"{0:0.00e0}",
enabled: adaptive_step_parameters.HasValue)) {
AdaptiveStepParameters new_adaptive_step_parameters =
new AdaptiveStepParameters{
integrator_kind = adaptive_step_parameters.Value.integrator_kind,
max_steps = prediction_steps,
length_integration_tolerance = prediction_length_tolerance,
speed_integration_tolerance = prediction_length_tolerance};
plugin.VesselSetPredictionAdaptiveStepParameters(
vessel_guid, new_adaptive_step_parameters);
}
}

private void RenderSelector<T>(bool enabled,
T[] array,
private bool RenderSelector<T>(T[] array,
ref int index,
string label,
string format) {
string format,
bool enabled) {
bool changed = false;
using (new UnityEngine.GUILayout.HorizontalScope()) {
UnityEngine.GUILayout.Label(text : label + ":",
options : GUILayoutWidth(6));
@@ -430,6 +444,7 @@ private void RenderSelector<T>(bool enabled,
enabled &&
index != 0) {
--index;
changed = true;
}
UnityEngine.GUILayout.TextArea(
text : enabled
@@ -443,8 +458,10 @@ private void RenderSelector<T>(bool enabled,
enabled &&
index != array.Length - 1) {
++index;
changed = true;
}
}
return changed;
}

private void RenderToggleableSection(string name,
@@ -464,6 +481,9 @@ private void RenderToggleableSection(string name,
}

private IntPtr plugin => adapter_.Plugin();
private double prediction_length_tolerance =>
prediction_length_tolerances_[prediction_length_tolerance_index_];
private long prediction_steps => prediction_steps_[prediction_steps_index_];

private static readonly double[] history_lengths_ =
{1 << 10, 1 << 11, 1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16, 1 << 17,