Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the flight plan tolerance and steps to be consistent with the prediction #3423

Merged
merged 3 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 68 additions & 16 deletions ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected override void RenderWindowContents(int window_id) {
must_create_flight_plan = UnityEngine.GUILayout.Button(
L10N.CacheFormat("#Principia_FlightPlan_Create"));
} else if (flight_plans < max_flight_plans) {
must_create_flight_plan =
must_create_flight_plan =
UnityEngine.GUILayout.Button("+", GUILayoutWidth(1));
}
if (must_create_flight_plan) {
Expand Down Expand Up @@ -194,31 +194,50 @@ private void RenderFlightPlan(string vessel_guid) {

FlightPlanAdaptiveStepParameters parameters =
plugin.FlightPlanGetAdaptiveStepParameters(vessel_guid);
length_integration_tolerance_index_ = Math.Max(
0,
Array.FindIndex(integration_tolerances_,
(double tolerance) => tolerance >=
parameters.
length_integration_tolerance));
speed_integration_tolerance_index_ = Math.Max(
0,
Array.FindIndex(integration_tolerances_,
(double tolerance) => tolerance >=
parameters.
speed_integration_tolerance));
max_steps_index_ = Math.Max(0,
Array.FindIndex(
max_steps_,
(long step) =>
step >= parameters.max_steps));

using (new UnityEngine.GUILayout.HorizontalScope()) {
using (new UnityEngine.GUILayout.HorizontalScope()) {
UnityEngine.GUILayout.Label(
L10N.CacheFormat("#Principia_FlightPlan_MaxSteps"),
GUILayoutWidth(6));
const int factor = 4;
if (parameters.max_steps <= 100) {
if (max_steps_index_ == 0) {
UnityEngine.GUILayout.Button(
L10N.CacheFormat("#Principia_DiscreteSelector_Min"));
} else if (UnityEngine.GUILayout.Button("−")) {
parameters.max_steps /= factor;
--max_steps_index_;
UpdateAdaptiveStepParameters(ref parameters);
var status =
plugin.FlightPlanSetAdaptiveStepParameters(
vessel_guid,
parameters);
UpdateStatus(status, null);
}
UnityEngine.GUILayout.TextArea(parameters.max_steps.ToString(),
GUILayoutWidth(3));
if (parameters.max_steps >= long.MaxValue / factor) {
UnityEngine.GUILayout.TextArea(
max_steps_[max_steps_index_].ToString(),
GUILayoutWidth(3));
if (max_steps_index_ == max_steps_.Length - 1) {
UnityEngine.GUILayout.Button(
L10N.CacheFormat("#Principia_DiscreteSelector_Max"));
} else if (UnityEngine.GUILayout.Button("+")) {
parameters.max_steps *= factor;
++max_steps_index_;
UpdateAdaptiveStepParameters(ref parameters);
var status =
plugin.FlightPlanSetAdaptiveStepParameters(
vessel_guid,
Expand All @@ -230,12 +249,15 @@ private void RenderFlightPlan(string vessel_guid) {
UnityEngine.GUILayout.Label(
L10N.CacheFormat("#Principia_PredictionSettings_ToleranceLabel"),
GUILayoutWidth(3));
if (parameters.length_integration_tolerance <= 1e-6) {
// Prior to Ἵππαρχος the tolerances were powers of 2, see #3395.
if (length_integration_tolerance_index_ == 0 ||
speed_integration_tolerance_index_ == 0) {
UnityEngine.GUILayout.Button(
L10N.CacheFormat("#Principia_DiscreteSelector_Min"));
} else if (UnityEngine.GUILayout.Button("−")) {
parameters.length_integration_tolerance /= 2;
parameters.speed_integration_tolerance /= 2;
--length_integration_tolerance_index_;
--speed_integration_tolerance_index_;
UpdateAdaptiveStepParameters(ref parameters);
var status =
plugin.FlightPlanSetAdaptiveStepParameters(
vessel_guid,
Expand All @@ -244,15 +266,19 @@ private void RenderFlightPlan(string vessel_guid) {
}
UnityEngine.GUILayout.TextArea(
L10N.CacheFormat("#Principia_PredictionSettings_ToleranceText",
parameters.length_integration_tolerance.ToString(
"0.0e0")),
length_integration_tolerances_names_[
length_integration_tolerance_index_]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the localized string (also from the localization files).

GUILayoutWidth(3));
if (parameters.length_integration_tolerance >= 1e6) {
if (length_integration_tolerance_index_ ==
integration_tolerances_.Length - 1 ||
speed_integration_tolerance_index_ ==
integration_tolerances_.Length - 1) {
UnityEngine.GUILayout.Button(
L10N.CacheFormat("#Principia_DiscreteSelector_Max"));
} else if (UnityEngine.GUILayout.Button("+")) {
parameters.length_integration_tolerance *= 2;
parameters.speed_integration_tolerance *= 2;
++length_integration_tolerance_index_;
++speed_integration_tolerance_index_;
UpdateAdaptiveStepParameters(ref parameters);
var status =
plugin.FlightPlanSetAdaptiveStepParameters(
vessel_guid,
Expand Down Expand Up @@ -684,8 +710,31 @@ private void UpdateBurnEditorIndices() {
}
}

private void UpdateAdaptiveStepParameters(
ref FlightPlanAdaptiveStepParameters parameters) {
parameters.length_integration_tolerance =
integration_tolerances_[length_integration_tolerance_index_];
parameters.speed_integration_tolerance =
integration_tolerances_[speed_integration_tolerance_index_];
parameters.max_steps = max_steps_[max_steps_index_];
}

private IntPtr plugin => adapter_.Plugin();

private static readonly double[] integration_tolerances_ =
{1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6};
private static readonly string[] length_integration_tolerances_names_ = {
"1 µm", "10 µm", "100 µm", "1 mm", "1 cm", "10 cm", "1 m", "10 m",
"100 m", "1 km", "10 km", "100 km", "1000 km"
};
private static readonly string[] speed_integration_tolerances_names_ = {
"1 µm/s", "10 µm/s", "100 µm/s", "1 mm/s", "1 cm/s", "10 cm/s", "1 m/s",
"10 m/s", "100 m/s", "1 km/s", "10 km/s", "100 km/s", "1000 km/s"
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, remove.
Also remove this TODO  in the main window :

// TODO(egg): make the speed tolerance independent.

Let’s not go there.

private static readonly long[] max_steps_ = {
1 << 6, 1 << 8, 1 << 10, 1 << 12, 1 << 14, 1 << 16, 1 << 18, 1 << 20
};

private readonly PrincipiaPluginAdapter adapter_;
private readonly PredictedVessel predicted_vessel_;

Expand All @@ -699,6 +748,9 @@ private void UpdateBurnEditorIndices() {
private int? first_future_manœuvre_;
private int number_of_anomalous_manœuvres_ = 0;

private int length_integration_tolerance_index_;
private int speed_integration_tolerance_index_;
private int max_steps_index_;
private bool show_guidance_ = false;
private float warning_height_ = 1;

Expand Down
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/localization/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Localization {
#Principia_MainWindow_LoggingSettings_JournalingStatus_ON = ON
#Principia_MainWindow_LoggingSettings_JournalingStatus_OFF = OFF
#Principia_PredictionSettings_ToleranceLabel = Tolerance:
#Principia_PredictionSettings_ToleranceText = <<1>> m // <<1>>: parameters.length_integration_tolerance.ToString("0.0e0").
#Principia_PredictionSettings_ToleranceText = <<1>> // <<1>>: length_integration_tolerances_names_[length_integration_tolerance_index_].
#Principia_PredictionSettings_Steps = Steps:
#Principia_DiscreteSelector_Min = min
#Principia_DiscreteSelector_Max = max
Expand Down
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/localization/fr-fr.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Localization {
#Principia_MainWindow_LoggingSettings_JournalingStatus_ON = ACTIF
#Principia_MainWindow_LoggingSettings_JournalingStatus_OFF = INACTIF
#Principia_PredictionSettings_ToleranceLabel = Tolérance :
#Principia_PredictionSettings_ToleranceText = <<1>> m // <<1>>: parameters.length_integration_tolerance.ToString("0.0e0").
#Principia_PredictionSettings_ToleranceText = <<1>> // <<1>>: length_integration_tolerances_names_[length_integration_tolerance_index_].
#Principia_PredictionSettings_Steps = Pas :
#Principia_DiscreteSelector_Min = min
#Principia_DiscreteSelector_Max = max
Expand Down
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/localization/ru.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Localization {
#Principia_MainWindow_LoggingSettings_JournalingStatus_ON = включено
#Principia_MainWindow_LoggingSettings_JournalingStatus_OFF = выключено
#Principia_PredictionSettings_ToleranceLabel = Допуск:
#Principia_PredictionSettings_ToleranceText = <<1>> м // <<1>>: parameters.length_integration_tolerance.ToString("0.0e0").
#Principia_PredictionSettings_ToleranceText = <<1>> // <<1>>: length_integration_tolerances_names_[length_integration_tolerance_index_].
#Principia_PredictionSettings_Steps = Количество шагов:
#Principia_DiscreteSelector_Min = мин.
#Principia_DiscreteSelector_Max = макс.
Expand Down
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/localization/zh-cn.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Localization {
#Principia_MainWindow_LoggingSettings_JournalingStatus_ON = 打开
#Principia_MainWindow_LoggingSettings_JournalingStatus_OFF = 关闭
#Principia_PredictionSettings_ToleranceLabel = 预测精度:
#Principia_PredictionSettings_ToleranceText = <<1>> m // <<1>>: parameters.length_integration_tolerance.ToString("0.0e0").
#Principia_PredictionSettings_ToleranceText = <<1>> // <<1>>: length_integration_tolerances_names_[length_integration_tolerance_index_].
#Principia_PredictionSettings_Steps = 预测步数:
#Principia_DiscreteSelector_Min = 已最小
#Principia_DiscreteSelector_Max = 已最大
Expand Down