Skip to content
Merged
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
1 change: 1 addition & 0 deletions MechJeb2/MechJebModuleStageStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private void RunSimulation()
_vesselManagerAtmo.SetConditions(atmDensity, staticPressureKpa * PhysicsGlobals.KpaToAtmospheres, mach);
_vesselManagerAtmo.SetInitial(VesselState.Time, VesselState.OrbitalPosition.WorldToV3Rotated(),
VesselState.OrbitalVelocity.WorldToV3Rotated(), VesselState.Forward.WorldToV3Rotated());
//_vesselManagerAtmo.PrintVessel();
if (!_vesselManagerAtmo.TryStartFuelFlowSimulationJob())
throw new Exception("[MechJebModuleStageStats] could not start atmo stats job");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ private static void Clear(SimLaunchClamp m)
{
}

public override string ToString() => Invariant($"SimLaunchClamp: {CommonFields()}");
public override string ToString() => ModuleLine("SimLaunchClamp", CommonFieldList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: LicenseRef-PD-hp OR Unlicense OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT OR LGPL-2.1+
*/

using System.Collections.Generic;
using MechJebLib.Utils;
using static System.FormattableString;

Expand Down Expand Up @@ -30,7 +31,11 @@ private static void Clear(SimModuleAvionics m)
{
}

public override string ToString() =>
Invariant($"SimModuleAvionics: {CommonFields()} ControllableMass={ControllableMass}");
public override string ToString()
{
List<string> fields = CommonFieldList();
AddField(fields, "ControllableMass", ControllableMass, 0);
return ModuleLine("SimModuleAvionics", fields);
}
}
}
20 changes: 14 additions & 6 deletions MechJebLib/FuelFlowSimulation/PartModules/SimModuleDecouple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: LicenseRef-PD-hp OR Unlicense OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT OR LGPL-2.1+
*/

using System.Collections.Generic;
using MechJebLib.Utils;
using static System.FormattableString;

Expand All @@ -12,9 +13,9 @@ public class SimModuleDecouple : SimPartModule
{
private static readonly ObjectPool<SimModuleDecouple> _pool = new ObjectPool<SimModuleDecouple>(New, Clear);

public bool IsDecoupled;
public bool IsOmniDecoupler;
public bool Staged;
public bool IsDecoupled = false;
public bool IsOmniDecoupler = false;
public bool Staged = false;
public SimPart? AttachedPart;

public override void Dispose() => _pool.Release(this);
Expand All @@ -30,8 +31,15 @@ public static SimModuleDecouple Borrow(SimPart part)

private static void Clear(SimModuleDecouple m) => m.AttachedPart = null;

public override string ToString() =>
Invariant(
$"SimModuleDecouple: {CommonFields()} IsDecoupled={IsDecoupled} IsOmniDecoupler={IsOmniDecoupler} Staged={Staged} AttachedPart={AttachedPart?.Name ?? "null"}");
public override string ToString()
{
List<string> fields = CommonFieldList();
AddField(fields, "IsDecoupled", IsDecoupled, false);
AddField(fields, "IsOmniDecoupler", IsOmniDecoupler, false);
AddField(fields, "Staged", Staged, false);
if (AttachedPart != null)
fields.Add(Invariant($"AttachedPart={AttachedPart.Ident}"));
return ModuleLine("SimModuleDecouple", fields);
}
}
}
13 changes: 10 additions & 3 deletions MechJebLib/FuelFlowSimulation/PartModules/SimModuleDockingNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: LicenseRef-PD-hp OR Unlicense OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT OR LGPL-2.1+
*/

using System.Collections.Generic;
using MechJebLib.Utils;
using static System.FormattableString;

