Skip to content

Commit

Permalink
Lots of code cleanup
Browse files Browse the repository at this point in the history
Shouldn't be any behavioral changes.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Oct 16, 2023
1 parent 82b714e commit 684b65e
Show file tree
Hide file tree
Showing 113 changed files with 1,121 additions and 2,474 deletions.
1 change: 1 addition & 0 deletions MechJeb2.sln.DotSettings
Expand Up @@ -12,6 +12,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ENU/@EntryIndexedValue">ENU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FFS/@EntryIndexedValue">FFS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FPA/@EntryIndexedValue">FPA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HS/@EntryIndexedValue">HS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPVG/@EntryIndexedValue">IPVG</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ISP/@EntryIndexedValue">ISP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IVP/@EntryIndexedValue">IVP</s:String>
Expand Down
5 changes: 1 addition & 4 deletions MechJeb2/AttitudeControllers/BaseAttitudeController.cs
Expand Up @@ -58,9 +58,6 @@ public virtual void GUI()
{
}

public virtual void Reset(int i)
{
Reset();
}
public virtual void Reset(int i) => Reset();
}
}
5 changes: 1 addition & 4 deletions MechJeb2/AttitudeControllers/KosPIDLoop.cs
Expand Up @@ -65,10 +65,7 @@ public double Update(double input, double setpoint, double minOutput, double max
return Update(input);
}

public double Update(double input, double setpoint, double maxOutput)
{
return Update(input, setpoint, -maxOutput, maxOutput);
}
public double Update(double input, double setpoint, double maxOutput) => Update(input, setpoint, -maxOutput, maxOutput);

public double Update(double input)
{
Expand Down
13 changes: 5 additions & 8 deletions MechJeb2/AttitudeControllers/MJAttitudeController.cs
Expand Up @@ -104,7 +104,7 @@ public void setPIDParameters()
pid.Ki = 1 / (kiFactor * Math.Sqrt(2)) * pid.Kp;
pid.Ki.Scale(invTf);

pid.intAccum = pid.intAccum.Clamp(-5, 5);
pid.INTAccum = pid.INTAccum.Clamp(-5, 5);
}

public void tuneTf(Vector3d torque)
Expand Down Expand Up @@ -142,10 +142,7 @@ public override void ResetConfig()
kWlimit = 0.15;
}

public override void Reset()
{
pid.Reset();
}
public override void Reset() => pid.Reset();

public override void DrivePre(FlightCtrlState s, out Vector3d act, out Vector3d deltaEuler)
{
Expand Down Expand Up @@ -332,17 +329,17 @@ public override void GUI()

GUILayout.BeginHorizontal();
GUILayout.Label(Localizer.Format("#MechJeb_AttitudeController_label16"), GUILayout.ExpandWidth(true)); //"prop. action."
GUILayout.Label(MuUtils.PrettyPrint(pid.propAct), GUILayout.ExpandWidth(false));
GUILayout.Label(MuUtils.PrettyPrint(pid.PropAct), GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label(Localizer.Format("#MechJeb_AttitudeController_label17"), GUILayout.ExpandWidth(true)); //"deriv. action"
GUILayout.Label(MuUtils.PrettyPrint(pid.derivativeAct), GUILayout.ExpandWidth(false));
GUILayout.Label(MuUtils.PrettyPrint(pid.DerivativeAct), GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label(Localizer.Format("#MechJeb_AttitudeController_label18"), GUILayout.ExpandWidth(true)); //"integral action."
GUILayout.Label(MuUtils.PrettyPrint(pid.intAccum), GUILayout.ExpandWidth(false));
GUILayout.Label(MuUtils.PrettyPrint(pid.INTAccum), GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
Expand Down
5 changes: 1 addition & 4 deletions MechJeb2/AttitudeControllers/TorquePI.cs
Expand Up @@ -16,9 +16,6 @@ public double Update(double input, double setpoint, double MomentOfInertia, doub
return Loop.Update(input, setpoint, maxOutput);
}

public void ResetI()
{
Loop.ResetI();
}
public void ResetI() => Loop.ResetI();
}
}
19 changes: 5 additions & 14 deletions MechJeb2/AutopilotModule.cs
Expand Up @@ -37,18 +37,9 @@ public override void OnFixedUpdate()
}
}

