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

Commits on Aug 5, 2021

  1. better encapsulation

    eggrobin committed Aug 5, 2021
    Copy the full SHA
    071595d View commit details
  2. more refactoring

    eggrobin committed Aug 5, 2021
    Copy the full SHA
    9be1530 View commit details

Commits on Aug 6, 2021

  1. Iron out some bugs

    eggrobin committed Aug 6, 2021
    Copy the full SHA
    2420f8e View commit details
  2. centre

    eggrobin committed Aug 6, 2021
    Copy the full SHA
    b6be713 View commit details

Commits on Aug 8, 2021

  1. after pleroy’s review

    eggrobin committed Aug 8, 2021
    Copy the full SHA
    0aaccc3 View commit details
  2. Merge pull request #3085 from eggrobin/refactor-frame-selector-api

    Refactor the ReferenceFrameSelector API
    eggrobin authored Aug 8, 2021
    Copy the full SHA
    ca535f3 View commit details
Showing with 190 additions and 126 deletions.
  1. +2 −1 ksp_plugin_adapter/burn_editor.cs
  2. +57 −47 ksp_plugin_adapter/ksp_plugin_adapter.cs
  3. +20 −28 ksp_plugin_adapter/map_node_pool.cs
  4. +111 −50 ksp_plugin_adapter/reference_frame_selector.cs
3 changes: 2 additions & 1 deletion ksp_plugin_adapter/burn_editor.cs
Original file line number Diff line number Diff line change
@@ -220,7 +220,8 @@ public Burn Burn() {
};
}

