Added deltaV readouts.
Added deltaV readouts.

--- a/KerbalEngineer/Editor/BuildAdvanced.cs
+++ b/KerbalEngineer/Editor/BuildAdvanced.cs
@@ -182,17 +182,17 @@
                 }

 

                 // Configure the simulation parameters based on the selected reference body.

-                SimulationManager.Gravity = CelestialBodies.Instance.SelectedBodyInfo.Gravity;

+                SimulationManager.Instance.Gravity = CelestialBodies.Instance.SelectedBodyInfo.Gravity;

                 if (this.useAtmosphericDetails)

                 {

-                    SimulationManager.Atmosphere = CelestialBodies.Instance.SelectedBodyInfo.Atmosphere * 0.01d;

+                    SimulationManager.Instance.Atmosphere = CelestialBodies.Instance.SelectedBodyInfo.Atmosphere * 0.01d;

                 }

                 else

                 {

-                    SimulationManager.Atmosphere = 0;

-                }

-

-                SimulationManager.TryStartSimulation();

+                    SimulationManager.Instance.Atmosphere = 0;

+                }

+

+                SimulationManager.Instance.TryStartSimulation();

             }

             catch

             {

@@ -209,7 +209,7 @@
                     return;

                 }

 

-                SimulationManager.RequestSimulation();

+                SimulationManager.Instance.RequestSimulation();

 

                 // Change the window title based on whether in compact mode or not.

                 string title;

@@ -223,7 +223,7 @@
                 }

 

                 // Reset the window size when the staging or something else has changed.

-                int stageCount = SimulationManager.Stages.Count(stage => this.showAllStages || stage.DeltaV > 0);

