Skip to content

Commit

Permalink
Merge pull request #136 from ZiwKerman/develop
Browse files Browse the repository at this point in the history
Fix for TimeWarp bug
  • Loading branch information
ZiwKerman authored Nov 24, 2016
2 parents 67674e1 + 49506f2 commit 1dd1ab1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
4 changes: 2 additions & 2 deletions InfernalRobotics/InfernalRobotics/Command/ServoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,13 @@ private void OnVesselPartCountModified(Vessel v)

private void OnVesselLoaded (Vessel v)
{
Logger.Log("[ServoController] OnVesselLoaded, v=" + v.GetName(), Logger.Level.SuperVerbose);
Logger.Log("[ServoController] OnVesselLoaded, v=" + v.GetName(), Logger.Level.Debug);
RebuildServoGroupsFlight ();
}

private void OnVesselUnloaded (Vessel v)
{
Logger.Log("[ServoController] OnVesselUnloaded, v=" + v.GetName(), Logger.Level.SuperVerbose);
Logger.Log("[ServoController] OnVesselUnloaded, v=" + v.GetName(), Logger.Level.Debug);
RebuildServoGroupsFlight ();
}

Expand Down
83 changes: 68 additions & 15 deletions InfernalRobotics/InfernalRobotics/Module/ModuleIRServo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public class ModuleIRServo : PartModule, IRescalable, IJointLockState
[KSPField(isPersistant = false)]
public float jointSpring = 0;
[KSPField(isPersistant = false)]
public float jointDamping = 0;
public float jointDamping = 0;

bool isOnRails = false;

[KSPField(isPersistant = true)] public bool rotateLimits = false;
[KSPField(isPersistant = true)] public float rotateMax = 360;
Expand Down Expand Up @@ -131,6 +133,7 @@ public class ModuleIRServo : PartModule, IRescalable, IJointLockState
protected const string ELECTRIC_CHARGE_RESOURCE_NAME = "ElectricCharge";

protected ConfigurableJoint joint;
protected ConfigurableJoint savedJoint;
protected Rigidbody jointRigidBody;

protected SoundSource motorSound;
Expand Down Expand Up @@ -427,9 +430,62 @@ public override void OnAwake()

Translator.Init(isMotionLock, new Servo(this), Interpolator);

GameEvents.onVesselGoOnRails.Add (OnVesselGoOnRails);
GameEvents.onVesselGoOffRails.Add (OnVesselGoOffRails);

Logger.Log(string.Format("[OnAwake] End, rotateLimits={0}, minTweak={1}, maxTweak={2}, rotateJoint={0}", rotateLimits, minTweak, maxTweak), Logger.Level.Debug);
}


public void OnVesselGoOnRails (Vessel v)
{
if (v != vessel)
return;

Logger.Log ("[OnVesselGoOnRails] Reverting Joint", Logger.Level.Debug);

part.attachJoint.Joint.angularXDrive = savedJoint.angularXDrive;
part.attachJoint.Joint.angularYZDrive = savedJoint.angularYZDrive;
part.attachJoint.Joint.xDrive = savedJoint.xDrive;
part.attachJoint.Joint.yDrive = savedJoint.yDrive;
part.attachJoint.Joint.zDrive = savedJoint.zDrive;
part.attachJoint.Joint.enableCollision = false;

if (joint)
{
// lock all movement by default
joint.xMotion = ConfigurableJointMotion.Locked;
joint.yMotion = ConfigurableJointMotion.Locked;
joint.zMotion = ConfigurableJointMotion.Locked;
joint.angularXMotion = ConfigurableJointMotion.Locked;
joint.angularYMotion = ConfigurableJointMotion.Locked;
joint.angularZMotion = ConfigurableJointMotion.Locked;
}

rotationDelta = GetRealRotation();
translationDelta = GetRealTranslation();

isOnRails = true;
}


public void OnVesselGoOffRails (Vessel v)
{
if (v != vessel)
return;

JointSetupDone = false;
Logger.Log ("[OnVesselGoOffRails] Resetting Joint", Logger.Level.Debug);

if (joint)
{
DestroyImmediate (joint);
}

SetupJoints ();

isOnRails = false;
}

public override void OnSave(ConfigNode node)
{
Logger.Log("[OnSave] Start", Logger.Level.Debug);
Expand Down Expand Up @@ -563,15 +619,17 @@ protected virtual void AttachToParent()
{
Transform fix = FixedMeshTransform;
//Transform fix = obj;


if (rotateJoint)
{
fix.RotateAround(transform.TransformPoint(rotatePivot), transform.TransformDirection(rotateAxis),
fix.RotateAround(part.transform.TransformPoint(rotatePivot), part.transform.TransformDirection(rotateAxis),
//(invertSymmetry ? ((part.symmetryCounterparts.Count != 1) ? -1 : 1) : -1) *
-rotation);
}
else if (translateJoint)
{
fix.Translate(transform.TransformDirection(translateAxis.normalized)*translation, Space.World);
fix.Translate(part.transform.TransformDirection(translateAxis.normalized)*translation, Space.World);
}
fix.parent = part.parent.transform;
}
Expand Down Expand Up @@ -746,19 +804,11 @@ public virtual bool SetupJoints()
return false;
}

if (part.attachJoint.Joint.xDrive.maximumForce > 0.0001)
{
JointSetupDone = false;
Logger.Log ("Resetting Joint", Logger.Level.Debug);
if(joint)
{
DestroyImmediate (joint);
}
}

if (JointSetupDone)
return false;


savedJoint = part.attachJoint.Joint;

// Catch reversed joint
// Maybe there is a best way to do it?
if (transform.position != part.attachJoint.Joint.connectedBody.transform.position)
Expand Down Expand Up @@ -1387,6 +1437,9 @@ public void FixedUpdate()
return;
}

if (isOnRails)
return;

if (minTweak > maxTweak)
{
maxTweak = minTweak;
Expand Down

0 comments on commit 1dd1ab1

Please sign in to comment.