Skip to content

Commit

Permalink
Make fields readonly
Browse files Browse the repository at this point in the history
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Nov 1, 2023
1 parent 95ae54a commit faf0377
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 173 deletions.
2 changes: 1 addition & 1 deletion MechJeb2/FlyingSim/SimulatedPart.cs
Expand Up @@ -6,7 +6,7 @@ namespace MuMech
{
public class SimulatedPart
{
protected DragCubeList cubes = new DragCubeList();
protected readonly DragCubeList cubes = new DragCubeList();

public double totalMass;
public bool shieldedFromAirstream;
Expand Down
6 changes: 3 additions & 3 deletions MechJeb2/FlyingSim/SimulatedVessel.cs
Expand Up @@ -5,9 +5,9 @@ namespace MuMech
{
public class SimulatedVessel
{
public List<SimulatedPart> parts = new List<SimulatedPart>();
private int count;
public double totalMass;
public readonly List<SimulatedPart> parts = new List<SimulatedPart>();
private int count;
public double totalMass;

private ReentrySimulation.SimCurves simCurves;

Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/Maneuver/OperationAdvancedTransfer.cs
Expand Up @@ -31,7 +31,7 @@ private enum Mode
private double maxDepartureTime;
private double maxTransferTime;

public EditableTime maxArrivalTime = new EditableTime();
public readonly EditableTime maxArrivalTime = new EditableTime();

private bool includeCaptureBurn;

Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/MechJebLib/Core/ODE/Event.cs
Expand Up @@ -19,8 +19,8 @@ public class Event : IComparable<Event>
public readonly AssertFunc? Assert;
public bool SaveBefore = true;
public bool SaveAfter = true;
public bool Terminal = true;
public int Direction = 0;
public readonly bool Terminal = true;
public readonly int Direction = 0;
public double LastValue;
public double NewValue;
public double Time;
Expand Down
18 changes: 9 additions & 9 deletions MechJeb2/MechJebLib/PVG/Optimizer.cs
Expand Up @@ -16,15 +16,15 @@ namespace MechJebLib.PVG
{
public partial class Optimizer : IDisposable
{
public double ZnormTerminationLevel = 1e-9;
public double Znorm;
public int MaxIter { get; set; } = 200000; // rely more on the optimizertimeout instead of iterations
public double LmEpsx { get; set; } = EPS; // rely more on manual termination at znorm=1e-9
public double LmDiffStep { get; set; } = 1e-10;
public int OptimizerTimeout { get; set; } = 5000; // milliseconds
public int LmStatus;
public int LmIterations;
public OptimStatus Status;
public readonly double ZnormTerminationLevel = 1e-9;
public double Znorm;
public int MaxIter { get; set; } = 200000; // rely more on the optimizertimeout instead of iterations
public double LmEpsx { get; set; } = EPS; // rely more on manual termination at znorm=1e-9
public double LmDiffStep { get; set; } = 1e-10;
public int OptimizerTimeout { get; set; } = 5000; // milliseconds
public int LmStatus;
public int LmIterations;
public OptimStatus Status;

private readonly Problem _problem;
private readonly List<Phase> _phases;
Expand Down
42 changes: 21 additions & 21 deletions MechJeb2/MechJebLib/PVG/Phase.cs
Expand Up @@ -16,21 +16,21 @@ namespace MechJebLib.PVG
{
public class Phase
{
public double m0;
public double thrust;
public double isp;
public double mf;
public double bt;
public double maxt;
public double mint;
public double ve;
public double a0;
public double tau;
public double mdot;
public double dv;
public double DropMass; // FIXME: unused
public bool OptimizeTime;
public bool Infinite = false;
public double m0;
public double thrust;
public readonly double isp;
public double mf;
public double bt;
public double maxt;
public double mint;
public double ve;
public readonly double a0;
public double tau;
public double mdot;
public double dv;
public double DropMass; // FIXME: unused
public bool OptimizeTime;
public bool Infinite = false;

private bool _analytic = true;

Expand All @@ -44,12 +44,12 @@ public bool Analytic
}
}

public bool Unguided;
public bool MassContinuity = false;
public bool LastFreeBurn = false;
public bool Normalized;
public int KSPStage;
public int MJPhase;
public bool Unguided;
public readonly bool MassContinuity = false;
public bool LastFreeBurn = false;
public bool Normalized;
public readonly int KSPStage;
public readonly int MJPhase;

private IPVGIntegrator? _ipvgIntegrator;

Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleAttitudeController.cs
Expand Up @@ -36,7 +36,7 @@ public class MechJebModuleAttitudeController : ComputerModule
[Persistent(pass = (int)Pass.GLOBAL)]
[ValueInfoItem("#MechJeb_SteeringError", InfoItem.Category.Vessel, format = "F1", units = "º")]
//Steering error
public MovingAverage steeringError = new MovingAverage();
public readonly MovingAverage steeringError = new MovingAverage();

public bool attitudeKILLROT;

Expand Down
44 changes: 22 additions & 22 deletions MechJeb2/MechJebModuleCustomInfoWindow.cs
Expand Up @@ -209,9 +209,9 @@ public void FromSharingString(string[] lines, List<InfoItem> registry)

public class MechJebModuleCustomWindowEditor : DisplayModule
{
public List<InfoItem> registry = new List<InfoItem>();
public MechJebModuleCustomInfoWindow editedWindow;
private int selectedItemIndex = -1;
public readonly List<InfoItem> registry = new List<InfoItem>();
public MechJebModuleCustomInfoWindow editedWindow;
private int selectedItemIndex = -1;

[UsedImplicitly]
[Persistent(pass = (int)Pass.GLOBAL)]
Expand Down Expand Up @@ -601,11 +601,11 @@ public MechJebModuleCustomInfoWindow CreateWindowFromSharingString(string sharin

public class InfoItem
{
public string name;
public string localizedName;
public string description;
public bool showInEditor;
public bool showInFlight;
public readonly string name;
public readonly string localizedName;
public readonly string description;
public readonly bool showInEditor;
public readonly bool showInFlight;

public enum Category
{
Expand All @@ -619,7 +619,7 @@ public enum Category
Misc
}

public Category category;
public readonly Category category;

[Persistent]
public string id;
Expand Down Expand Up @@ -808,8 +808,8 @@ public override void UpdateItem()

public class EditableInfoItem : InfoItem
{
public string rightLabel;
public float width;
public readonly string rightLabel;
public readonly float width;
private readonly IEditable val;

public EditableInfoItem(object obj, MemberInfo member, EditableInfoItemAttribute attribute)
Expand All @@ -835,11 +835,11 @@ public override void DrawItem()

public abstract class InfoItemAttribute : Attribute
{
public string name; //the name displayed in the info window
public InfoItem.Category category;
public string description = ""; //the description shown in the window editor list
public bool showInEditor = false;
public bool showInFlight = true;
public readonly string name; //the name displayed in the info window
public InfoItem.Category category;
public string description = ""; //the description shown in the window editor list
public bool showInEditor = false;
public bool showInFlight = true;

public InfoItemAttribute(string name, InfoItem.Category category)
{
Expand All @@ -853,11 +853,11 @@ public InfoItemAttribute(string name, InfoItem.Category category)
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method)]
public class ValueInfoItemAttribute : InfoItemAttribute
{
public string units = "";
public string format = "";
public int siSigFigs = 4;
public int siMaxPrecision = -33;
public int timeDecimalPlaces = 0;
public string units = "";
public string format = "";
public int siSigFigs = 4;
public readonly int siMaxPrecision = -33;
public int timeDecimalPlaces = 0;

public ValueInfoItemAttribute(string name, InfoItem.Category category) : base(name, category) { }
}
Expand Down Expand Up @@ -902,7 +902,7 @@ public struct Preset
public string sharingString;
}

public static Preset[] presets =
public static readonly Preset[] presets =
{
new Preset
{
Expand Down
4 changes: 2 additions & 2 deletions MechJeb2/MechJebModuleDebugArrows.cs
Expand Up @@ -32,7 +32,7 @@ internal class MechJebModuleDebugArrows : ComputerModule
public static DebugIcoSphere cotSphere;

[Persistent(pass = (int)Pass.GLOBAL)]
public EditableDouble comSphereRadius = new EditableDouble(0.09);
public readonly EditableDouble comSphereRadius = new EditableDouble(0.09);

[Persistent(pass = (int)Pass.GLOBAL)]
public bool srfVelocityArrowActive;
Expand Down Expand Up @@ -78,7 +78,7 @@ internal class MechJebModuleDebugArrows : ComputerModule
public static Vector3d debugVector2 = Vector3d.one;

[Persistent(pass = (int)Pass.GLOBAL)]
public EditableDouble arrowsLength = new EditableDouble(4);
public readonly EditableDouble arrowsLength = new EditableDouble(4);

public MechJebModuleDebugArrows(MechJebCore core) : base(core)
{
Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleDeployableController.cs
Expand Up @@ -26,7 +26,7 @@ public MechJebModuleDeployableController(MechJebCore core) : base(core)

protected string type = "";

protected List<ModuleDeployablePart> cachedPartModules = new List<ModuleDeployablePart>(16);
protected readonly List<ModuleDeployablePart> cachedPartModules = new List<ModuleDeployablePart>(16);

protected void DiscoverDeployablePartModules()
{
Expand Down
2 changes: 1 addition & 1 deletion MechJeb2/MechJebModuleDockingAutopilot.cs
Expand Up @@ -15,7 +15,7 @@ public class MechJebModuleDockingAutopilot : ComputerModule
public EditableDouble speedLimit = 1;

[Persistent(pass = (int)Pass.LOCAL)]
public EditableDouble rol = new EditableDouble(0);
public readonly EditableDouble rol = new EditableDouble(0);

[Persistent(pass = (int)Pass.LOCAL)]
public bool forceRol = false;
Expand Down
12 changes: 6 additions & 6 deletions MechJeb2/MechJebModuleLandingPredictions.cs
Expand Up @@ -117,14 +117,14 @@ public double
protected bool
errorSimulationRunning; // the predictor can run two types of simulation - 1) simulations of the current situation. 2) simulations of the current situation with deliberate error introduced into the parachute multiplier to aid the statistical analysis of these results.

protected Stopwatch errorStopwatch = new Stopwatch();
protected long millisecondsBetweenErrorSimulations;
protected readonly Stopwatch errorStopwatch = new Stopwatch();
protected long millisecondsBetweenErrorSimulations;

public bool SimulationRunning { get; private set; }

protected Stopwatch stopwatch = new Stopwatch();
public double SimulationRunningTime => SimulationRunning ? stopwatch.ElapsedMilliseconds / 1000d : 0;
protected long millisecondsBetweenSimulations;
protected readonly Stopwatch stopwatch = new Stopwatch();
public double SimulationRunningTime => SimulationRunning ? stopwatch.ElapsedMilliseconds / 1000d : 0;
protected long millisecondsBetweenSimulations;

protected ReentrySimulation.Result result;
protected ReentrySimulation.Result errorResult;
Expand All @@ -137,7 +137,7 @@ protected double
dt = 0.2; // the suggested dt for each timestep in the simulations. This will be adjusted depending on how long the simulations take to run if variabledt is active

// TODO - decide if variable for fixed dt results in a more stable result
protected bool
protected readonly bool
variabledt = false; // Set this to true to allow the predictor to choose a dt based on how long each run is taking, and false to use a fixed dt.

public bool noSkipToFreefall = false;
Expand Down
6 changes: 3 additions & 3 deletions MechJeb2/MechJebModuleMenu.cs
Expand Up @@ -128,11 +128,11 @@ public Rect buttonPos

[ToggleInfoItem("#MechJeb_HideMenuButton", InfoItem.Category.Misc)]
[Persistent(pass = (int)Pass.GLOBAL)]
public bool hideButton = false; //Hide Menu Button
public readonly bool hideButton = false; //Hide Menu Button

[ToggleInfoItem("#MechJeb_UseAppLauncher", InfoItem.Category.Misc)]
[Persistent(pass = (int)Pass.GLOBAL)]
public bool useAppLauncher = true; //Use AppLauncher
public readonly bool useAppLauncher = true; //Use AppLauncher

[GeneralInfoItem("#MechJeb_MenuPosition", InfoItem.Category.Misc)] //Menu Position
private void MenuPosition()
Expand Down Expand Up @@ -641,7 +641,7 @@ private DisplayOrder()
{
}

public static DisplayOrder instance = new DisplayOrder();
public static readonly DisplayOrder instance = new DisplayOrder();

int IComparer<DisplayModule>.Compare(DisplayModule a, DisplayModule b)
{
Expand Down
10 changes: 5 additions & 5 deletions MechJeb2/MechJebModuleRCSBalancer.cs
Expand Up @@ -28,25 +28,25 @@ public class MechJebModuleRCSBalancer : ComputerModule
// threshold' tuning parameter, because waste thresholds of 1 or above
// cause problems by allowing unhelpful thrusters to fire.
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
public EditableDouble overdriveScale = 0.9;
public readonly EditableDouble overdriveScale = 0.9;

// Advanced: tuning parameters
[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
public EditableDouble tuningParamFactorTorque = 1;
public readonly EditableDouble tuningParamFactorTorque = 1;

[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
public EditableDouble tuningParamFactorTranslate = 0.005;
public readonly EditableDouble tuningParamFactorTranslate = 0.005;

[Persistent(pass = (int)(Pass.TYPE | Pass.GLOBAL))]
public EditableDouble tuningParamFactorWaste = 1;
public readonly EditableDouble tuningParamFactorWaste = 1;

// Variables for RCS solving.
private readonly RCSSolverThread solverThread = new RCSSolverThread();
private List<RCSSolver.Thruster> thrusters;
private double[] throttles;

[EditableInfoItem("#MechJeb_RCSBalancerPrecision", InfoItem.Category.Thrust)] //RCS balancer precision
public EditableInt calcPrecision = 3;
public readonly EditableInt calcPrecision = 3;

[GeneralInfoItem("#MechJeb_RCSBalancerInfo", InfoItem.Category.Thrust)] //RCS balancer info
public void RCSBalancerInfoItem()
Expand Down
18 changes: 9 additions & 9 deletions MechJeb2/MechJebModuleRCSController.cs
Expand Up @@ -9,10 +9,10 @@ public class MechJebModuleRCSController : ComputerModule
{
public Vector3d targetVelocity = Vector3d.zero;

public PIDControllerV2 pid;
private Vector3d lastAct = Vector3d.zero;
private Vector3d worldVelocityDelta = Vector3d.zero;
private Vector3d prev_worldVelocityDelta = Vector3d.zero;
public readonly PIDControllerV2 pid;
private Vector3d lastAct = Vector3d.zero;
private Vector3d worldVelocityDelta = Vector3d.zero;
private Vector3d prev_worldVelocityDelta = Vector3d.zero;

private enum ControlType
{
Expand All @@ -26,23 +26,23 @@ private enum ControlType

[Persistent(pass = (int)Pass.GLOBAL)]
[ToggleInfoItem("#MechJeb_conserveFuel", InfoItem.Category.Thrust)] //Conserve RCS fuel
public bool conserveFuel = false;
public readonly bool conserveFuel = false;

[EditableInfoItem("#MechJeb_conserveThreshold", InfoItem.Category.Thrust, rightLabel = "m/s")] //Conserve RCS fuel threshold
public EditableDouble conserveThreshold = 0.05;
public readonly EditableDouble conserveThreshold = 0.05;

[Persistent(pass = (int)(Pass.LOCAL | Pass.TYPE | Pass.GLOBAL))]
[EditableInfoItem("#MechJeb_RCSTf", InfoItem.Category.Thrust)] //RCS Tf
public EditableDouble Tf = 1;

[Persistent(pass = (int)(Pass.LOCAL | Pass.TYPE | Pass.GLOBAL))]
public EditableDouble Kp = 0.125;
public readonly EditableDouble Kp = 0.125;

[Persistent(pass = (int)(Pass.LOCAL | Pass.TYPE | Pass.GLOBAL))]
public EditableDouble Ki = 0.07;
public readonly EditableDouble Ki = 0.07;

[Persistent(pass = (int)(Pass.LOCAL | Pass.TYPE | Pass.GLOBAL))]
public EditableDouble Kd = 0.53;
public readonly EditableDouble Kd = 0.53;

[Persistent(pass = (int)Pass.GLOBAL)]
public bool rcsManualPID;
Expand Down

0 comments on commit faf0377

Please sign in to comment.