public void ReferenceFrameChanged(NavigationFrameParameters parameters) {
public void ReferenceFrameChanged(NavigationFrameParameters? parameters,
Vessel target_vessel) {
changed_reference_frame_ = true;
}

104 changes: 57 additions & 47 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -108,8 +108,6 @@ internal IntPtr Plugin() {
private UnityEngine.Texture target_navball_texture_;
private bool navball_changed_ = true;
private FlightGlobals.SpeedDisplayModes? previous_display_mode_;
private ReferenceFrameSelector.FrameType last_non_surface_frame_type_ =
ReferenceFrameSelector.FrameType.BODY_CENTRED_NON_ROTATING;

private UnityEngine.Color history_colour = XKCDColors.Lime;
private GLLines.Style history_style = GLLines.Style.Faded;
@@ -436,7 +434,7 @@ private void UpdatePredictions() {
if (ready_to_draw_active_vessel_trajectory) {
string target_id =
FlightGlobals.fetch.VesselTarget?.GetVessel()?.id.ToString();
if (!plotting_frame_selector_.target_override &&
if (!plotting_frame_selector_.target_frame_selected &&
target_id != null &&
plugin_.HasVessel(target_id)) {
// TODO(phl): It's not nice that we are overriding the target vessel
@@ -916,7 +914,7 @@ private void LateUpdate() {
plotting_frame_selector_.SetToSurfaceFrameOf(active_vessel.mainBody);
}

if (plotting_frame_selector_.target_override == null &&
if (!plotting_frame_selector_.target_frame_selected &&
FlightGlobals.speedDisplayMode ==
FlightGlobals.SpeedDisplayModes.Target) {
KSP.UI.Screens.Flight.SpeedDisplay.Instance.textTitle.text =
@@ -927,7 +925,7 @@ private void LateUpdate() {
FlightGlobals.SpeedDisplayModes.Orbit ||
FlightGlobals.speedDisplayMode ==
FlightGlobals.SpeedDisplayModes.Surface ||
plotting_frame_selector_.target_override) {
plotting_frame_selector_.target_frame_selected) {
bool plugin_has_active_manageable_vessel =
has_active_manageable_vessel() &&
plugin_.HasVessel(active_vessel.id.ToString());
@@ -1724,7 +1722,7 @@ private void BetterLateThanNeverLateUpdate() {
string target_id =
FlightGlobals.fetch.VesselTarget?.GetVessel()?.id.ToString();
if (FlightGlobals.ActiveVessel != null &&
!plotting_frame_selector_.target_override &&
!plotting_frame_selector_.target_frame_selected &&
target_id != null &&
plugin_.HasVessel(target_id)) {
RenderPredictionMarkers(target_id, sun_world_position);
@@ -1871,25 +1869,26 @@ private void RenderNavball(Vessel active_vessel) {
}

var target_vessel = FlightGlobals.fetch.VesselTarget?.GetVessel();
if (FlightGlobals.speedDisplayMode ==
FlightGlobals.SpeedDisplayModes.Target &&
target_vessel != null &&
plugin_.HasVessel(target_vessel.id.ToString())) {
plugin_.SetTargetVessel(target_vessel.id.ToString(),
plotting_frame_selector_.selected_celestial.
flightGlobalsIndex);
if (plotting_frame_selector_.target_override != target_vessel) {
navball_changed_ = true;
planetarium_camera_adjuster_.should_transfer_camera_coordinates = true;
plotting_frame_selector_.target_override = target_vessel;
}
} else {
plugin_.ClearTargetVessel();
if (plotting_frame_selector_.target_override != null) {
navball_changed_ = true;
planetarium_camera_adjuster_.should_transfer_camera_coordinates = true;
plotting_frame_selector_.target_override = null;
}
if (target_vessel != null && !plugin_.HasVessel(target_vessel.id.ToString())) {
target_vessel = null;
}
if (plotting_frame_selector_.target != target_vessel) {
plotting_frame_selector_.target = target_vessel;
if (plotting_frame_selector_.target_frame_selected &&
target_vessel == null) {
// The target is not longer manageable.
plotting_frame_selector_.UnsetTargetFrame();
} else if (FlightGlobals.speedDisplayMode ==
FlightGlobals.SpeedDisplayModes.Target &&
!plotting_frame_selector_.target_frame_selected) {
// The navball was in target mode, but the target was not known to
// Principia; now that it is, switch the reference frame accordingly.
plotting_frame_selector_.SetTargetFrame();
} else if (plotting_frame_selector_.target_frame_selected) {
// The target changed.
navball_changed_ = true;
planetarium_camera_adjuster_.should_transfer_camera_coordinates = true;
}
}

// Orient the ball.
@@ -1906,28 +1905,35 @@ private void RenderNavball(Vessel active_vessel) {
// frame accordingly.
switch (FlightGlobals.speedDisplayMode) {
case FlightGlobals.SpeedDisplayModes.Surface:
plotting_frame_selector_.SetFrameType(
ReferenceFrameSelector.FrameType.BODY_SURFACE);
plotting_frame_selector_.SetToSurfaceFrame();
break;
case FlightGlobals.SpeedDisplayModes.Orbit:
plotting_frame_selector_.SetFrameType(last_non_surface_frame_type_);
plotting_frame_selector_.SetToOrbitalFrame();
break;
case FlightGlobals.SpeedDisplayModes.Target:
if (target_vessel != null) {
plotting_frame_selector_.SetTargetFrame();
}
break;
}
}

if (navball_changed_ && previous_display_mode_ != null) {
// Texture the ball.
navball_changed_ = false;
if (plotting_frame_selector_.target_override) {
if (plotting_frame_selector_.target_frame_selected) {
set_navball_texture(target_navball_texture_);
if (FlightGlobals.speedDisplayMode !=
FlightGlobals.SpeedDisplayModes.Target) {
FlightGlobals.SetSpeedMode(FlightGlobals.SpeedDisplayModes.Target);
}
} else {
// If we are targeting an unmanageable vessel, keep the navball in
// target mode; otherwise, put it in the mode that reflects the
// plotting frame.
if (FlightGlobals.speedDisplayMode !=
FlightGlobals.SpeedDisplayModes.Target) {
if (plotting_frame_selector_.frame_type ==
ReferenceFrameSelector.FrameType.BODY_SURFACE) {
if (plotting_frame_selector_.IsSurfaceFrame()) {
if (FlightGlobals.speedDisplayMode !=
FlightGlobals.SpeedDisplayModes.Surface) {
FlightGlobals.SetSpeedMode(
@@ -2140,7 +2146,7 @@ private void RenderTrajectories() {
string target_id = FlightGlobals.fetch.VesselTarget?.GetVessel()?.id.
ToString();
if (FlightGlobals.ActiveVessel != null &&
!plotting_frame_selector_.target_override &&
!plotting_frame_selector_.target_frame_selected &&
target_id != null &&
plugin_.HasVessel(target_id)) {
using (DisposableIterator rp2_lines_iterator =
@@ -2230,7 +2236,7 @@ private void RenderTrajectories() {
private void PlotCelestialTrajectories(DisposablePlanetarium planetarium,
string main_vessel_guid) {
foreach (CelestialBody celestial in FlightGlobals.Bodies) {
if (plotting_frame_selector_.FixedBodies().Contains(celestial)) {
if (plotting_frame_selector_.FixesBody(celestial)) {
continue;
}
var colour = celestial.MapObject?.uiNode?.VisualIconData.color ??
@@ -2274,7 +2280,7 @@ private void PlotCelestialTrajectories(DisposablePlanetarium planetarium,

private void RenderPredictionMarkers(string vessel_guid,
XYZ sun_world_position) {
if (plotting_frame_selector_.target_override) {
if (plotting_frame_selector_.target_frame_selected) {
plugin_.RenderedPredictionNodes(vessel_guid,
sun_world_position,
MapNodePool.MaxRenderedNodes,
@@ -2300,10 +2306,10 @@ out DisposableIterator
MapNodePool.NodeSource.Prediction,
plotting_frame_selector_);
} else {
foreach (CelestialBody celestial in
plotting_frame_selector_.FixedBodies()) {
if (plotting_frame_selector_.Centre() != null) {
var centre_index = plotting_frame_selector_.Centre().flightGlobalsIndex;
plugin_.RenderedPredictionApsides(vessel_guid,
celestial.flightGlobalsIndex,
centre_index,
sun_world_position,
MapNodePool.MaxRenderedNodes,
out DisposableIterator
@@ -2339,7 +2345,7 @@ out DisposableIterator

private void RenderFlightPlanMarkers(string vessel_guid,
XYZ sun_world_position) {
if (plotting_frame_selector_.target_override) {
if (plotting_frame_selector_.target_frame_selected) {
plugin_.FlightPlanRenderedNodes(vessel_guid,
sun_world_position,
MapNodePool.MaxRenderedNodes,
@@ -2365,10 +2371,10 @@ out DisposableIterator
MapNodePool.NodeSource.FlightPlan,
plotting_frame_selector_);
} else {
foreach (CelestialBody celestial in
plotting_frame_selector_.FixedBodies()) {
if (plotting_frame_selector_.Centre() != null) {
var centre_index = plotting_frame_selector_.Centre().flightGlobalsIndex;
plugin_.FlightPlanRenderedApsides(vessel_guid,
celestial.flightGlobalsIndex,
centre_index,
sun_world_position,
MapNodePool.MaxRenderedNodes,
out DisposableIterator
@@ -2423,12 +2429,16 @@ private void Cleanup() {
}

private void UpdateRenderingFrame(
NavigationFrameParameters frame_parameters) {
plugin_.SetPlottingFrame(frame_parameters);
var frame_type =
(ReferenceFrameSelector.FrameType)frame_parameters.extension;
if (frame_type != ReferenceFrameSelector.FrameType.BODY_SURFACE) {
last_non_surface_frame_type_ = frame_type;
NavigationFrameParameters? frame_parameters,
Vessel target_vessel) {
if (target_vessel != null) {
// TODO(egg): We should use the analyser to pick the reference body.
plugin_.SetTargetVessel(
target_vessel.id.ToString(),
target_vessel.orbit.referenceBody.flightGlobalsIndex);
} else {
plugin_.ClearTargetVessel();
plugin_.SetPlottingFrame(frame_parameters.Value);
}
navball_changed_ = true;
reset_rsas_target_ = true;
48 changes: 20 additions & 28 deletions ksp_plugin_adapter/map_node_pool.cs
Original file line number Diff line number Diff line change
@@ -55,44 +55,37 @@ public void RenderMarkers(DisposableIterator apsis_iterator,
switch (type) {
case MapObject.ObjectType.Apoapsis:
case MapObject.ObjectType.Periapsis:
CelestialBody fixed_body = reference_frame.selected_celestial;
CelestialBody fixed_body = reference_frame.Centre();
associated_map_object = fixed_body.MapObject;
colour = fixed_body.orbit == null
? XKCDColors.SunshineYellow
: fixed_body.orbitDriver.Renderer.nodeColor;
break;
case MapObject.ObjectType.ApproachIntersect:
associated_map_object = reference_frame.target_override.mapObject;
associated_map_object = reference_frame.target.mapObject;
colour = XKCDColors.Chartreuse;
break;
case MapObject.ObjectType.AscendingNode:
case MapObject.ObjectType.DescendingNode:
if (!reference_frame.target_override &&
(reference_frame.frame_type ==
ReferenceFrameSelector.FrameType.BODY_CENTRED_NON_ROTATING ||
reference_frame.frame_type ==
ReferenceFrameSelector.FrameType.BODY_SURFACE)) {
// In one-body frames, the apsides are shown with the colour of the
// body.
// The nodes are with respect to the equator, rather than with respect
// to an orbit. We show the nodes in a different (but arbitrary)
// colour so that they can be distinguished easily.
associated_map_object = reference_frame.selected_celestial.MapObject;
colour = XKCDColors.Chartreuse;
} else {
if (reference_frame.Centre() == null) {
// In two-body frames, if apsides are shown, they are shown with the
// colour of the secondary (or in XKCD chartreuse if the secondary is
// a vessel).
// The nodes are with respect to the orbit of the secondary around the
// primary. We show the nodes with the colour of the primary.
CelestialBody primary = reference_frame.target_override
? reference_frame.selected_celestial
: reference_frame.selected_celestial.
referenceBody;
CelestialBody primary = reference_frame.OrientingBody();
associated_map_object = primary.MapObject;
colour = primary.orbit == null
? XKCDColors.SunshineYellow
: primary.orbitDriver.Renderer.nodeColor;
? XKCDColors.SunshineYellow
: primary.orbitDriver.Renderer.nodeColor;
} else {
// In one-body frames, the apsides are shown with the colour of the
// body.
// The nodes are with respect to the equator, rather than with respect
// to an orbit. We show the nodes in a different (but arbitrary)
// colour so that they can be distinguished easily.
associated_map_object = reference_frame.Centre().MapObject;
colour = XKCDColors.Chartreuse;
}
break;
default:
@@ -116,7 +109,7 @@ public void RenderMarkers(DisposableIterator apsis_iterator,
associated_map_object = associated_map_object,
};
if (type == MapObject.ObjectType.Periapsis &&
reference_frame.selected_celestial.GetAltitude(
reference_frame.Centre().GetAltitude(
node_properties.world_position) < 0) {
node_properties.object_type = MapObject.ObjectType.PatchTransition;
node_properties.colour = XKCDColors.Orange;
@@ -220,7 +213,7 @@ private KSP.UI.Screens.Mapview.MapNode MakePoolNode() {
? Localizer.Format("#Principia_MapNode_Periapsis")
: Localizer.Format("#Principia_MapNode_Apoapsis");
CelestialBody celestial =
properties.reference_frame.selected_celestial;
properties.reference_frame.Centre();
Vector3d position = properties.world_position;
double speed = properties.velocity.magnitude;
caption.Header = Localizer.Format("#Principia_MapNode_ApsisHeader",
@@ -251,9 +244,9 @@ private KSP.UI.Screens.Mapview.MapNode MakePoolNode() {
break;
}
case MapObject.ObjectType.ApproachIntersect: {
Vessel target_vessel = properties.reference_frame.target_override;
double separation = (target_vessel.GetWorldPos3D() -
properties.world_position).magnitude;
double separation =
(properties.reference_frame.target.GetWorldPos3D() -
properties.world_position).magnitude;
double speed = properties.velocity.magnitude;
caption.Header = Localizer.Format("#Principia_MapNode_ApproachHeader",
source,
@@ -264,8 +257,7 @@ private KSP.UI.Screens.Mapview.MapNode MakePoolNode() {
break;
}
case MapObject.ObjectType.PatchTransition: {
CelestialBody celestial =
properties.reference_frame.selected_celestial;
CelestialBody celestial = properties.reference_frame.Centre();
caption.Header = Localizer.Format("#Principia_MapNode_ImpactHeader",
source,
celestial.name);
Loading