Skip to content

Commit

Permalink
Merge remote-tracking branch 'MagicSmokeIndustries/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiwKerman committed May 6, 2016
2 parents 5f256c7 + 7cbbe7f commit 9aab687
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 34 deletions.
46 changes: 46 additions & 0 deletions InfernalRobotics/InfernalRobotics/Command/ServoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,30 @@ private void Awake()
Logger.Log("[ServoController] awake finished successfully, AddonName = " + this.AddonName, Logger.Level.Debug);
}

/// <summary>
/// Sets the wheel auto-struting for the Vessel v.
/// In flight mode we need to set to false before moving
/// the joint and to true aferwards
/// </summary>
public static void SetWheelAutoStruts(bool value, Vessel v)
{
if (!HighLogic.LoadedSceneIsFlight)
return;

var activeVesselWheels = v.FindPartModulesImplementing<ModuleWheelBase>();
foreach(var mwb in activeVesselWheels)
{
mwb.autoStrut = value;
if (value)
{
mwb.CycleWheelStrut();
}
else
mwb.ReleaseWheelStrut();
}
}


private void FixedUpdate()
{
//because OnVesselDestroy and OnVesselGoOnRails seem to only work for active vessel I had to build this stupid workaround
Expand All @@ -345,6 +369,28 @@ private void FixedUpdate()
RebuildServoGroupsFlight ();
loadedVesselCounter = FlightGlobals.Vessels.Count(v => v.loaded);
}

//check if all servos stopped running and enable the struts, otherwise disable wheel autostruts
var anyActive = new Dictionary<Vessel, bool>();

foreach(var g in ServoGroups)
{
if (!anyActive.ContainsKey(g.Vessel))
anyActive.Add(g.Vessel, false);

foreach(var s in g.Servos)
{
if (s.RawServo.Interpolator.Active)
{
anyActive[g.Vessel] = true;
break;
}
}
}
foreach(var pair in anyActive)
{
SetWheelAutoStruts(!pair.Value, pair.Key);
}
}
}

Expand Down
45 changes: 11 additions & 34 deletions InfernalRobotics/InfernalRobotics/Module/ModuleIRServo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,26 +1051,6 @@ protected virtual void UpdateJointSettings(float torque, float springPower, floa
if(springPower > 0f || dampingPower > 0f)
EnforceJointLimits ();
}
/// <summary>
/// Sets the wheel auto-struting for the ActiveVessel.
/// In flight mode we need to set to false before moving
/// the joint and to true aferwards
/// </summary>
private void SetWheelAutoStruts(bool value)
{
if (!HighLogic.LoadedSceneIsFlight)
return;

var activeVesselWheels = FlightGlobals.ActiveVessel.FindPartModulesImplementing<ModuleWheelBase>();
foreach(var mwb in activeVesselWheels)
{
mwb.autoStrut = value;
if (value)
mwb.CycleWheelStrut();
else
mwb.ReleaseWheelStrut();
}
}

/// <summary>
/// Called every FixedUpdate, reads next target position and
Expand Down Expand Up @@ -1098,8 +1078,6 @@ protected virtual void UpdatePosition()
part.attachJoint.Joint.angularZMotion = ConfigurableJointMotion.Free;
}

SetWheelAutoStruts(false);

if (rotateJoint)
{
if (rotation != targetPos) //this comparison is intentional
Expand All @@ -1122,8 +1100,6 @@ protected virtual void UpdatePosition()
RotateModelTransform.localRotation = curRot;
}
}
else
SetWheelAutoStruts(false);
}
else
{
Expand All @@ -1136,8 +1112,6 @@ protected virtual void UpdatePosition()
joint.targetPosition = -translateAxis*(translation - translationDelta);
}
}
else
SetWheelAutoStruts(false);
}

if (freeMoving)
Expand Down Expand Up @@ -1414,7 +1388,17 @@ public void FixedUpdate()

if (UseElectricCharge && GetAvailableElectricCharge() <= groupECRequired)
Translator.Stop();


if (Interpolator.Active)
{
ServoController.SetWheelAutoStruts(false, FlightGlobals.ActiveVessel);
motorSound.Play();
}
else
{
motorSound.Stop();
}

UpdatePosition();

/*float currentTorque = (isMotionLock || (!UseTorque)) ? float.PositiveInfinity : (torqueTweak == 0f ? float.PositiveInfinity : torqueTweak);
Expand All @@ -1425,13 +1409,6 @@ public void FixedUpdate()
//Springy joints are broken, need to redo it completely
UpdateJointSettings(currentTorque, currentSpring, currentDamping);*/

if (Interpolator.Active)
{
motorSound.Play();
}
else
motorSound.Stop();

ConsumeElectricCharge();
}

Expand Down

0 comments on commit 9aab687

Please sign in to comment.