Expand All @@ -12,7 +13,7 @@ public class SimModuleDockingNode : SimPartModule
{
private static readonly ObjectPool<SimModuleDockingNode> _pool = new ObjectPool<SimModuleDockingNode>(New, Clear);

public bool Staged;
public bool Staged = false;
public SimPart? AttachedPart;

public override void Dispose() => _pool.Release(this);
Expand All @@ -28,7 +29,13 @@ public static SimModuleDockingNode Borrow(SimPart part)

private static void Clear(SimModuleDockingNode m) => m.AttachedPart = null;

public override string ToString() =>
Invariant($"SimModuleDockingNode: {CommonFields()} Staged={Staged} AttachedPart={AttachedPart?.Name ?? "null"}");
public override string ToString()
{
List<string> fields = CommonFieldList();
AddField(fields, "Staged", Staged, false);
if (AttachedPart != null)
fields.Add(Invariant($"AttachedPart={AttachedPart.Ident}"));
return ModuleLine("SimModuleDockingNode", fields);
}
}
}
25 changes: 16 additions & 9 deletions MechJebLib/FuelFlowSimulation/PartModules/SimModuleEngines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private void SetConsumptionRates()
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine(Invariant($"SimModuleEngines: {CommonFields()}"));
sb.AppendLine(ModuleLine("SimModuleEngines", CommonFieldList()));
sb.AppendLine(Invariant(
$" IsOperational={IsOperational} IsEnabled={IsEnabled} IsUnrestartableDeadEngine={IsUnrestartableDeadEngine} NoPropellants={NoPropellants}"));
sb.AppendLine(Invariant($" MaxFuelFlow={MaxFuelFlow} MinFuelFlow={MinFuelFlow} MaxThrust={MaxThrust} MinThrust={MinThrust} G={G}"));
Expand All @@ -404,14 +404,21 @@ public override string ToString()
$" AtmChangeFlow={AtmChangeFlow} UseAtmCurve={UseAtmCurve} UseAtmCurveIsp={UseAtmCurveIsp} UseThrottleIspCurve={UseThrottleIspCurve} UseThrustCurve={UseThrustCurve} UseVelCurve={UseVelCurve} UseVelCurveIsp={UseVelCurveIsp}"));
sb.AppendLine(Invariant(
$" ModuleResiduals={ModuleResiduals} ModuleSpoolupTime={ModuleSpoolupTime} AutoCutoff={AutoCutoff} IsModuleEnginesRf={IsModuleEnginesRf} Ullage={Ullage}"));
sb.AppendLine(Invariant($" AtmosphereCurve: {AtmosphereCurve}"));
sb.AppendLine(Invariant($" ThrustCurve: {ThrustCurve}"));
sb.AppendLine(Invariant($" ThrottleIspCurve: {ThrottleIspCurve}"));
sb.AppendLine(Invariant($" ThrottleIspCurveAtmStrength: {ThrottleIspCurveAtmStrength}"));
sb.AppendLine(Invariant($" VelCurve: {VelCurve}"));
sb.AppendLine(Invariant($" VelCurveIsp: {VelCurveIsp}"));
sb.AppendLine(Invariant($" ATMCurve: {ATMCurve}"));
sb.AppendLine(Invariant($" ATMCurveIsp: {ATMCurveIsp}"));
void AppendCurve(string name, H1 curve)
{
// empty curves are the default and very common, so omit them to keep the dump readable
if (!curve.IsEmpty)
sb.AppendLine(Invariant($" {name}: {curve}"));
}

AppendCurve("AtmosphereCurve", AtmosphereCurve);
AppendCurve("ThrustCurve", ThrustCurve);
AppendCurve("ThrottleIspCurve", ThrottleIspCurve);
AppendCurve("ThrottleIspCurveAtmStrength", ThrottleIspCurveAtmStrength);
AppendCurve("VelCurve", VelCurve);
AppendCurve("VelCurveIsp", VelCurveIsp);
AppendCurve("ATMCurve", ATMCurve);
AppendCurve("ATMCurveIsp", ATMCurveIsp);