protected void SetStep(AutopilotStep step)
{
CurrentStep = step;
}
protected void SetStep(AutopilotStep step) => CurrentStep = step;

public string Status
{
get
{
return CurrentStep == null ? "Off" : CurrentStep.Status;
}
}
public string Status => CurrentStep == null ? "Off" : CurrentStep.Status;

protected bool Active => CurrentStep != null;

Expand All @@ -67,11 +58,11 @@ public class AutopilotStep

protected AutopilotStep(MechJebCore core)
{
this.Core = core;
Core = core;
}

public virtual AutopilotStep Drive(FlightCtrlState s) { return this; }
public virtual AutopilotStep OnFixedUpdate() { return this; }
public virtual AutopilotStep Drive(FlightCtrlState s) => this;
public virtual AutopilotStep OnFixedUpdate() => this;
public string Status { get; protected set; }
}
}
10 changes: 2 additions & 8 deletions MechJeb2/CachedLocalizer.cs
Expand Up @@ -86,15 +86,9 @@ public static void Bootstrap()
Instance = go.AddComponent<CachedLocalizer>();
}

public void OnDestroy()
{
Instance = null;
}
public void OnDestroy() => Instance = null;

public void Awake()
{
UpdateCachedStrings();
}
public void Awake() => UpdateCachedStrings();

private void UpdateCachedStrings()
{
Expand Down
20 changes: 5 additions & 15 deletions MechJeb2/CompatibilityChecker.cs
Expand Up @@ -85,22 +85,18 @@ public static bool IsCompatible()
\*-----------------------------------------------*/
}

public static bool IsUnityCompatible()
{
public static bool IsUnityCompatible() =>
/*-----------------------------------------------*\
| BEGIN IMPLEMENTATION-SPECIFIC EDITS HERE. |
\*-----------------------------------------------*/

// TODO: Implement your own Unity compatibility check.
//
// MJ is not going to care about the fact that KSP .25 OSX uses a different Unity.
return true;
true;

/*-----------------------------------------------*\
/*-----------------------------------------------*\
| IMPLEMENTERS SHOULD NOT EDIT BEYOND THIS POINT! |
\*-----------------------------------------------*/
}

// Version of the compatibility checker itself.
private static int _version = 5;

Expand Down Expand Up @@ -210,15 +206,9 @@ public void Start()
}
}

public static bool IsWin64()
{
return IntPtr.Size == 8 && Environment.OSVersion.Platform == PlatformID.Win32NT;
}
public static bool IsWin64() => IntPtr.Size == 8 && Environment.OSVersion.Platform == PlatformID.Win32NT;

public static bool IsAllCompatible()
{
return IsCompatible() && IsUnityCompatible(); // && !IsWin64();
}
public static bool IsAllCompatible() => IsCompatible() && IsUnityCompatible(); // && !IsWin64();

private static IEnumerable<Type> getAllTypes()
{
Expand Down
35 changes: 8 additions & 27 deletions MechJeb2/ComputerModule.cs
Expand Up @@ -35,10 +35,7 @@ public class ComputerModule : IComparable<ComputerModule>

public bool UnlockChecked;

public int CompareTo(ComputerModule other)
{
return other == null ? 1 : Priority.CompareTo(other.Priority);
}
public int CompareTo(ComputerModule other) => other == null ? 1 : Priority.CompareTo(other.Priority);

private bool _enabled;

Expand Down Expand Up @@ -185,10 +182,7 @@ public virtual void OnDestroy()
{
}

protected virtual bool IsSpaceCenterUpgradeUnlocked()
{
return true;
}
protected virtual bool IsSpaceCenterUpgradeUnlocked() => true;

public virtual void UnlockCheck()
{
Expand Down Expand Up @@ -242,27 +236,15 @@ public virtual void UnlockCheck()
}
}

protected static void Print(object message)
{
MonoBehaviour.print("[MechJeb2] " + message);
}
protected static void Print(object message) => MonoBehaviour.print("[MechJeb2] " + message);

[UsedImplicitly]
public void Disable()
{
Enabled = false;
}
public void Disable() => Enabled = false;

[UsedImplicitly]
public void Enable()
{
Enabled = true;
}
public void Enable() => Enabled = true;

