Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize VesselModules #151

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 29 additions & 37 deletions FerramAerospaceResearch/FARAeroComponents/FARVesselAero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ public double MaxCrossSectionArea
protected override void OnStart()
{
FARLogger.Info("FARVesselAero on " + vessel.name + " reporting startup");
base.OnStart();

if (!HighLogic.LoadedSceneIsFlight)
{
enabled = false;
return;
}

_currentGeoModules = new List<GeometryPartModule>();

Expand Down Expand Up @@ -159,45 +152,44 @@ protected override void OnStart()
enabled = true;
}

public override Activation GetActivation() => Activation.FlightScene | Activation.LoadedVessels;

private PartModule.StartState StartState()
{
PartModule.StartState startState = PartModule.StartState.None;
if (HighLogic.LoadedSceneIsEditor)
startState |= PartModule.StartState.Editor;
else if (HighLogic.LoadedSceneIsFlight)
switch (vessel.situation)
{
case Vessel.Situations.PRELAUNCH:
startState |= PartModule.StartState.PreLaunch;
startState |= PartModule.StartState.Landed;
break;
case Vessel.Situations.DOCKED:
startState |= PartModule.StartState.Docked;
break;
case Vessel.Situations.ORBITING:
case Vessel.Situations.ESCAPING:
startState |= PartModule.StartState.Orbital;
break;
case Vessel.Situations.SUB_ORBITAL:
startState |= PartModule.StartState.SubOrbital;
break;
case Vessel.Situations.SPLASHED:
startState |= PartModule.StartState.Splashed;
break;
case Vessel.Situations.FLYING:
startState |= PartModule.StartState.Flying;
break;
case Vessel.Situations.LANDED:
startState |= PartModule.StartState.Landed;
break;
}
switch (vessel.situation)
{
case Vessel.Situations.PRELAUNCH:
startState |= PartModule.StartState.PreLaunch;
startState |= PartModule.StartState.Landed;
break;
case Vessel.Situations.DOCKED:
startState |= PartModule.StartState.Docked;
break;
case Vessel.Situations.ORBITING:
case Vessel.Situations.ESCAPING:
startState |= PartModule.StartState.Orbital;
break;
case Vessel.Situations.SUB_ORBITAL:
startState |= PartModule.StartState.SubOrbital;
break;
case Vessel.Situations.SPLASHED:
startState |= PartModule.StartState.Splashed;
break;
case Vessel.Situations.FLYING:
startState |= PartModule.StartState.Flying;
break;
case Vessel.Situations.LANDED:
startState |= PartModule.StartState.Landed;
break;
}

return startState;
}

private void FixedUpdate()
{
if (_vehicleAero == null || !vessel.loaded)
if (_vehicleAero == null)
return;
if (_vehicleAero.CalculationCompleted)
{
Expand Down
33 changes: 16 additions & 17 deletions FerramAerospaceResearch/FARGUI/FARFlightGUI/FlightGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class FlightGUI : VesselModule
internal static GUIStyle buttonStyle;

private readonly StringBuilder _strBuilder = new StringBuilder();
private Vessel _vessel;
private FARVesselAero _vesselAero;

private PhysicsCalcs _physicsCalcs;
Expand Down Expand Up @@ -113,12 +112,10 @@ protected override void OnStart()
else
FARDebugAndSettings.FARDebugButtonStock.SetFalse(false);


_vessel = GetComponent<Vessel>();
_vesselAero = GetComponent<FARVesselAero>();
_physicsCalcs = new PhysicsCalcs(_vessel, _vesselAero);
_physicsCalcs = new PhysicsCalcs(vessel, _vesselAero);
_flightStatusGUI = new FlightStatusGUI();
_stabilityAugmentation = new StabilityAugmentation(_vessel);
_stabilityAugmentation = new StabilityAugmentation(vessel);
_flightDataGUI = new FlightDataGUI();
AeroVizGUI = new AeroVisualizationGUI();
debugGUI = new DebugGUI();
Expand All @@ -132,11 +129,11 @@ protected override void OnStart()
},
new[] { 0, 1, 2, 3 });

if (vesselFlightGUI.ContainsKey(_vessel))
vesselFlightGUI[_vessel] = this;
if (vesselFlightGUI.ContainsKey(vessel))
vesselFlightGUI[vessel] = this;
else
vesselFlightGUI.Add(_vessel, this);
flightDataLogger = FlightDataLogger.CreateLogger(_vessel);
vesselFlightGUI.Add(vessel, this);
flightDataLogger = FlightDataLogger.CreateLogger(vessel);

enabled = true;

Expand All @@ -145,21 +142,23 @@ protected override void OnStart()

activeFlightGUICount++;

if (_vessel == FlightGlobals.ActiveVessel || FlightGlobals.ActiveVessel == null)
if (vessel == FlightGlobals.ActiveVessel || FlightGlobals.ActiveVessel == null)
LoadConfigs();

GameEvents.onShowUI.Add(ShowUI);
GameEvents.onHideUI.Add(HideUI);
}

public override Activation GetActivation() => Activation.FlightScene | Activation.LoadedVessels;

private void OnDestroy()
{
FlightGUIDrawer.SetGUIActive(this, false);
GameEvents.onShowUI.Remove(ShowUI);
GameEvents.onHideUI.Remove(HideUI);
SaveConfigs();
if (_vessel)
vesselFlightGUI.Remove(_vessel);
if (vessel)
vesselFlightGUI.Remove(vessel);
_physicsCalcs = null;

_flightDataGUI?.SaveSettings();
Expand Down Expand Up @@ -196,7 +195,7 @@ private void OnDestroy()

public void SaveData()
{
if (_vessel != FlightGlobals.ActiveVessel)
if (vessel != FlightGlobals.ActiveVessel)
return;
SaveConfigs();
airSpeedGUI?.SaveSettings();
Expand Down Expand Up @@ -246,7 +245,7 @@ private void FixedUpdate()

private void Update()
{
FlightGUIDrawer.SetGUIActive(this, _vessel == FlightGlobals.ActiveVessel && showGUI && showAllGUI);
FlightGUIDrawer.SetGUIActive(this, vessel == FlightGlobals.ActiveVessel && showGUI && showAllGUI);
if (frameCountForSaving >= 120)
{
SaveActiveData();
Expand All @@ -262,8 +261,8 @@ private void LateUpdate()
{
if (airSpeedGUI != null)
airSpeedGUI.ChangeSurfVelocity();
else if (_vessel != null)
airSpeedGUI = new AirspeedSettingsGUI(_vessel);
else if (vessel != null)
airSpeedGUI = new AirspeedSettingsGUI(vessel);
}

public void DrawGUI()
Expand Down Expand Up @@ -291,7 +290,7 @@ public void DrawGUI()
buttonStyle.padding = new RectOffset(2, 2, 2, 2);
}

if (_vessel != FlightGlobals.ActiveVessel || !showGUI || !showAllGUI)
if (vessel != FlightGlobals.ActiveVessel || !showGUI || !showAllGUI)
return;
mainGuiRect = GUILayout.Window(GetHashCode(),
mainGuiRect,
Expand Down