+                int stageCount = SimulationManager.Instance.Stages.Count(stage => this.showAllStages || stage.DeltaV > 0);

                 if (this.hasChanged || stageCount != this.numberOfStages)

                 {

                     this.hasChanged = false;

@@ -359,7 +359,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(30.0f));

             GUILayout.Label(string.Empty, this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {

@@ -376,7 +376,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(50.0f));

             GUILayout.Label("PARTS", this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {

@@ -393,7 +393,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(100.0f));

             GUILayout.Label("COST", this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {

@@ -410,7 +410,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(100.0f));

             GUILayout.Label("MASS", this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {

@@ -427,7 +427,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(50.0f));

             GUILayout.Label("ISP", this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {

@@ -444,7 +444,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(75.0f));

             GUILayout.Label("THRUST", this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {

@@ -461,7 +461,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(50.0f));

             GUILayout.Label("TWR", this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {

@@ -478,7 +478,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(100.0f));

             GUILayout.Label("DELTA-V", this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {

@@ -495,7 +495,7 @@
         {

             GUILayout.BeginVertical(GUILayout.Width(75.0f));

             GUILayout.Label("BURN", this.titleStyle);

-            foreach (var stage in SimulationManager.Stages)

+            foreach (var stage in SimulationManager.Instance.Stages)

             {

                 if (this.showAllStages || stage.DeltaV > 0)

                 {


--- a/KerbalEngineer/Editor/BuildOverlay.cs
+++ b/KerbalEngineer/Editor/BuildOverlay.cs
@@ -146,18 +146,18 @@
                 }

 

                 // Configure the simulation parameters based on the selected reference body.

-                SimulationManager.Gravity = CelestialBodies.Instance.SelectedBodyInfo.Gravity;

+                SimulationManager.Instance.Gravity = CelestialBodies.Instance.SelectedBodyInfo.Gravity;

 

                 if (BuildAdvanced.Instance.UseAtmosphericDetails)

                 {

-                    SimulationManager.Atmosphere = CelestialBodies.Instance.SelectedBodyInfo.Atmosphere * 0.01d;

+                    SimulationManager.Instance.Atmosphere = CelestialBodies.Instance.SelectedBodyInfo.Atmosphere * 0.01d;

                 }

                 else

                 {

-                    SimulationManager.Atmosphere = 0;

-                }

-

-                SimulationManager.TryStartSimulation();

+                    SimulationManager.Instance.Atmosphere = 0;

+                }

+

+                SimulationManager.Instance.TryStartSimulation();

             }

             catch

             {

@@ -174,7 +174,7 @@
                     return;

                 }

 

-                SimulationManager.RequestSimulation();

+                SimulationManager.Instance.RequestSimulation();

 

                 this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, string.Empty, this.windowStyle);

 

@@ -244,9 +244,9 @@
 

             // Details

             GUILayout.BeginVertical(GUILayout.Width(100.0f));

-            GUILayout.Label(SimulationManager.LastStage.PartCount.ToString("N0"), this.infoStyle);

-            GUILayout.Label(SimulationManager.LastStage.TotalDeltaV.ToString("N0") + " m/s", this.infoStyle);

-            GUILayout.Label(SimulationManager.LastStage.ThrustToWeight.ToString("F2"), this.infoStyle);

+            GUILayout.Label(SimulationManager.Instance.LastStage.PartCount.ToString("N0"), this.infoStyle);

+            GUILayout.Label(SimulationManager.Instance.LastStage.TotalDeltaV.ToString("N0") + " m/s", this.infoStyle);

+            GUILayout.Label(SimulationManager.Instance.LastStage.ThrustToWeight.ToString("F2"), this.infoStyle);

             GUILayout.EndVertical();

 

             GUILayout.EndHorizontal();


--- a/KerbalEngineer/Extensions/FloatExtensions.cs
+++ b/KerbalEngineer/Extensions/FloatExtensions.cs
@@ -62,14 +62,14 @@
                     {

                         value = -value;

                     }

-                    return value.ToString("N2") + "mm";

+                    return value.ToString("N0") + "mm";

                 }

 

                 if (negative)

                 {

                     value = -value;

                 }

-                return value.ToString("N2") + "m";

+                return value.ToString("N0") + "m";

             }

 

             value /= 1000.0f;

@@ -81,14 +81,14 @@
                 {

                     value = -value;

                 }

-                return value.ToString("N2" + "Mm");

+                return value.ToString("N0" + "Mm");

             }

 

             if (negative)

             {

                 value = -value;

             }

-            return value.ToString("N2" + "km");

+            return value.ToString("N0" + "km");

         }

 

         /// <summary>


--- a/KerbalEngineer/Flight/FlightEngineerCore.cs
+++ b/KerbalEngineer/Flight/FlightEngineerCore.cs
@@ -6,6 +6,7 @@
 

 using System.Collections.Generic;

 

+using KerbalEngineer.Flight.Readouts;

 using KerbalEngineer.Flight.Sections;

 

 using UnityEngine;

@@ -41,6 +42,7 @@
             this.DisplayStack = this.gameObject.AddComponent<DisplayStack>();

             this.SectionWindows = new List<SectionWindow>();

             this.SectionEditors = new List<SectionEditor>();

+            this.UpdatableModules = new List<IUpdatable>();

         }

 

         /// <summary>

@@ -49,6 +51,7 @@
         private void Start()

         {

             SectionLibrary.Instance.Load();

+            ReadoutLibrary.Instance.Reset();

         }

 

         #endregion

@@ -75,6 +78,11 @@
         /// </summary>

         public List<SectionEditor> SectionEditors { get; private set; }

 

+        /// <summary>

+        ///     Gets the list of currently running updatable modules.

+        /// </summary>

+        public List<IUpdatable> UpdatableModules { get; private set; }

+

         #endregion

 

         #region Updating

@@ -85,6 +93,15 @@
         private void Update()

         {

             SectionLibrary.Instance.Update();

+            this.UpdateModules();

+        }

+

+        private void UpdateModules()

+        {

+            foreach (var updatable in this.UpdatableModules)

+            {

+                updatable.Update();

+            }

         }

 

         #endregion

@@ -151,6 +168,17 @@
             return editor;

         }

 

+        /// <summary>

+        ///     Adds an updatable object to be automatically updated every frame and will ignore duplicate objects.

+        /// </summary>

+        public void AddUpdatable(IUpdatable updatable)

+        {

+            if (!this.UpdatableModules.Contains(updatable))

+            {

+                this.UpdatableModules.Add(updatable);

+            }

+        }

+

         #endregion

     }

 }

--- a/KerbalEngineer/Flight/FlightEngineerModule.cs
+++ b/KerbalEngineer/Flight/FlightEngineerModule.cs
@@ -43,7 +43,6 @@
                 // Checks for an existing instance of FlightEngineerCore, and if this part is the first part containing FlightEngineerModule within the vessel.

                 if (this.flightEngineerCore == null && this.part == this.vessel.parts.FirstOrDefault(p => p.Modules.Contains("FlightEngineerModule")))

                 {

-                    ReadoutLibrary.Instance.Reset();

                     this.flightEngineerCore = this.gameObject.AddComponent<FlightEngineerCore>();

                 }

             }


