Skip to content

Commit

Permalink
fix, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
meirumeiru committed Apr 3, 2018
1 parent 0d1b2f1 commit a51a174
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 65 deletions.
2 changes: 0 additions & 2 deletions InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,6 @@ private void InitEditorServoControls(GameObject newServoLine, ControlGroup g, IS
IRBuildAid.IRBuildAidManager.Instance.HideServoRange(s);
g.servosState[s].bIsBuildAidOn = v;
s = s;
});
if(HighLogic.LoadedSceneIsEditor && g.servosState[s].bIsBuildAidOn)
{
Expand Down
150 changes: 87 additions & 63 deletions InfernalRobotics/InfernalRobotics/Module/ModuleIRServo_v3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override void OnAwake()
lightColorId = Shader.PropertyToID("_EmissiveColor");
lightColorOff = new Color(0, 0, 0, 0);
lightColorLocked = new Color(1, 0, 0, 1);
lightColorIdle = new Color(1, 1, 0, 1);
lightColorIdle = new Color(1, 0.7f, 0, 1);
lightColorMoving = new Color(0, 1, 0, 1);
}

Expand All @@ -166,6 +166,9 @@ public override void OnStart(StartState state)
{
base.OnStart(state);

// Renderer for lights
lightRenderer = part.gameObject.GetComponentInChildren<Renderer>(); // do this before workaround

if(state == StartState.Editor)
{
part.OnEditorAttach = (Callback)Delegate.Combine(part.OnEditorAttach, new Callback(onEditorAttached));
Expand Down Expand Up @@ -200,9 +203,6 @@ public override void OnStart(StartState state)
// FEHLER ??? einfügen in liste
}

// Renderer for lights
lightRenderer = part.gameObject.GetComponentInChildren<Renderer>();

AttachContextMenu();

UpdateUI();
Expand Down Expand Up @@ -509,7 +509,7 @@ public void InitializeLimits()
{
bUseDynamicLimitJoint = (hasPositionLimit || hasMinMaxPosition) && (max - min > 140);

if(!bUseDynamicLimitJoint)
if(!bUseDynamicLimitJoint && (hasPositionLimit || hasMinMaxPosition))
{
// we only use (unity-)limits on this joint for parts with a small range (because of the 177° limits in unity)

Expand Down Expand Up @@ -686,6 +686,38 @@ public static float to360(float v)
return v;
}

private bool UpdateAndConsumeElectricCharge()
{
if((electricChargeRequired == 0f) || isFreeMoving)
return true;

ip.PrepareUpdate(TimeWarp.fixedDeltaTime);

float amountToConsume = electricChargeRequired * TimeWarp.fixedDeltaTime;

amountToConsume *= TorqueLimit / MaxTorque;
amountToConsume *= (ip.NewSpeed + ip.Speed) / (2 * maxSpeed * factorSpeed);

float amountConsumed = part.RequestResource(electricResource.id, amountToConsume);

LastPowerDrawRate = amountConsumed / TimeWarp.fixedDeltaTime;

return amountConsumed == amountToConsume;
}

private bool IsStopping()
{
if(ip.IsStopping)
return true;

bool bRes = ip.Stop();

// Stop changed the direction -> we need to recalculate this now
ip.PrepareUpdate(TimeWarp.fixedDeltaTime);

return bRes;
}

// set original rotation to new rotation
public void UpdatePos()
{
Expand Down Expand Up @@ -774,38 +806,8 @@ public void UpdatePos()
IsRotation = transform.rotation;
}

public void Update()
{
if(soundSound != null)
{
float pitchMultiplier = Math.Max(Math.Abs(Speed / factorSpeed), 0.05f);
// FEHLER, Division, blöd

if(pitchMultiplier > 1)
pitchMultiplier = (float)Math.Sqrt(pitchMultiplier);

soundSound.Update(soundVolume, soundPitch * pitchMultiplier);
}

if(HighLogic.LoadedSceneIsFlight)
{
CheckInputs();


double amount, maxAmount;
part.GetConnectedResourceTotals(electricResource.id, electricResource.resourceFlowMode, out amount, out maxAmount);

if(amount == 0)
{
if(lightStatus != -1)
{
lightStatus = -1;
lightRenderer.material.SetColor(lightColorId, lightColorOff);
}
}
else if(lightStatus == -1) lightStatus = -2;
}
}
////////////////////////////////////////
// Update-Functions

public void FixedUpdate()
{
Expand Down Expand Up @@ -879,19 +881,37 @@ public void FixedUpdate()
Joint.transform.TransformDirection(Joint.axis))
- jointconnectedzero;

// correct value into a plausible range
// correct value into a plausible range -> FEHLER, unschön, dass es zwei Schritte braucht -> nochmal prüfen auch wird -90 als 270 angezeigt nach dem Laden?
float newPositionCorrected = newPosition - zeroNormal - correction_1 + correction_0;
float positionCorrected = position - zeroNormal - correction_1 + correction_0;

if(newPositionCorrected < positionCorrected)
{
if((positionCorrected - newPositionCorrected) > (newPositionCorrected + 360f - positionCorrected))
{
newPosition += 360f;
newPositionCorrected = newPosition - zeroNormal - correction_1 + correction_0;
}
}
else
{
if((newPositionCorrected - positionCorrected) > (positionCorrected - newPositionCorrected + 360f))
{
newPosition -= 360f;
newPositionCorrected = newPosition - zeroNormal - correction_1 + correction_0;
}
}

while(newPositionCorrected < -360f)
{
newPosition += 360f;
newPositionCorrected += 360f;
}

while(newPositionCorrected > 360f)
{
newPosition -= 360f;
newPositionCorrected -= 360f;
}

// manuell dämpfen der Bewegung
Expand Down Expand Up @@ -1073,36 +1093,37 @@ public void FixedUpdate()
ProcessShapeUpdates();
}

private bool UpdateAndConsumeElectricCharge()
public void Update()
{
if((electricChargeRequired == 0f) || isFreeMoving)
return true;

ip.PrepareUpdate(TimeWarp.fixedDeltaTime);

float amountToConsume = electricChargeRequired * TimeWarp.fixedDeltaTime;

amountToConsume *= TorqueLimit / MaxTorque;
amountToConsume *= (ip.NewSpeed + ip.Speed) / (2 * maxSpeed * factorSpeed);

float amountConsumed = part.RequestResource(electricResource.id, amountToConsume);
if(soundSound != null)
{
float pitchMultiplier = Math.Max(Math.Abs(Speed / factorSpeed), 0.05f);
// FEHLER, Division, blöd

LastPowerDrawRate = amountConsumed / TimeWarp.fixedDeltaTime;
if(pitchMultiplier > 1)
pitchMultiplier = (float)Math.Sqrt(pitchMultiplier);

return amountConsumed == amountToConsume;
}
soundSound.Update(soundVolume, soundPitch * pitchMultiplier);
}

private bool IsStopping()
{
if(ip.IsStopping)
return true;
if(HighLogic.LoadedSceneIsFlight)
{
CheckInputs();

bool bRes = ip.Stop();

// Stop changed the direction -> we need to recalculate this now
ip.PrepareUpdate(TimeWarp.fixedDeltaTime);
double amount, maxAmount;
part.GetConnectedResourceTotals(electricResource.id, electricResource.resourceFlowMode, out amount, out maxAmount);

return bRes;
if(amount == 0)
{
if(lightStatus != -1)
{
lightStatus = -1;
lightRenderer.material.SetColor(lightColorId, lightColorOff);
}
}
else if(lightStatus == -1) lightStatus = -2;
}
}

////////////////////////////////////////
Expand Down Expand Up @@ -1233,11 +1254,11 @@ public void OnRescale(ScalingFactor factor)
}

////////////////////////////////////////
// IJointLockState
// IJointLockState (auto strut support)

bool IJointLockState.IsJointUnlocked()
{
return !isLocked;
return !isLocked && !isOnRails;
}

////////////////////////////////////////
Expand Down Expand Up @@ -1349,6 +1370,9 @@ public bool IsLocked
if(isLocked)
Stop();

if(vessel) // not set in editor
vessel.CycleAllAutoStrut();

UpdateUI();
}
}
Expand Down

0 comments on commit a51a174

Please sign in to comment.