Skip to content

Commit

Permalink
Eliminate log spam
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Mar 13, 2021
1 parent a84e751 commit e9f6809
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions GameData/PlanningNode/PlanningNode-Changelog.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ KERBALCHANGELOG
change = Pick right node for auto adjust button (xzy)
type = Fix
}
CHANGE
{
change = Eliminate log spam
type = Fix
}
}
VERSION
{
Expand Down
1 change: 0 additions & 1 deletion GameData/PlanningNode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ Other notes:
- You can click the text labels for a planning node to edit it.
- You can use the "New" button in the dialog to create multiple nodes for the same vessel, and the `<` and `>` buttons next to the name field to switch to other nodes.
- Editing in the tracking station would be desirable but is not possible because the stock maneuver editor crashes outside of the flight scene's map view.
- Similarly, you may experience extreme log spam in some instances while editing nodes due to the stock maneuver editor being extremely sensitive about being used in unexpected ways (and the difficulty of figuring out what it takes to pacify it).
- Blizzy's toolbar is not and will not be supported. 0.23.5 was a **long** time ago.

## How to donate
Expand Down
35 changes: 35 additions & 0 deletions Source/PlanningNodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public PlanningNodeEditor() : base() { }

private IEnumerator Start()
{
// Fingers crossed that nobody else does this, or if they do,
// that we restore our old references in the right order
originalCheckEncounter = PatchedConics.CheckEncounter;
PatchedConics.CheckEncounter = MyCheckEncounter;

// This represents our starting orbit
driver = gameObject.AddComponent<OrbitDriver>();
driver.lowerCamVsSmaRatio = 0.0001f;
Expand Down Expand Up @@ -158,6 +163,10 @@ private void OnManeuverNodeSelected()

private void OnDisable()
{
// Put the encounter checker back to normal when we're done
PatchedConics.CheckEncounter = originalCheckEncounter;
originalCheckEncounter = null;

GameEvents.onManeuverNodeSelected.Remove(OnManeuverNodeSelected);
origCamTarget = null;
DestroyNode();
Expand Down Expand Up @@ -261,6 +270,30 @@ private float SaneMax(float a, float b)
return float.IsNaN(a) ? b : float.IsNaN(b) ? a : Mathf.Max(a, b);
}

/// <summary>
/// Old school style override of PatchedConics.CheckEncounter, set up in Start and reset at destroy.
/// We prevent any encounter with our starting body, and otherwise hand off to the default implementation.
/// </summary>
/// <param name="p">The patch currently being analyzed</param>
/// <param name="nextPatch">The next patch to be analyzed</param>
/// <param name="startEpoch">The time when the vessel reaches p</param>
/// <param name="sec">The driver of the orbit to check for an encounter; this is the only parameter that we actually use here rather than passing along to the default implementation</param>
/// <param name="targetBody">The user's currently selected target</param>
/// <param name="pars">Stuff that controls how the solver works</param>
/// <param name="logErrors">true to print things to the log, false otherwise</param>
/// <returns>
/// true if encounter found, false otherwise (or if one would have been found for our starting body)
/// </returns>
private bool MyCheckEncounter(
Orbit p, Orbit nextPatch, double startEpoch, OrbitDriver sec,
CelestialBody targetBody, PatchedConics.SolverParameters pars, bool logErrors = true)
{
// Suppress encounters with our starting body, because it makes the solver put NaN orbits in the flight plan
return sec?.celestialBody == editingNode?.origin
? false
: originalCheckEncounter(p, nextPatch, startEpoch, sec, targetBody, pars, logErrors);
}

private void Update()
{
if (node != null && solver != null && !solver.maneuverNodes.Contains(node)) {
Expand Down Expand Up @@ -295,6 +328,8 @@ private void OnGizmoUpdated(Vector3d dV, double ut)
}
}

private PatchedConics.CheckEncounterDelegate originalCheckEncounter;

private MapObject origCamTarget;
private float origCamDist;

Expand Down

0 comments on commit e9f6809

Please sign in to comment.