--- a/KerbalEngineer/Flight/Readouts/ReadoutLibrary.cs
+++ b/KerbalEngineer/Flight/Readouts/ReadoutLibrary.cs
@@ -8,7 +8,9 @@
 using System.Linq;

 

 using KerbalEngineer.Flight.Readouts.Orbital;

+using KerbalEngineer.Flight.Readouts.Rendezvous;

 using KerbalEngineer.Flight.Readouts.Surface;

+using KerbalEngineer.Flight.Readouts.Vessel;

 using KerbalEngineer.Settings;

 

 #endregion

@@ -44,6 +46,7 @@
         /// </summary>

         private ReadoutLibrary()

         {

+            // Orbital

             this.readoutModules.Add(new ApoapsisHeight());

             this.readoutModules.Add(new PeriapsisHeight());

             this.readoutModules.Add(new TimeToApoapsis());

@@ -56,6 +59,7 @@
             this.readoutModules.Add(new SemiMajorAxis());

             this.readoutModules.Add(new SemiMinorAxis());

 

+            // Surface

             this.readoutModules.Add(new AltitudeSeaLevel());

             this.readoutModules.Add(new AltitudeTerrain());

             this.readoutModules.Add(new VerticalSpeed());

@@ -63,6 +67,15 @@
             this.readoutModules.Add(new Longitude());

             this.readoutModules.Add(new Latitude());

             this.readoutModules.Add(new GeeForce());

+            this.readoutModules.Add(new TerminalVelocity());

+            this.readoutModules.Add(new AtmosphericEfficiency());

+

+            // Vessel

+            this.readoutModules.Add(new DeltaVStaged());

+            this.readoutModules.Add(new DeltaVTotal());

+

+            // Rendezvous

+            this.readoutModules.Add(new TargetSelector());

 

             this.LoadHelpStrings();

         }


--- a/KerbalEngineer/Flight/Readouts/ReadoutModule.cs
+++ b/KerbalEngineer/Flight/Readouts/ReadoutModule.cs
@@ -35,6 +35,8 @@
 

         public bool ShowHelp { get; set; }

 

+        public bool ResizeRequested { get; set; }

+

         /// <summary>

         ///     Gets ans sets the readout category.

         /// </summary>

@@ -63,16 +65,57 @@
         public GUIStyle ValueStyle { get; set; }

 

         /// <summary>

+        ///     Gets and sets the message style.

+        /// </summary>

+        public GUIStyle MessageStyle { get; set; }

+

+        /// <summary>

+        ///     Gets and sets the flexible label style.

+        /// </summary>

+        public GUIStyle FlexiLabelStyle { get; set; }

+

+        /// <summary>

         ///     Gets and sets the button style.

         /// </summary>

         public GUIStyle ButtonStyle { get; set; }

 

         /// <summary>

+        ///     Gets and sets the text field style.

+        /// </summary>

+        public GUIStyle TextFieldStyle { get; set; }

+

+        /// <summary>

         ///     Initialises all the styles required for this object.

         /// </summary>

         private void InitialiseStyles()

         {

             this.NameStyle = new GUIStyle(HighLogic.Skin.label)

+            {

+                normal =

+                {

+                    textColor = Color.white

+                },

+                margin = new RectOffset(),

+                padding = new RectOffset(5,0,0,0),

+                alignment = TextAnchor.MiddleLeft,

+                fontSize = 11,

+                fontStyle = FontStyle.Bold,

+                fixedWidth = 115.0f,

+                fixedHeight = 20.0f

+            };

+

+            this.ValueStyle = new GUIStyle(HighLogic.Skin.label)

+            {

+                margin = new RectOffset(),

+                padding = new RectOffset(0,5,0,0),

+                alignment = TextAnchor.MiddleRight,

+                fontSize = 11,

+                fontStyle = FontStyle.Normal,

+                fixedWidth = 115.0f,

+                fixedHeight = 20.0f

+            };

+

+            this.MessageStyle = new GUIStyle(HighLogic.Skin.label)

             {

                 normal =

                 {

@@ -80,22 +123,17 @@
                 },

                 margin = new RectOffset(),

                 padding = new RectOffset(),

-                alignment = TextAnchor.MiddleLeft,

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                fixedWidth = 110.0f,

+                alignment = TextAnchor.MiddleCenter,

+                fontSize = 11,

+                fontStyle = FontStyle.Normal,

+                fixedWidth = this.ContentWidth,

                 fixedHeight = 20.0f

             };

 

-            this.ValueStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                margin = new RectOffset(),

-                padding = new RectOffset(),

-                alignment = TextAnchor.MiddleRight,

-                fontSize = 11,

-                fontStyle = FontStyle.Normal,

-                fixedWidth = 110.0f,

-                fixedHeight = 20.0f

+            this.FlexiLabelStyle = new GUIStyle(this.NameStyle)

+            {

+                fixedWidth = 0,

+                stretchWidth = true

             };

 

             this.ButtonStyle = new GUIStyle(HighLogic.Skin.button)

@@ -104,10 +142,20 @@
                 {

                     textColor = Color.white

                 },

-                margin = new RectOffset(),

+                margin = new RectOffset(0,0,1,1),

                 padding = new RectOffset(),

-                fontSize = 11,

-                fixedHeight = 20.0f

+                alignment = TextAnchor.MiddleCenter,

+                fontSize = 11,

+                fixedHeight = 18.0f

+            };