public void CascadeDisable(ComputerModule m)
{
ModuleDisabledEvents.Add(m.Disable);
}
public void CascadeDisable(ComputerModule m) => ModuleDisabledEvents.Add(m.Disable);
}

[Flags]
Expand All @@ -275,9 +257,9 @@ public enum Pass

public class ModuleEvent
{
public delegate void OnEvent();
public delegate void OnEvent();

private readonly List<OnEvent> _events = new List<OnEvent>();
private readonly List<OnEvent> _events = new List<OnEvent>();
private readonly Dictionary<OnEvent, int> _eventIndex = new Dictionary<OnEvent, int>();

public void Add(OnEvent evt)
Expand Down Expand Up @@ -307,7 +289,6 @@ public void Clear()

public void Fire(bool reverse)
{

if (reverse)
{
for (int i = _events.Count - 1; i >= 0; i--)
Expand Down
20 changes: 4 additions & 16 deletions MechJeb2/DisplayModule.cs
Expand Up @@ -135,10 +135,7 @@ public DisplayModule(MechJebCore core)
nextID++;
}

public virtual GUILayoutOption[] WindowOptions()
{
return new GUILayoutOption[0];
}
public virtual GUILayoutOption[] WindowOptions() => new GUILayoutOption[0];

protected void WindowGUI(int windowID, bool draggable)
{
Expand Down Expand Up @@ -172,10 +169,7 @@ protected void ProfiledWindowGUI(int windowID)
Profiler.EndSample();
}

protected virtual void WindowGUI(int windowID)
{
WindowGUI(windowID, true);
}
protected virtual void WindowGUI(int windowID) => WindowGUI(windowID, true);

public virtual void DrawGUI(bool inEditor)
{
Expand Down Expand Up @@ -320,14 +314,8 @@ public override void UnlockCheck()
}
}

public virtual string GetName()
{
return "Display Module";
}
public virtual string GetName() => "Display Module";

public virtual string IconName()
{
return "Display Module Icon";
}
public virtual string IconName() => "Display Module Icon";
}
}
5 changes: 1 addition & 4 deletions MechJeb2/FlyingSim/SimulatedParachute.cs
Expand Up @@ -30,10 +30,7 @@ public class SimulatedParachute : SimulatedPart

public new static int PoolSize => pool.Size;

private static SimulatedParachute Create()
{
return new SimulatedParachute();
}
private static SimulatedParachute Create() => new SimulatedParachute();

public override void Release()
{
Expand Down
12 changes: 4 additions & 8 deletions MechJeb2/FlyingSim/SimulatedPart.cs
Expand Up @@ -189,16 +189,12 @@ public virtual Vector3d Lift(Vector3d vesselVelocity, double liftFactor)
}

public virtual bool SimulateAndRollback(double altATGL, double altASL, double endASL, double pressure, double shockTemp, double time,
double semiDeployMultiplier)
{
return false;
}
double semiDeployMultiplier) =>
false;

public virtual bool Simulate(double altATGL, double altASL, double endASL, double pressure, double shockTemp, double time,
double semiDeployMultiplier)
{
return false;
}
double semiDeployMultiplier) =>
false;

public static class DragCubePool
{
Expand Down
10 changes: 2 additions & 8 deletions MechJeb2/FlyingSim/SimulatedVessel.cs
Expand Up @@ -15,15 +15,9 @@ public class SimulatedVessel

public static int PoolSize => pool.Size;

private static SimulatedVessel Create()
{
return new SimulatedVessel();
}
private static SimulatedVessel Create() => new SimulatedVessel();

public void Release()
{
pool.Release(this);
}
public void Release() => pool.Release(this);

private static void Reset(SimulatedVessel obj)
{
Expand Down
4 changes: 1 addition & 3 deletions MechJeb2/GLUtils.cs
Expand Up @@ -18,10 +18,8 @@ private static Material material
}

public static void DrawMapViewGroundMarker(CelestialBody body, double latitude, double longitude, Color c, double rotation = 0,
double radius = 0)
{
double radius = 0) =>
DrawGroundMarker(body, latitude, longitude, c, true, rotation, radius);
}

public static void DrawGroundMarker(CelestialBody body, double latitude, double longitude, Color c, bool map, double rotation = 0,
double radius = 0)
Expand Down

0 comments on commit 684b65e

Please sign in to comment.