Fixes to make flight engineer use correct gravity and velocity
[VesselSimulator.git] / KerbalEngineer / Flight / Readouts / Vessel / SimulationProcessor.cs
blob:a/KerbalEngineer/Flight/Readouts/Vessel/SimulationProcessor.cs -> blob:b/KerbalEngineer/Flight/Readouts/Vessel/SimulationProcessor.cs
--- a/KerbalEngineer/Flight/Readouts/Vessel/SimulationProcessor.cs
+++ b/KerbalEngineer/Flight/Readouts/Vessel/SimulationProcessor.cs
@@ -1,16 +1,57 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+// 
+//     Kerbal Engineer Redux
+// 
+//     Copyright (C) 2014 CYBUTEK
+// 
+//     This program is free software: you can redistribute it and/or modify
+//     it under the terms of the GNU General Public License as published by
+//     the Free Software Foundation, either version 3 of the License, or
+//     (at your option) any later version.
+// 
+//     This program is distributed in the hope that it will be useful,
+//     but WITHOUT ANY WARRANTY; without even the implied warranty of
+//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//     GNU General Public License for more details.
+// 
+//     You should have received a copy of the GNU General Public License
+//     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// 
 
-using KerbalEngineer.VesselSimulator;
+#region Using Directives
+
+
+
+#endregion
 
 namespace KerbalEngineer.Flight.Readouts.Vessel
 {
+    #region Using Directives
+
+    using System;
+    using VesselSimulator;
+
+    #endregion
+
     public class SimulationProcessor : IUpdatable, IUpdateRequest
     {
         #region Instance
+
+        #region Fields
+
         private static readonly SimulationProcessor instance = new SimulationProcessor();
+
+        #endregion
+
+        #region Constructors
+
+        static SimulationProcessor()
+        {
+            SimManager.OnReady += GetStageInfo;
+        }
+
+        #endregion
+
+        #region Properties
 
         /// <summary>
         ///     Gets the current instance of the simulation processor.
@@ -19,9 +60,17 @@
         {
             get { return instance; }
         }
+
         #endregion
 
-        #region Properies
+        #endregion
+
+        #region Properties
+
+        /// <summary>
+        ///     Gets the currently active vessel stage.
+        /// </summary>
+        public static Stage LastStage { get; private set; }
 
         /// <summary>
         ///     Gets whether the details are ready to be shown.
@@ -33,47 +82,47 @@
         /// </summary>
         public static Stage[] Stages { get; private set; }
 
-        /// <summary>
-        ///     Gets the currently active vessel stage.
-        /// </summary>
-        public static Stage LastStage { get; private set; }
+        public bool UpdateRequested { get; set; }
 
         #endregion
+
+        #region Methods
+
+        private static void GetStageInfo()
+        {
+            Stages = SimManager.Stages;
+            LastStage = SimManager.LastStage;
+        }
+
+        public static void RequestUpdate()
+        {
+            instance.UpdateRequested = true;
+        }
 
         public void Update()
         {
             SimManager.RequestSimulation();
+            SimManager.TryStartSimulation();
 
             if (!SimManager.ResultsReady())
             {
                 return;
             }
 
-            Stages = SimManager.Stages;
-            LastStage = SimManager.LastStage;
-
             if (Stages != null && LastStage != null)
             {
                 ShowDetails = true;
             }
 
-
             if (FlightGlobals.ActiveVessel != null)
             {
-                SimManager.Gravity = FlightGlobals.ActiveVessel.mainBody.gravParameter / Math.Pow(FlightGlobals.ActiveVessel.mainBody.Radius + FlightGlobals.ActiveVessel.mainBody.GetAltitude(FlightGlobals.ActiveVessel.CoM), 2);
-                SimManager.Velocity = FlightGlobals.ActiveVessel.srfSpeed;
+                SimManager.Gravity = FlightGlobals.ActiveVessel.mainBody.gravParameter /
+                                     Math.Pow(FlightGlobals.ActiveVessel.mainBody.Radius +
+                                              FlightGlobals.ActiveVessel.mainBody.GetAltitude(FlightGlobals.ActiveVessel.CoM), 2);
+                SimManager.Mach = FlightGlobals.ActiveVessel.mach;
             }
-            // We should be allowing this to be set too...
-            //SimManager.vectoredThrust = vectoredThrust; 
-            SimManager.TryStartSimulation();
         }
 
-        public bool UpdateRequested { get; set; }
-
-        public static void RequestUpdate()
-        {
-            instance.UpdateRequested = true;
-        }
+        #endregion
     }
 }
-