+

+            this.TextFieldStyle = new GUIStyle(HighLogic.Skin.textField)

+            {

+                margin = new RectOffset(0,0,1,1),

+                padding = new RectOffset(5, 5, 0, 0),

+                alignment = TextAnchor.MiddleLeft,

+                fontSize = 11,

+                fixedHeight = 18.0f

             };

         }

 

@@ -137,6 +185,13 @@
             GUILayout.EndHorizontal();

         }

 

+        protected void DrawMessageLine(string value)

+        {

+            GUILayout.BeginHorizontal();

+            GUILayout.Label(value, this.MessageStyle);

+            GUILayout.EndHorizontal();

+        }

+

         #endregion

 

         #region Virtual Methods


--- a/KerbalEngineer/Flight/Readouts/Surface/AltitudeTerrain.cs
+++ b/KerbalEngineer/Flight/Readouts/Surface/AltitudeTerrain.cs
@@ -21,7 +21,7 @@
 

         public override void Draw()

         {

-            this.DrawLine(FlightGlobals.ActiveVessel.terrainAltitude.ToDistance());

+            this.DrawLine((FlightGlobals.ActiveVessel.altitude - FlightGlobals.ActiveVessel.terrainAltitude).ToDistance());

         }

     }

 }

--- /dev/null
+++ b/KerbalEngineer/Flight/Readouts/Vessel/DeltaVStaged.cs
@@ -1,1 +1,56 @@
-
+// Project:	KerbalEngineer

+// Author:	CYBUTEK

+// License:	Attribution-NonCommercial-ShareAlike 3.0 Unported

+

+#region Using Directives

+

+using System.Linq;

+

+using KerbalEngineer.Simulation;

+

+#endregion

+

+namespace KerbalEngineer.Flight.Readouts.Vessel

+{

+    public class DeltaVStaged : ReadoutModule

+    {

+        private int numberOfStages;

+

+        public DeltaVStaged()

+        {

+            this.Name = "DeltaV Staged";

+            this.Category = ReadoutCategory.Vessel;

+            this.HelpString = "Shows the vessel's delta velocity for each stage.";

+        }

+

+        public override void Update()

+        {

+            SimulationManager.Instance.RequestSimulation();

+        }

+

+        public override void Draw()

+        {

+            var newNumberOfStages = 0;

+

+            foreach (var stage in SimulationManager.Instance.Stages)

+            {

+                if (stage.DeltaV > 0 || stage.Number == Staging.CurrentStage)

+                {

+                    this.DrawLine("DeltaV (S" + stage.Number + ")", stage.DeltaV.ToString("N0") + "m/s");

+                    newNumberOfStages++;

+                }

+            }

+

+            if (newNumberOfStages != this.numberOfStages)

+            {

+                this.numberOfStages = newNumberOfStages;

+                this.ResizeRequested = true;

+            }

+        }

+

+        public override void Reset()

+        {

+            FlightEngineerCore.Instance.AddUpdatable(SimulationManager.Instance);

+        }

+    }

+}

