--- a/VOID_Core.cs +++ b/VOID_Core.cs @@ -284,6 +284,18 @@ } } + public Stage[] Stages + { + get; + protected set; + } + + public Stage LastStage + { + get; + protected set; + } + protected IconState powerState { get @@ -437,7 +449,7 @@ } } - public void OnGUI() + public virtual void OnGUI() { if (Event.current.type == EventType.Repaint) { @@ -491,21 +503,14 @@ } } - public void Update() + public virtual void Update() { this.LoadBeforeUpdate(); if (this.vessel != null && this.vesselSimActive) { - double radius = this.vessel.Radius(); - SimManager.Gravity = this.vessel.mainBody.gravParameter / - (radius * radius); - SimManager.minSimTime = (long)(this.updatePeriod * 1000); - SimManager.TryStartSimulation(); - } - else if (!this.vesselSimActive) - { - SimManager.ClearResults(); + Tools.PostDebugMessage(this, "Updating SimManager."); + this.UpdateSimManager(); } if (!this.guiRunning) @@ -542,7 +547,7 @@ this._updateTimer += Time.deltaTime; } - public void FixedUpdate() + public virtual void FixedUpdate() { bool newPowerState = this.powerAvailable; @@ -729,6 +734,41 @@ this._factoryReset = GUILayout.Toggle(this._factoryReset, "Factory Reset"); } + protected void UpdateSimManager() + { + if (SimManager.ResultsReady()) + { + Tools.PostDebugMessage(this, "VesselSimulator results ready, setting Stages."); + + this.Stages = SimManager.Stages; + + if (this.Stages != null) + { + this.LastStage = this.Stages.Last(); + } + + if (HighLogic.LoadedSceneIsEditor) + { + SimManager.Gravity = VOID_Data.KerbinGee; + } + else + { + double radius = this.vessel.Radius(); + SimManager.Gravity = this.vessel.mainBody.gravParameter / (radius * radius); + } + + SimManager.minSimTime = (long)(this.updatePeriod * 1000); + + SimManager.TryStartSimulation(); + } + #if DEBUG + else + { + Tools.PostDebugMessage(this, "VesselSimulator results not ready."); + } + #endif + } + protected void LoadModulesOfType<T>() { var types = AssemblyLoader.loadedAssemblies @@ -899,7 +939,7 @@ protected void InitializeToolbarButton() { - // Do nothing if the Toolbar is not available. + // Do nothing if (the Toolbar is not available. if (!ToolbarManager.ToolbarAvailable) { return; @@ -1103,9 +1143,16 @@ { get { - return core.Kerbin.gravParameter / (core.Kerbin.Radius * core.Kerbin.Radius); - } - } + if (kerbinGee == default(double)) + { + kerbinGee = core.Kerbin.gravParameter / (core.Kerbin.Radius * core.Kerbin.Radius); + } + + return kerbinGee; + } + } + + private static double kerbinGee; } }