Skip to content

Commit

Permalink
Don't run RCS in Node Executor when IDLE
Browse files Browse the repository at this point in the history
We can be enabled and hammering on DoRCS every tick but not be doing
anything.

Added more initializion paranoia around resetting back to Idle as well.

Also bonus fixed that it doesn't rely on VesselState any more for doing
its own reflection poking around.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Mar 28, 2024
1 parent 07ff528 commit 33e8258
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions MechJeb2/MechJebModuleNodeExecutor.cs
Expand Up @@ -9,11 +9,13 @@ namespace MuMech
{
public class MechJebModuleNodeExecutor : ComputerModule
{
private static readonly bool realfuelsLoaded;
private static readonly bool _isLoadedRealFuels;
private static readonly bool _isLoadedPrincipia;

static MechJebModuleNodeExecutor()
{
realfuelsLoaded = ReflectionUtils.IsAssemblyLoaded("RealFuels");
_isLoadedRealFuels = ReflectionUtils.IsAssemblyLoaded("RealFuels");
_isLoadedPrincipia = ReflectionUtils.IsAssemblyLoaded("principia.ksp_plugin_adapter");
}

// whether to auto-warp to nodes
Expand All @@ -35,7 +37,7 @@ public string NextNodeBurnTime()
return "-";

double dV;
if (VesselState.isLoadedPrincipia && _dvLeft > 0)
if (_isLoadedPrincipia && _dvLeft > 0)
{
dV = _dvLeft;
}
Expand Down Expand Up @@ -103,13 +105,15 @@ protected override void OnModuleEnabled()
{
Core.Attitude.Users.Add(this);
Core.Thrust.Users.Add(this);
State = States.IDLE;
}

protected override void OnModuleDisabled()
{
Core.Attitude.attitudeDeactivate();
Core.Thrust.ThrustOff();
Core.Thrust.Users.Remove(this);
State = States.IDLE;
_dvLeft = 0;
}

Expand All @@ -120,18 +124,20 @@ public enum States { WARPALIGN, LEAD, BURN, IDLE }
private Mode _mode = Mode.ONE_NODE;
public States State = States.IDLE;

private double _dvLeft; // for Principia
private Vector3d _direction; // de-rotated world vector
private Vector3d _worldDirection => Planetarium.fetch.rotation * _direction;
private double _ignitionUT;
private static bool _isLoadedPrincipia => VesselState.isLoadedPrincipia;
private bool _hasNodes => Vessel.patchedConicSolver.maneuverNodes.Count > 0;
private double _ullageUntil;
private double _dvLeft; // for Principia
private Vector3d _direction; // de-rotated world vector
private Vector3d _worldDirection => Planetarium.fetch.rotation * _direction;
private double _ignitionUT;
private bool _hasNodes => Vessel.patchedConicSolver.maneuverNodes.Count > 0;
private double _ullageUntil;

public override void Drive(FlightCtrlState s) => DoRCS(s);

private void DoRCS(FlightCtrlState s)
{
if (State == States.IDLE)
return;

// seconds to continue to apply RCS after ullage has settled to VeryStable
const double MIN_RCS_TIME = 0.25;

Expand All @@ -145,7 +151,7 @@ private void DoRCS(FlightCtrlState s)
if (State != States.LEAD || RCSOnly)
return;

if (!Core.Thrust.AutoRCSUllaging || !realfuelsLoaded)
if (!Core.Thrust.AutoRCSUllaging || !_isLoadedRealFuels)
return;

// always apply MIN_RCS_TIME of ullage right before the ignition time
Expand Down

0 comments on commit 33e8258

Please sign in to comment.