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
3 changes: 3 additions & 0 deletions MechJebLib/FuelFlowSimulation/PartModules/SimLaunchClamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

using MechJebLib.Utils;
using static System.FormattableString;

namespace MechJebLib.FuelFlowSimulation.PartModules
{
Expand All @@ -25,5 +26,7 @@ public static SimLaunchClamp Borrow(SimPart part)
private static void Clear(SimLaunchClamp m)
{
}

public override string ToString() => Invariant($"SimLaunchClamp: {CommonFields()}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

using MechJebLib.Utils;
using static System.FormattableString;

namespace MechJebLib.FuelFlowSimulation.PartModules
{
Expand All @@ -28,5 +29,8 @@ public static SimModuleAvionics Borrow(SimPart part)
private static void Clear(SimModuleAvionics m)
{
}

public override string ToString() =>
Invariant($"SimModuleAvionics: {CommonFields()} ControllableMass={ControllableMass}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

using MechJebLib.Utils;
using static System.FormattableString;

namespace MechJebLib.FuelFlowSimulation.PartModules
{
Expand All @@ -28,5 +29,9 @@ public static SimModuleDecouple Borrow(SimPart part)
private static SimModuleDecouple New() => new SimModuleDecouple();

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"}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

using MechJebLib.Utils;
using static System.FormattableString;

namespace MechJebLib.FuelFlowSimulation.PartModules
{
Expand All @@ -26,5 +27,8 @@ public static SimModuleDockingNode Borrow(SimPart part)
private static SimModuleDockingNode New() => new SimModuleDockingNode();

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

public override string ToString() =>
Invariant($"SimModuleDockingNode: {CommonFields()} Staged={Staged} AttachedPart={AttachedPart?.Name ?? "null"}");
}
}
42 changes: 42 additions & 0 deletions MechJebLib/FuelFlowSimulation/PartModules/SimModuleEngines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using MechJebLib.Primitives;
using MechJebLib.Utils;
using static MechJebLib.Utils.Statics;
using static System.FormattableString;

namespace MechJebLib.FuelFlowSimulation.PartModules
{
Expand Down Expand Up @@ -387,5 +389,45 @@ private void SetConsumptionRates()
ResourceConsumptions.Add(p.id, propVolumeRate);
}
}

public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine(Invariant($"SimModuleEngines: {CommonFields()}"));
sb.AppendLine(Invariant(
$" IsOperational={IsOperational} IsEnabled={IsEnabled} IsUnrestartableDeadEngine={IsUnrestartableDeadEngine} NoPropellants={NoPropellants}"));
sb.AppendLine(Invariant($" MaxFuelFlow={MaxFuelFlow} MinFuelFlow={MinFuelFlow} MaxThrust={MaxThrust} MinThrust={MinThrust} G={G}"));
sb.AppendLine(Invariant(
$" ThrottleLocked={ThrottleLocked} ThrottleLimiter={ThrottleLimiter} MultIsp={MultIsp} MultFlow={MultFlow} FlowMultiplier={FlowMultiplier}"));
sb.AppendLine(Invariant($" Clamp={Clamp} FlowMultCap={FlowMultCap} FlowMultCapSharpness={FlowMultCapSharpness}"));
sb.AppendLine(Invariant(
$" 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}"));

sb.Append(" ThrustTransformMultipliers:");
foreach (double m in ThrustTransformMultipliers)
sb.Append(Invariant($" {m}"));
sb.AppendLine();

sb.Append(" ThrustDirectionVectors:");
foreach (V3 v in ThrustDirectionVectors)
sb.Append(Invariant($" {v}"));
sb.AppendLine();

sb.Append(" Propellants:");
foreach (SimPropellant p in Propellants)
sb.Append(Invariant(
$" [id={p.id} ignoreForIsp={p.ignoreForIsp} ratio={p.ratio} flowMode={p.FlowMode} density={p.density}]"));
return sb.ToString();
}
}
}
16 changes: 16 additions & 0 deletions MechJebLib/FuelFlowSimulation/PartModules/SimModuleRCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using MechJebLib.Primitives;
using MechJebLib.Utils;
using static System.FormattableString;

namespace MechJebLib.FuelFlowSimulation.PartModules
{
Expand Down Expand Up @@ -182,5 +184,19 @@ private void SetConsumptionRates()
ResourceConsumptions.Add(p.id, propVolumeRate);
}
}

public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine(Invariant($"SimModuleRCS: {CommonFields()}"));
sb.AppendLine(Invariant(
$" G={G} Isp={Isp} Thrust={Thrust} RcsEnabled={RcsEnabled} ISPMult={ISPMult} ThrustPercentage={ThrustPercentage} MaxFuelFlow={MaxFuelFlow} MassFlowRate={MassFlowRate}"));
sb.AppendLine(Invariant($" AtmosphereCurve: {AtmosphereCurve}"));
sb.Append(" Propellants:");
foreach (SimPropellant p in Propellants)
sb.Append(Invariant(
$" [id={p.id} ignoreForIsp={p.ignoreForIsp} ratio={p.ratio} flowMode={p.FlowMode} density={p.density}]"));
return sb.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

using MechJebLib.Utils;
using static System.FormattableString;

namespace MechJebLib.FuelFlowSimulation.PartModules
{
Expand All @@ -27,5 +28,8 @@ public static SimProceduralFairingDecoupler Borrow(SimPart part)
private static void Clear(SimProceduralFairingDecoupler m)
{
}

public override string ToString() =>
Invariant($"SimProceduralFairingDecoupler: {CommonFields()} IsDecoupled={IsDecoupled}");
}
}
44 changes: 31 additions & 13 deletions MechJebLib/FuelFlowSimulation/SimPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Text;
using MechJebLib.Utils;
using static System.Math;
using static System.FormattableString;
using static MechJebLib.Utils.Statics;

