/
SimVesselManager.cs
72 lines (61 loc) · 2.16 KB
/
SimVesselManager.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
#nullable enable
using System.Collections.Generic;
namespace MechJebLib.Simulations
{
public partial class SimVesselManager
{
private readonly SimVesselBuilder _builder;
private readonly SimVesselUpdater _updater;
private SimVessel _vessel;
private IShipconstruct _kspVessel;
private readonly FuelFlowSimulation _fuelFlowSimulation = new FuelFlowSimulation();
private readonly Dictionary<Part, SimPart> _partMapping = new Dictionary<Part, SimPart>();
private readonly Dictionary<SimPart, Part> _inversePartMapping = new Dictionary<SimPart, Part>();
private readonly Dictionary<SimPartModule, PartModule> _inversePartModuleMapping = new Dictionary<SimPartModule, PartModule>();
public SimVesselManager()
{
_builder = new SimVesselBuilder(this);
_updater = new SimVesselUpdater(this);
_vessel = SimVessel.Borrow();
_kspVessel = null!;
}
public void Build(IShipconstruct vessel)
{
Clear();
_builder.BuildVessel(vessel);
_builder.BuildParts();
Update();
_builder.UpdateLinks();
_builder.UpdateCrossFeedSet();
DecouplingAnalyzer.Analyze(_vessel);
_builder.UpdateEngineSet();
}
public void Update()
{
_updater.Update();
}
public void SetConditions(double atmDensity, double atmPressure, double machNumber)
{
_vessel.SetConditions(atmDensity, atmPressure, machNumber);
}
public void RunFuelFlowSimulation()
{
_fuelFlowSimulation.Run(_vessel);
}
public List<FuelStats> GetFuelFlowResults()
{
return _fuelFlowSimulation.Segments;
}
private void Clear()
{
_partMapping.Clear();
_inversePartMapping.Clear();
_inversePartModuleMapping.Clear();
}
public void Release()
{
Clear();
_vessel.Dispose();
}
}
}