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

Commits on May 11, 2019

  1. Copy the full SHA
    b6e9a6a View commit details
  2. Some simplification.

    pleroy committed May 11, 2019
    Copy the full SHA
    ca94df5 View commit details
  3. Remove traces.

    pleroy committed May 11, 2019
    Copy the full SHA
    e8592e8 View commit details
  4. Merge pull request #2163 from pleroy/2157

    Properly detect changes to the navigation frame
    pleroy authored May 11, 2019
    Copy the full SHA
    e3bed38 View commit details
Showing with 64 additions and 50 deletions.
  1. +1 −1 journal/player_test.cpp
  2. +63 −49 ksp_plugin_adapter/reference_frame_selector.cs
2 changes: 1 addition & 1 deletion journal/player_test.cpp
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ TEST_F(PlayerTest, DISABLED_Debug) {
// An example of how journaling may be used for debugging. You must set
// |path| and fill the |method_in| and |method_out_return| protocol buffers.
std::string path =
R"(C:\Program Files\Kerbal Space Program\1.6.1\glog\Principia\JOURNAL.20190425-223810)"; // NOLINT
R"(C:\Program Files\Kerbal Space Program\1.6.1\glog\Principia\JOURNAL.20190511-140327)"; // NOLINT
Player player(path);
int count = 0;
while (player.Play()) {
112 changes: 63 additions & 49 deletions ksp_plugin_adapter/reference_frame_selector.cs
Original file line number Diff line number Diff line change
@@ -30,10 +30,10 @@ public enum FrameType {

public delegate void Callback(NavigationFrameParameters frame_parameters);

public ReferenceFrameSelector(
ISupervisor supervisor,
Callback on_change,
string name) : base(supervisor, UnityEngine.GUILayout.MinWidth(0)) {
public ReferenceFrameSelector(ISupervisor supervisor,
Callback on_change,
string name)
: base(supervisor, UnityEngine.GUILayout.MinWidth(0)) {
on_change_ = on_change;
name_ = name;

@@ -51,56 +51,60 @@ public ReferenceFrameSelector(
}

public void UpdateMainBody() {
frame_type = FrameType.BODY_CENTRED_NON_ROTATING;
selected_celestial =
FlightGlobals.currentMainBody ?? FlightGlobals.GetHomeBody();
for (CelestialBody celestial = selected_celestial;
celestial.orbit != null;
celestial = celestial.orbit.referenceBody) {
if (!celestial.is_leaf()) {
expanded_[celestial] = true;
EffectChange(() => {
frame_type = FrameType.BODY_CENTRED_NON_ROTATING;
selected_celestial =
FlightGlobals.currentMainBody ?? FlightGlobals.GetHomeBody();
for (CelestialBody celestial = selected_celestial;
celestial.orbit != null;
celestial = celestial.orbit.referenceBody) {
if (!celestial.is_leaf()) {
expanded_[celestial] = true;
}
}
}
on_change_(FrameParameters());
});
}

public void SetFrameParameters(NavigationFrameParameters parameters) {
frame_type = (FrameType)parameters.extension;
switch (frame_type) {
case FrameType.BODY_CENTRED_NON_ROTATING:
case FrameType.BODY_SURFACE:
selected_celestial = FlightGlobals.Bodies[parameters.centre_index];
break;
case FrameType.BARYCENTRIC_ROTATING:
selected_celestial = FlightGlobals.Bodies[parameters.secondary_index];
break;
case FrameType.BODY_CENTRED_PARENT_DIRECTION:
selected_celestial = FlightGlobals.Bodies[parameters.primary_index];
break;
}
on_change_(FrameParameters());
EffectChange(() => {
frame_type = (FrameType)parameters.extension;
switch (frame_type) {
case FrameType.BODY_CENTRED_NON_ROTATING:
case FrameType.BODY_SURFACE:
selected_celestial = FlightGlobals.Bodies[parameters.centre_index];
break;
case FrameType.BARYCENTRIC_ROTATING:
selected_celestial = FlightGlobals.Bodies[parameters.secondary_index];
break;
case FrameType.BODY_CENTRED_PARENT_DIRECTION:
selected_celestial = FlightGlobals.Bodies[parameters.primary_index];
break;
}
});
}

// Sets the |frame_type| to |type| unless this would be invalid for the
// |selected_celestial|, in which case |frame_type| is set to
// |BODY_CENTRED_NON_ROTATING|.
public void SetFrameType(FrameType type) {
if (selected_celestial.is_root() &&
(type == FrameType.BARYCENTRIC_ROTATING ||
type == FrameType.BODY_CENTRED_PARENT_DIRECTION)) {
frame_type = FrameType.BODY_CENTRED_NON_ROTATING;
} else {
frame_type = type;
}
on_change_(FrameParameters());
EffectChange(() => {
if (selected_celestial.is_root() &&
(type == FrameType.BARYCENTRIC_ROTATING ||
type == FrameType.BODY_CENTRED_PARENT_DIRECTION)) {
frame_type = FrameType.BODY_CENTRED_NON_ROTATING;
} else {
frame_type = type;
}
});
}

// Sets the |frame_type| to |BODY_SURFACE| and sets |selected_celestial| to
// the given |celestial|.
public void SetToSurfaceFrameOf(CelestialBody celestial) {
frame_type = FrameType.BODY_SURFACE;
selected_celestial = celestial;
on_change_(FrameParameters());
EffectChange(() => {
frame_type = FrameType.BODY_SURFACE;
selected_celestial = celestial;
});
}

public static String Name(FrameType type,
@@ -267,6 +271,10 @@ public void RenderButton() {
}
}

public FrameType frame_type { get; private set; }
public CelestialBody selected_celestial { get; private set; }
public Vessel target_override { get; set; }

protected override String Title {
get {
return name_ + " selection (" + Name() + ")";
@@ -328,13 +336,12 @@ private void RenderSubtree(CelestialBody celestial, int depth) {
}
if (UnityEngine.GUILayout.Toggle(selected_celestial == celestial,
celestial.name)) {
if (selected_celestial != celestial) {
EffectChange(() => {
selected_celestial = celestial;
if (celestial.is_root() && frame_type != FrameType.BODY_SURFACE) {
frame_type = FrameType.BODY_CENTRED_NON_ROTATING;
}
on_change_(FrameParameters());
}
});
}
}
if (celestial.is_root() || (!celestial.is_leaf() && expanded_[celestial])) {
@@ -354,16 +361,23 @@ private void TypeSelector(FrameType value) {
style,
GUILayoutWidth(6),
GUILayoutHeight(5))) {
if (frame_type != value) {
frame_type = value;
on_change_(FrameParameters());
}
EffectChange(() => {
frame_type = value;
});
}
}

public FrameType frame_type { get; private set; }
public CelestialBody selected_celestial { get; private set; }
public Vessel target_override { get; set; }
// Runs an action that may change the frame and run on_change_ if there
// actually was a change.
private void EffectChange(Action action) {
var old_frame_type = frame_type;
var old_selected_celestial = selected_celestial;
action();
if (frame_type != old_frame_type ||
selected_celestial != old_selected_celestial) {
on_change_(FrameParameters());
}
}

private readonly Callback on_change_;
private readonly string name_;