public override void Update() { //init engine wrappers, update thrust and torque information Thrust = Vector3.zero; DefThrust = Vector3.zero; DefManualThrust = Vector3.zero; ManualThrustLimits = Vector6.zero; ManualThrustSpeed = Vector6.zero; MassFlow = 0f; ManualMassFlow = 0f; for (int i = 0; i < NumActive; i++) { var e = Active[i]; e.InitState(); e.InitTorque(VSL, EngineOptimizer.C.TorqueRatioFactor); e.UpdateCurrentTorque(1); //do not include maneuver engines' thrust into the total to break the feedback loop with HSC if (e.Role != TCARole.MANEUVER) { Thrust += e.wThrustDir * e.finalThrust; DefThrust += e.defThrustDir * e.finalThrust; } if (e.Role == TCARole.MANUAL) { DefManualThrust += e.defThrustDir * e.finalThrust; ManualMassFlow += e.RealFuelFlow; var man_thrust = e.defThrustDirL * e.nominalFullThrust; ManualThrustLimits.Add(man_thrust); if (e.useEngineResponseTime) { ManualThrustSpeed.Add(man_thrust * Mathf.Max(e.engineAccelerationSpeed, e.engineDecelerationSpeed)); } } MassFlow += e.RealFuelFlow; } ManualThrustSpeed.Scale(ManualThrustLimits.Inverse()); update_MaxThrust(); update_RCS(); //update engines' current torque var throttle = VSL.PreUpdateControls.mainThrottle; var vsc_throttle = (VSL.OnPlanet && CFG.VSCIsActive)? throttle * VSL.OnPlanetParams.GeeVSF : throttle; for (int i = 0; i < NumActive; i++) { var e = Active[i]; e.UpdateCurrentTorque(e.isVSC? vsc_throttle : throttle); e.ApplyPreset(); } }
public override void Update() { //init engine wrappers, update thrust and torque information Thrust = Vector3.zero; DefThrust = Vector3.zero; DefManualThrust = Vector3.zero; ManualThrustLimits = Vector6.zero; MassFlow = 0f; ManualMassFlow = 0f; for (int i = 0; i < NumActive; i++) { var e = Active[i]; e.InitState(); e.InitTorque(VSL, GLB.ENG.TorqueRatioFactor); e.UpdateCurrentTorque(1); //do not include maneuver engines' thrust into the total to break the feedback loop with HSC if (e.Role != TCARole.MANEUVER) { Thrust += e.wThrustDir * e.finalThrust; DefThrust += e.defThrustDir * e.finalThrust; } if (e.Role == TCARole.MANUAL) { DefManualThrust += e.defThrustDir * e.finalThrust; ManualMassFlow += e.RealFuelFlow; ManualThrustLimits.Add(e.thrustDirection * e.nominalCurrentThrust(1)); } MassFlow += e.RealFuelFlow; } update_MaxThrust(); update_RCS(); //update engines' current torque var throttle = VSL.vessel.ctrlState.mainThrottle; var vsc_throttle = (VSL.OnPlanet && CFG.VSCIsActive)? throttle * VSL.OnPlanetParams.GeeVSF : throttle; for (int i = 0; i < NumActive; i++) { var e = Active[i]; e.UpdateCurrentTorque(e.isVSC? vsc_throttle : throttle); e.ApplyPreset(); } }
public override void Update() { //init engine wrappers, thrust and torque information Thrust = Vector3.zero; MaxThrust = Vector3.zero; ManualThrust = Vector3.zero; ManualThrustLimits = Vector6.zero; MassFlow = 0f; MaxMassFlow = 0f; ManualMassFlow = 0f; ThrustDecelerationTime = 0f; SlowTorque = false; TorqueResponseTime = 0f; var total_torque = 0f; for (int i = 0; i < NumActive; i++) { var e = Active[i]; e.InitState(); e.InitTorque(VSL, GLB.ENG.TorqueRatioFactor); //do not include maneuver engines' thrust into the total to break the feedback loop with HSC if (e.Role != TCARole.MANEUVER) { Thrust += e.wThrustDir * e.finalThrust; } if (e.Role == TCARole.MANUAL) { ManualThrust += e.wThrustDir * e.finalThrust; ManualMassFlow += e.RealFuelFlow; ManualThrustLimits.Add(e.thrustDirection * e.nominalCurrentThrust(1)); } if (e.isVSC) { MaxThrust += e.wThrustDir * e.nominalCurrentThrust(1); MaxMassFlow += e.MaxFuelFlow; if (e.useEngineResponseTime && e.finalThrust > 0) { var decelT = 1f / e.engineDecelerationSpeed; if (decelT > ThrustDecelerationTime) { ThrustDecelerationTime = decelT; } } } if (e.useEngineResponseTime && (e.Role == TCARole.MAIN || e.Role == TCARole.MANEUVER)) { var torque = e.Torque(1).magnitude; total_torque += torque; TorqueResponseTime += torque * Mathf.Max(e.engineAccelerationSpeed, e.engineDecelerationSpeed); } MassFlow += e.RealFuelFlow; } if (MassFlow > MaxMassFlow) { MaxMassFlow = MassFlow; } if (TorqueResponseTime > 0) { TorqueResponseTime = total_torque / TorqueResponseTime; } SlowTorque = TorqueResponseTime > 0; MaxThrustM = MaxThrust.magnitude; MaxVe = MaxThrustM / MaxMassFlow; MaxAccel = MaxThrustM / VSL.Physics.M; //init RCS wrappers and calculate MaxThrust taking torque imbalance into account MaxThrustRCS = new Vector6(); var RCSThrusImbalance = new Vector3[6]; for (int i = 0; i < NumActiveRCS; i++) { var t = ActiveRCS[i]; t.InitState(); for (int j = 0, tCount = t.rcs.thrusterTransforms.Count; j < tCount; j++) { var T = t.rcs.thrusterTransforms[j]; var thrust = refT.InverseTransformDirection((t.rcs.useZaxis ? T.forward : T.up) * t.maxThrust); MaxThrustRCS.Add(thrust); var pos = refT.InverseTransformDirection(T.position - VSL.Physics.wCoM); var athrust = Vector3.zero; for (int k = 0; k < 3; k++) { athrust[k] = thrust[k]; var p = pos; p[k] = 0; RCSThrusImbalance[thrust[k] > 0 ? k : k + 3] += Vector3.Cross(p, athrust); athrust[k] = 0; } } if (NoActiveRCS) { continue; } t.InitTorque(VSL, GLB.RCS.TorqueRatioFactor); t.currentTorque = t.Torque(1); t.currentTorque_m = t.currentTorque.magnitude; } if (!MaxThrustRCS.IsZero()) { MaxThrustRCS.Scale(new Vector6( 1 / Utils.ClampL(RCSThrusImbalance[0].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[1].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[2].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[3].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[4].sqrMagnitude, 1), 1 / Utils.ClampL(RCSThrusImbalance[5].sqrMagnitude, 1))); } }