sb.Append(" ThrustTransformMultipliers:");
foreach (double m in ThrustTransformMultipliers)
Expand Down
2 changes: 1 addition & 1 deletion MechJebLib/FuelFlowSimulation/PartModules/SimModuleRCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void SetConsumptionRates()
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine(Invariant($"SimModuleRCS: {CommonFields()}"));
sb.AppendLine(ModuleLine("SimModuleRCS", CommonFieldList()));
sb.AppendLine(Invariant(
$" G={G} Isp={Isp} Thrust={Thrust} RcsEnabled={RcsEnabled} ISPMult={ISPMult} ThrustPercentage={ThrustPercentage} MaxFuelFlow={MaxFuelFlow} MassFlowRate={MassFlowRate}"));
sb.AppendLine(Invariant($" AtmosphereCurve: {AtmosphereCurve}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: LicenseRef-PD-hp OR Unlicense OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT OR LGPL-2.1+
*/

using System.Collections.Generic;
using MechJebLib.Utils;
using static System.FormattableString;

Expand All @@ -12,7 +13,7 @@ public class SimProceduralFairingDecoupler : SimPartModule
{
private static readonly ObjectPool<SimProceduralFairingDecoupler> _pool = new ObjectPool<SimProceduralFairingDecoupler>(New, Clear);

public bool IsDecoupled;
public bool IsDecoupled = false;

public override void Dispose() => _pool.Release(this);

Expand All @@ -29,7 +30,11 @@ private static void Clear(SimProceduralFairingDecoupler m)
{
}

public override string ToString() =>
Invariant($"SimProceduralFairingDecoupler: {CommonFields()} IsDecoupled={IsDecoupled}");
public override string ToString()
{
List<string> fields = CommonFieldList();
AddField(fields, "IsDecoupled", IsDecoupled, false);
return ModuleLine("SimProceduralFairingDecoupler", fields);
}
}
}
134 changes: 89 additions & 45 deletions MechJebLib/FuelFlowSimulation/SimPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,32 @@ public class SimPart
private readonly Dictionary<int, double> _resourceDrains = new Dictionary<int, double>();
private readonly Dictionary<int, double> _rcsDrains = new Dictionary<int, double>();

public int DecoupledInStage;
public bool StagingOn;
public int InverseStage;
public int DecoupledInStage = -1;
public bool StagingOn = true;
public int InverseStage = -1;
public SimVessel Vessel;
public string Name;
public uint PersistentId;

public bool ActivatesEvenIfDisconnected;
public bool IsThrottleLocked;
public int ResourcePriority;
public double ResourceRequestRemainingThreshold;
public bool IsEnabled;
public string Ident => Invariant($"{Name}-{PersistentId}");

public bool ActivatesEvenIfDisconnected = true;
public bool IsThrottleLocked = false;
public int ResourcePriority = 0;
public double ResourceRequestRemainingThreshold = 1E-12;
public bool IsEnabled = false;

public double Mass;
public double DryMass;
public double CrewMass;
public double ModulesStagedMass;
public double ModulesUnstagedMass;
public double DisabledResourcesMass;
public double EngineResiduals;

public bool IsRoot;
public bool IsLaunchClamp;
public bool IsEngine;
public double CrewMass = 0;
public double ModulesStagedMass = 0;
public double ModulesUnstagedMass = 0;
public double DisabledResourcesMass = 0;
public double EngineResiduals = 0;

public bool IsRoot = false;
public bool IsLaunchClamp = false;
public bool IsEngine = false;
public bool IsSepratron => IsEngine && IsThrottleLocked && ActivatesEvenIfDisconnected && InverseStage == DecoupledInStage;

private SimPart()
Expand Down Expand Up @@ -224,40 +227,81 @@ public double RCSMaxTime()
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine(Invariant($"SimPart '{Name}':"));
sb.AppendLine(Invariant($" InverseStage={InverseStage} DecoupledInStage={DecoupledInStage} StagingOn={StagingOn}"));
sb.AppendLine(Invariant(
$" IsRoot={IsRoot} IsEngine={IsEngine} IsLaunchClamp={IsLaunchClamp} IsThrottleLocked={IsThrottleLocked} ActivatesEvenIfDisconnected={ActivatesEvenIfDisconnected} IsEnabled={IsEnabled}"));
sb.AppendLine(Invariant($" ResourcePriority={ResourcePriority} ResourceRequestRemainingThreshold={ResourceRequestRemainingThreshold}"));
sb.AppendLine(Invariant(
$" Mass={Mass} DryMass={DryMass} CrewMass={CrewMass} ModulesStagedMass={ModulesStagedMass} ModulesUnstagedMass={ModulesUnstagedMass} DisabledResourcesMass={DisabledResourcesMass} EngineResiduals={EngineResiduals}"));

sb.Append(" Links:");
foreach (SimPart p in Links)
sb.Append(Invariant($" {p.Name}"));
sb.AppendLine();
sb.AppendLine(Invariant($"SimPart '{Ident}':"));

sb.Append(" SymmetryCounterParts:");
foreach (SimPart p in SymmetryCounterParts)
sb.Append(Invariant($" {p.Name}"));
sb.AppendLine();
// only emit fields that differ from their declared default, so the dump focuses on what a fixture needs to set
var fields = new List<string>();

sb.Append(" CrossFeedPartSet:");
foreach (SimPart p in CrossFeedPartSet)
sb.Append(Invariant($" {p.Name}"));
sb.AppendLine();
void B(string name, bool val, bool def)
{
if (val != def) fields.Add(Invariant($"{name}={val}"));
}

sb.Append(" Resources:");
foreach (SimResource r in Resources.Values)
sb.Append(Invariant(
$" [id={r.Id} amount={r.Amount} maxAmount={r.MaxAmount} density={r.Density} free={r.Free} residual={r.Residual}]"));
sb.AppendLine();
void I(string name, int val, int def)
{
if (val != def) fields.Add(Invariant($"{name}={val}"));
}

sb.AppendLine(Invariant($" Modules ({Modules.Count}):"));
foreach (SimPartModule m in Modules)
sb.AppendLine(m.ToString().Indent(4));
void D(string name, double val, double def)
{
// ReSharper disable once CompareOfFloatsByEqualityOperator
if (val != def) fields.Add(Invariant($"{name}={val}"));
}

I("InverseStage", InverseStage, -1);
I("DecoupledInStage", DecoupledInStage, -1);
B("StagingOn", StagingOn, true);
B("IsRoot", IsRoot, false);
B("IsEngine", IsEngine, false);
B("IsLaunchClamp", IsLaunchClamp, false);
B("IsThrottleLocked", IsThrottleLocked, false);
B("ActivatesEvenIfDisconnected", ActivatesEvenIfDisconnected, true);
B("IsEnabled", IsEnabled, false);
I("ResourcePriority", ResourcePriority, 0);
D("ResourceRequestRemainingThreshold", ResourceRequestRemainingThreshold, 1E-12);
D("Mass", Mass, 0);
D("DryMass", DryMass, 0);
D("CrewMass", CrewMass, 0);
D("ModulesStagedMass", ModulesStagedMass, 0);
D("ModulesUnstagedMass", ModulesUnstagedMass, 0);
D("DisabledResourcesMass", DisabledResourcesMass, 0);
D("EngineResiduals", EngineResiduals, 0);

if (fields.Count > 0)
sb.AppendLine(" " + string.Join(" ", fields));

AppendParts(sb, "Links", Links);
AppendParts(sb, "SymmetryCounterParts", SymmetryCounterParts);
AppendParts(sb, "CrossFeedPartSet", CrossFeedPartSet);

if (Resources.Count > 0)
{
sb.Append(" Resources:");
foreach (SimResource r in Resources.Values)
sb.Append(Invariant(
$" [id={r.Id} amount={r.Amount} maxAmount={r.MaxAmount} density={r.Density} free={r.Free} residual={r.Residual}]"));
sb.AppendLine();
}

if (Modules.Count > 0)
{
sb.AppendLine(Invariant($" Modules ({Modules.Count}):"));
foreach (SimPartModule m in Modules)
sb.AppendLine(m.ToString().Indent(4));
}

return sb.ToString().TrimEnd();
}

private static void AppendParts(StringBuilder sb, string name, List<SimPart> parts)
{
if (parts.Count == 0)
return;

sb.Append(Invariant($" {name}:"));
foreach (SimPart p in parts)
sb.Append(Invariant($" {p.Ident}"));
sb.AppendLine();
}
}
}
Loading
Loading