--- a/KerbalEngineer/Flight/Sections/SectionLibrary.cs
+++ b/KerbalEngineer/Flight/Sections/SectionLibrary.cs
@@ -120,7 +120,28 @@
                 {

                     if (!section.IsFloating)

                     {

+                        foreach (var readout in section.ReadoutModules)

+                        {

+                            if (readout.ResizeRequested)

+                            {

+                                DisplayStack.Instance.RequestResize();

+                                readout.ResizeRequested = false;

+                            }

+                        }

+

                         this.NumberOfStackSections++;

+                    }

+                    else

+                    {

+                        foreach (var readout in section.ReadoutModules)

+                        {

+                            if (readout.ResizeRequested)

+                            {

+                                section.Window.RequestResize();

+                                readout.ResizeRequested = false;

+                            }

+                        }

+                        

                     }

                     section.Update();

                 }


--- a/KerbalEngineer/Flight/Sections/SectionModule.cs
+++ b/KerbalEngineer/Flight/Sections/SectionModule.cs
@@ -25,7 +25,6 @@
 

         private SectionEditor editor;

         private int numberOfReadouts;

-        private SectionWindow window;

 

         #endregion

 

@@ -83,16 +82,16 @@
         /// </summary>

         public bool IsFloating

         {

-            get { return this.window != null; }

+            get { return this.Window != null; }

             set

             {

-                if (value && this.window == null)

-                {

-                    this.window = FlightEngineerCore.Instance.AddSectionWindow(this);

-                }

-                else if (!value && this.window != null)

-                {

-                    Object.Destroy(this.window);

+                if (value && this.Window == null)

+                {

+                    this.Window = FlightEngineerCore.Instance.AddSectionWindow(this);

+                }

+                else if (!value && this.Window != null)

+                {

+                    Object.Destroy(this.Window);

                 }

             }

         }

@@ -139,6 +138,11 @@
         ///     Gets and sets the list of readout modules.

         /// </summary>

         [XmlIgnore] public List<ReadoutModule> ReadoutModules { get; set; }

+

+        /// <summary>

+        ///     Gets and sets the floating window.

+        /// </summary>

+        [XmlIgnore] public SectionWindow Window { get; set; }

 

         #endregion

 

@@ -157,7 +161,7 @@
             this.boxStyle = new GUIStyle(HighLogic.Skin.box)

             {

                 margin = new RectOffset(),

-                padding = new RectOffset(10, 10, 5, 5)

+                padding = new RectOffset(5, 5, 5, 5)

             };

 

             this.titleStyle = new GUIStyle(HighLogic.Skin.label)

@@ -228,7 +232,7 @@
                 }

                 else

                 {

-                    this.window.RequestResize();

+                    this.Window.RequestResize();

                 }

             }

         }


--- a/KerbalEngineer/KerbalEngineer.csproj
+++ b/KerbalEngineer/KerbalEngineer.csproj
@@ -66,6 +66,7 @@
     <Compile Include="Flight\DisplayStack.cs" />

     <Compile Include="Flight\FlightEngineerCore.cs" />

     <Compile Include="Flight\FlightEngineerModule.cs" />

+    <Compile Include="Flight\IUpdatable.cs" />

     <Compile Include="Flight\Readouts\Orbital\ApoapsisHeight.cs" />

     <Compile Include="Flight\Readouts\Orbital\Eccentricity.cs" />

     <Compile Include="Flight\Readouts\Orbital\Inclination.cs" />

@@ -80,13 +81,19 @@
     <Compile Include="Flight\Readouts\ReadoutCategory.cs" />

     <Compile Include="Flight\Readouts\ReadoutLibrary.cs" />

     <Compile Include="Flight\Readouts\ReadoutModule.cs" />

+    <Compile Include="Flight\Readouts\Rendezvous\TargetSelector.cs" />

     <Compile Include="Flight\Readouts\Surface\AltitudeSeaLevel.cs" />

     <Compile Include="Flight\Readouts\Surface\AltitudeTerrain.cs" />

+    <Compile Include="Flight\Readouts\Surface\AtmosphericDetails.cs" />

+    <Compile Include="Flight\Readouts\Surface\AtmosphericEfficiency.cs" />

     <Compile Include="Flight\Readouts\Surface\GeeForce.cs" />

     <Compile Include="Flight\Readouts\Surface\HorizontalSpeed.cs" />

     <Compile Include="Flight\Readouts\Surface\Latitude.cs" />

     <Compile Include="Flight\Readouts\Surface\Longitude.cs" />

