From e9f6809dbb0100d70f037d8fcdbeb2bccd4ebb4e Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Fri, 12 Mar 2021 23:06:31 -0600 Subject: [PATCH] Eliminate log spam --- .../PlanningNode/PlanningNode-Changelog.cfg | 5 +++ GameData/PlanningNode/README.md | 1 - Source/PlanningNodeEditor.cs | 35 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/GameData/PlanningNode/PlanningNode-Changelog.cfg b/GameData/PlanningNode/PlanningNode-Changelog.cfg index 40743ce..a19fedb 100644 --- a/GameData/PlanningNode/PlanningNode-Changelog.cfg +++ b/GameData/PlanningNode/PlanningNode-Changelog.cfg @@ -15,6 +15,11 @@ KERBALCHANGELOG change = Pick right node for auto adjust button (xzy) type = Fix } + CHANGE + { + change = Eliminate log spam + type = Fix + } } VERSION { diff --git a/GameData/PlanningNode/README.md b/GameData/PlanningNode/README.md index f864a46..e3989d5 100644 --- a/GameData/PlanningNode/README.md +++ b/GameData/PlanningNode/README.md @@ -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 diff --git a/Source/PlanningNodeEditor.cs b/Source/PlanningNodeEditor.cs index 7d8384c..1037e36 100644 --- a/Source/PlanningNodeEditor.cs +++ b/Source/PlanningNodeEditor.cs @@ -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(); driver.lowerCamVsSmaRatio = 0.0001f; @@ -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(); @@ -261,6 +270,30 @@ private float SaneMax(float a, float b) return float.IsNaN(a) ? b : float.IsNaN(b) ? a : Mathf.Max(a, b); } + /// + /// 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. + /// + /// The patch currently being analyzed + /// The next patch to be analyzed + /// The time when the vessel reaches p + /// 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 + /// The user's currently selected target + /// Stuff that controls how the solver works + /// true to print things to the log, false otherwise + /// + /// true if encounter found, false otherwise (or if one would have been found for our starting body) + /// + 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)) { @@ -295,6 +328,8 @@ private void OnGizmoUpdated(Vector3d dV, double ut) } } + private PatchedConics.CheckEncounterDelegate originalCheckEncounter; + private MapObject origCamTarget; private float origCamDist;