/// <summary> /// Here when the add-on loads upon flight start. /// </summary> public void Start() { try { instance = this; lastVesselHeightUpdate = DateTime.Now; Reset(); } catch (Exception e) { Logging.Exception(e); } }
/// <summary> /// Do necessary calculations around atmosphere tracking. Returns true if there's anything to display. /// It's okay to call frequently, since it uses an update timer to avoid spamming the CPU. /// </summary> /// <returns></returns> private bool Recalculate() { Vessel vessel = FlightGlobals.ActiveVessel; if (vessel == null) { return(false); } bool shouldDisplay = displayEnabled; // Only display for bodies with atmospheres. shouldDisplay &= (FlightGlobals.currentMainBody != null) && FlightGlobals.currentMainBody.atmosphere; double timeUntil = double.NaN; if (shouldDisplay) { DateTime now = DateTime.Now; if (now > nextUpdate) { nextUpdate = now + UPDATE_INTERVAL; transitionTimeUT = CalculateTimeAtTransition(vessel, out transitionVerb); } if (double.IsNaN(transitionTimeUT)) { timeUntil = double.NaN; shouldDisplay = false; } else { timeUntil = transitionTimeUT - Planetarium.GetUniversalTime(); } } if (shouldDisplay) { int remainingSeconds = ImpactTracker.AsInteger(timeUntil); if (remainingSeconds != secondsUntilTransition) { secondsUntilTransition = remainingSeconds; transitionDescription = string.Format("{0} in {1}", transitionVerb, TimeFormatter.Default.format(ImpactTracker.AsInteger(secondsUntilTransition))); } } else { Reset(); } return(shouldDisplay); }