+    <Compile Include="Flight\Readouts\Surface\TerminalVelocity.cs" />

     <Compile Include="Flight\Readouts\Surface\VerticalSpeed.cs" />

+    <Compile Include="Flight\Readouts\Vessel\DeltaVStaged.cs" />

+    <Compile Include="Flight\Readouts\Vessel\DeltaVTotal.cs" />

     <Compile Include="Flight\Sections\SectionEditor.cs" />

     <Compile Include="Flight\Sections\SectionLibrary.cs" />

     <Compile Include="Flight\Sections\SectionModule.cs" />

@@ -104,10 +111,7 @@
     <Compile Include="Simulation\Stage.cs" />

     <Compile Include="TapeDriveAnimator.cs" />

   </ItemGroup>

-  <ItemGroup>

-    <Folder Include="Flight\Readouts\Rendezvous\" />

-    <Folder Include="Flight\Readouts\Vessel\" />

-  </ItemGroup>

+  <ItemGroup />

   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

   <PropertyGroup>

     <PostBuildEvent>xcopy "$(SolutionDir)Output\*" "$(SolutionDir)Game\GameData\*" /E /Y</PostBuildEvent>


--- a/KerbalEngineer/Simulation/SimulationManager.cs
+++ b/KerbalEngineer/Simulation/SimulationManager.cs
@@ -10,29 +10,38 @@
 using System.Linq;

 using System.Threading;

 

+using KerbalEngineer.Flight;

+

 using UnityEngine;

 

 #endregion

 

 namespace KerbalEngineer.Simulation

 {

-    public class SimulationManager

+    public class SimulationManager : IUpdatable

     {

-        private static bool bRequested;

-        private static bool bRunning;

-        private static readonly Stopwatch timer = new Stopwatch();

-        private static long delayBetweenSims;

+        private static readonly SimulationManager instance = new SimulationManager();

 

-        private static Stopwatch _func = new Stopwatch();

+        public static SimulationManager Instance

+        {

+            get { return instance; }

+        }

 

-        public static Stage[] Stages { get; private set; }

-        public static Stage LastStage { get; private set; }

-        public static String failMessage { get; private set; }

+        private bool bRequested;

+        private bool bRunning;

+        private readonly Stopwatch timer = new Stopwatch();

+        private long delayBetweenSims;

 

-        public static double Gravity { get; set; }

-        public static double Atmosphere { get; set; }

+        private Stopwatch _func = new Stopwatch();

 

-        public static void RequestSimulation()

+        public Stage[] Stages { get; private set; }

+        public Stage LastStage { get; private set; }

+        public String failMessage { get; private set; }

+

+        public double Gravity { get; set; }

+        public double Atmosphere { get; set; }

+

+        public void RequestSimulation()

         {

             bRequested = true;

             if (!timer.IsRunning)

@@ -41,7 +50,7 @@
             }

         }

 

-        public static void TryStartSimulation()

+        public void TryStartSimulation()

         {

             if (bRequested && !bRunning && (HighLogic.LoadedSceneIsEditor || FlightGlobals.ActiveVessel != null) && timer.ElapsedMilliseconds > delayBetweenSims)

             {

@@ -51,19 +60,19 @@
             }

         }

 

-        public static bool ResultsReady()

+        public bool ResultsReady()

         {

             return !bRunning;

         }

 

-        private static void ClearResults()

+        private void ClearResults()

         {

             failMessage = "";

             Stages = null;

             LastStage = null;

         }

 

-        private static void StartSimulation()

+        private void StartSimulation()

         {

             try

             {

@@ -74,7 +83,7 @@
                 List<Part> parts = HighLogic.LoadedSceneIsEditor ? EditorLogic.SortedShipList : FlightGlobals.ActiveVessel.Parts;

 

                 // Create the Simulation object in this thread

-                Simulation sim = new Simulation();

+                var sim = new Simulation();

 

                 // This call doesn't ever fail at the moment but we'll check and return a sensible error for display

                 if (sim.PrepareSimulation(parts, Gravity, Atmosphere))

@@ -95,7 +104,7 @@
             }

         }

 

-        private static void RunSimulation(object simObject)

+        private void RunSimulation(object simObject)

         {

             try

             {

@@ -126,5 +135,10 @@
 

             bRunning = false;

         }

+

+        public void Update()

+        {

+            this.TryStartSimulation();

+        }

     }

 }

 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