Skip to content

Commit

Permalink
correctly clear markers when the flight plan disappears
Browse files Browse the repository at this point in the history
  • Loading branch information
al2me6 committed Jul 1, 2024
1 parent 334a659 commit a56b73a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,14 +2243,14 @@ select PartCentredForceHolder.
if (main_vessel_guid == null) {
return;
}
int number_of_rendered_manœuvres = 0;
if (plugin_.FlightPlanExists(main_vessel_guid)) {
int number_of_anomalous_manœuvres =
plugin_.FlightPlanNumberOfAnomalousManoeuvres(main_vessel_guid);
int number_of_manœuvres =
plugin_.FlightPlanNumberOfManoeuvres(main_vessel_guid);
int number_of_segments =
plugin_.FlightPlanNumberOfSegments(main_vessel_guid);
int number_of_rendered_manœuvres = 0;
for (int i = 0; i < number_of_segments; ++i) {
bool is_burn = i % 2 == 1;
using (DisposableIterator rendered_segments =
Expand Down Expand Up @@ -2289,11 +2289,19 @@ select PartCentredForceHolder.
}
}
}
for (int i = number_of_rendered_manœuvres;
i < manœuvre_marker_pool_.Count;
++i) {
manœuvre_marker_pool_[i].Disable();
}
// This cleanup must occur even if there is no flight plan. In the
// tracking station, one may switch from a vessel with a plan to one
// without.
for (int i = number_of_rendered_manœuvres;
i < manœuvre_marker_pool_.Count;
++i) {
// Since markers are used sequentially, all subsequent ones will
// be in the disabled state.
if (manœuvre_marker_pool_[i].is_disabled) {
break;
}
manœuvre_marker_pool_[i].Disable();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions ksp_plugin_adapter/manœuvre_marker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ internal class ManœuvreMarker : UnityEngine.MonoBehaviour {
// during which it is consumed by node markers.
public static bool has_interacting_marker { get; private set; }

public bool is_disabled => !gameObject.activeSelf && !caption_.activeSelf;

// Construct the geometry of the marker when instantiated.
// 1. Build the mesh of the marker (base 'bulb' & one cylinder for each axis).
// 2. Attach a spherical collider (centred on the bulb) to the gameobject for
Expand Down

0 comments on commit a56b73a

Please sign in to comment.