namespace MechJebLib.FuelFlowSimulation
{
Expand Down Expand Up @@ -222,24 +224,40 @@ public double RCSMaxTime()
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine($"{Name}: ");
sb.Append(" Neighbors:");
for (int i = 0; i < Links.Count; i++)
sb.Append($" {Links[i].Name}");
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.Append(" CrossFeedPartSet:");
//for (int i = 0; i < CrossFeedPartSet.Count; i++)
// sb.Append($" {CrossFeedPartSet[i].Name}");
//sb.AppendLine();
sb.Append(" Resources:");
foreach (SimResource resource in Resources.Values)
sb.Append($" {resource.Id}={resource.Amount}*{resource.Density}");

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

sb.Append(" CrossFeedPartSet:");
foreach (SimPart p in CrossFeedPartSet)
sb.Append(Invariant($" {p.Name}"));
sb.AppendLine();
sb.Append($" DecoupledInStage: {DecoupledInStage} InverseStage: {InverseStage}");

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();

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

return sb.ToString();
return sb.ToString().TrimEnd();
}
}
}
5 changes: 5 additions & 0 deletions MechJebLib/FuelFlowSimulation/SimPartModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

using System;
using static System.FormattableString;

namespace MechJebLib.FuelFlowSimulation
{
Expand All @@ -15,5 +16,9 @@ public abstract class SimPartModule : IDisposable
public bool StagingEnabled;

public abstract void Dispose();

// The fields common to every SimPartModule, for the concrete ToString() debug dumps to include.
protected string CommonFields() =>
Invariant($"IsEnabled={IsEnabled} ModuleIsEnabled={ModuleIsEnabled} StagingEnabled={StagingEnabled}");
}
}
21 changes: 11 additions & 10 deletions MechJebLib/FuelFlowSimulation/SimVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using MechJebLib.FuelFlowSimulation.PartModules;
using MechJebLib.Primitives;
using MechJebLib.Utils;
using static System.FormattableString;
using static MechJebLib.Utils.Statics;

namespace MechJebLib.FuelFlowSimulation
{
Expand Down Expand Up @@ -292,16 +294,15 @@ public void ResetRcsStatus()
public override string ToString()
{
var sb = new StringBuilder();

for (int i = 0; i <= CurrentStage; i++)
{
sb.AppendLine($"stage {i}:");
foreach (SimPart part in PartsRemainingInStage[i])
sb.Append(part);
sb.AppendLine("------------------------");
}

return sb.ToString();
sb.AppendLine("SimVessel:");
sb.AppendLine(Invariant($" CurrentStage={CurrentStage} HasLaunchClamp={HasLaunchClamp} MainThrottle={MainThrottle}"));
sb.AppendLine(Invariant($" ATMPressure={ATMPressure} ATMDensity={ATMDensity} MachNumber={MachNumber}"));
sb.AppendLine(Invariant($" T={T} R={R} V={V} U={U}"));
sb.AppendLine(Invariant($" Parts ({Parts.Count}):"));
foreach (SimPart part in Parts)
sb.AppendLine(part.ToString().Indent(4));

return sb.ToString().TrimEnd();
}
}
}
20 changes: 20 additions & 0 deletions MechJebLib/Primitives/H1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* 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.Text;
using MechJebLib.Utils;
using static System.FormattableString;

namespace MechJebLib.Primitives
{
Expand Down Expand Up @@ -46,5 +48,23 @@ protected override double Interpolant(double x1, double y1, double yp1, double x
Functions.Interpolants.CubicHermiteInterpolant(x1, y1, yp1, x2, y2, yp2, x);

private static void Clear(H1 h) => h.Clear();

// Debug dump of the raw keyframes, in a form that mirrors HBase.Add(time, value, inTangent, outTangent) so the
// curve can be transcribed into a test fixture. HBase/H3/Hn are effectively deprecated so this lives only on H1.
public override string ToString()
{
var sb = new StringBuilder();
sb.Append(Invariant($"H1(unityCompat={UnityCompat})["));
for (int i = 0; i < _list.Count; i++)
{
HFrame<double> f = _list.Values[i];
if (i > 0)
sb.Append(", ");
sb.Append(Invariant($"(t={f.Time}, v={f.Value}, in={f.InTangent}, out={f.OutTangent})"));
}

sb.Append("]");
return sb.ToString();
}
}
}
10 changes: 10 additions & 0 deletions MechJebLib/Utils/Statics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,16 @@ public static string ToSI(this double d, int sigFigs = 4, int maxPrecision = int
public static string ToSI(this float f, int sigFigs = 4, int maxPrecision = int.MaxValue) =>
((double)f).ToSI(sigFigs, maxPrecision);

/// <summary>
/// Prefixes every line of a (possibly multi-line) string with <paramref name="n" /> spaces. Used to compose the
/// nested ToString() debug dumps of SimVessel/SimPart/SimPartModule so children indent underneath their parent.
/// </summary>
public static string Indent(this string s, int n)
{
string pad = new string(' ', n);
return pad + s.Replace("\n", "\n" + pad);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Print(string message) => Logger.Print(message);

Expand Down
2 changes: 1 addition & 1 deletion MechJebLibBindings/H1Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace MechJebLibBindings
{
public static class H1Extensions
{
public static void LoadH1(this H1 h, FloatCurve f)
public static void LoadH1(this H1 h, FloatCurve? f)
{
h.Clear();

Expand Down
Loading