Skip to content

Commit

Permalink
Improve coroutine performance
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
SofieBrink committed Nov 16, 2024
1 parent 30e99bb commit 1f4b847
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Source/Modules/ModuleBCSAirbags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private void SetupPartIcon()
}
}

private void StopAltitudeCoroutine()
private void StopAltitudeCoroutine()
{
if (altitudeCoroutine != null)
{
Expand Down Expand Up @@ -323,15 +323,15 @@ private void PlayAnimation(Animation anim, string animationName, float start, fl
// Coroutines
public IEnumerator AltitudeCoroutine()
{
yield return new WaitUntil(ShouldDeploy);
while (!ShouldDeploy()) yield return new WaitForFixedUpdate();
part.stackIcon.SetIconColor(XKCDColors.Yellow);
if (nodeCoroutine == null) nodeCoroutine = StartCoroutine(NodeCoroutine());
}

public IEnumerator NodeCoroutine()
{
StopAltitudeCoroutine();
yield return new WaitUntil(NodeDetached);
while (!NodeDetached()) yield return new WaitForFixedUpdate();

bool isAboveWater = vessel.terrainAltitude <= 0;
if ((isAboveWater && !deployAboveWater) || (!isAboveWater && !deployAboveLand)) Disarm();
Expand Down
3 changes: 2 additions & 1 deletion Source/Modules/ModuleDecoupleAtAltitude.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ protected bool ShouldJetison()

public IEnumerator AltitudeDecouple()
{
yield return new WaitUntil(ShouldJetison);
while (!ShouldJetison()) yield return new WaitForFixedUpdate();

Decouple();
}
}
Expand Down

0 comments on commit 1f4b847

Please sign in to comment.