minor tweaks
[VesselSimulator.git] / KerbalEngineer / Flight / Readouts / Vessel / SimulationProcessor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using KerbalEngineer.VesselSimulator;
 
namespace KerbalEngineer.Flight.Readouts.Vessel
{
    public class SimulationProcessor : IUpdatable, IUpdateRequest
    {
        #region Instance
        private static readonly SimulationProcessor instance = new SimulationProcessor();
 
        /// <summary>
        ///     Gets the current instance of the simulation processor.
        /// </summary>
        public static SimulationProcessor Instance
        {
            get { return instance; }
        }
        #endregion
 
        #region Properties
 
        /// <summary>
        ///     Gets whether the details are ready to be shown.
        /// </summary>
        public static bool ShowDetails { get; private set; }
 
        /// <summary>
        ///     Gets an array of the vessel stages.
        /// </summary>
        public static Stage[] Stages { get; private set; }
 
        /// <summary>
        ///     Gets the currently active vessel stage.
        /// </summary>
        public static Stage LastStage { get; private set; }
 
        #endregion
 
        public void Update()
        {
            SimManager.RequestSimulation();
 
            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;
            }
            // Cybutek: We should be allowing this to be set too but not sure where you want to put the control
            //SimManager.vectoredThrust = vectoredThrust; 
            SimManager.TryStartSimulation();
        }
 
        public bool UpdateRequested { get; set; }
 
        public static void RequestUpdate()
        {
            instance.UpdateRequested = true;
        }
    }
}