Skip to content

Commit

Permalink
Remove ICoroutineStopListener
Browse files Browse the repository at this point in the history
Replaced with a direct reference to the parent coroutine. Allows for the OnChildStopped method to be protected, preventing unwanted access from the outside.
  • Loading branch information
Inspiaaa committed Sep 4, 2024
1 parent 032a957 commit 8433d34
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
13 changes: 6 additions & 7 deletions src/CoroutineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ namespace HCoroutines;
/// The coroutines themselves act like a doubly linked list, so that
/// the list of children can be efficiently managed and even modified during iteration.
/// </summary>
public class CoroutineBase : ICoroutineStopListener
public class CoroutineBase
{
public CoroutineManager Manager;
// TODO: Implement as event?
public ICoroutineStopListener StopListener;

public CoroutineBase Parent;

protected CoroutineBase firstChild, lastChild;
protected CoroutineBase previousSibling, nextSibling;

Expand All @@ -23,8 +22,8 @@ public class CoroutineBase : ICoroutineStopListener

public void StartCoroutine(CoroutineBase coroutine)
{
coroutine.StopListener = this;
coroutine.Manager = Manager;
coroutine.Parent = this;

AddChild(coroutine);
coroutine.OnEnter();
Expand Down Expand Up @@ -74,7 +73,7 @@ public void PauseUpdates()
Manager.DeactivateCoroutine(this);
}

public virtual void OnChildStopped(CoroutineBase child)
protected virtual void OnChildStopped(CoroutineBase child)
{
// If the parent coroutine is dead, then there is no reason to
// manually remove the child coroutines.
Expand Down Expand Up @@ -114,7 +113,7 @@ public void Kill()
child = child.nextSibling;
}

StopListener?.OnChildStopped(this);
Parent?.OnChildStopped(this);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Coroutines/Coroutine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override void Update()
}
}

public override void OnChildStopped(CoroutineBase child)
protected override void OnChildStopped(CoroutineBase child)
{
base.OnChildStopped(child);
ResumeUpdates();
Expand Down
2 changes: 1 addition & 1 deletion src/Coroutines/ParallelCoroutine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override void OnEnter()
}
}

public override void OnChildStopped(CoroutineBase child)
protected override void OnChildStopped(CoroutineBase child)
{
base.OnChildStopped(child);

Expand Down
2 changes: 1 addition & 1 deletion src/Coroutines/RepeatCoroutine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void Repeat()
StartCoroutine(coroutine);
}

public override void OnChildStopped(CoroutineBase child)
protected override void OnChildStopped(CoroutineBase child)
{
base.OnChildStopped(child);

Expand Down
2 changes: 1 addition & 1 deletion src/Coroutines/SequentialCoroutine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnEnter()
StartCoroutine(coroutines[0]);
}

public override void OnChildStopped(CoroutineBase child)
protected override void OnChildStopped(CoroutineBase child)
{
base.OnChildStopped(child);

Expand Down
6 changes: 0 additions & 6 deletions src/ICoroutineStopListener.cs

This file was deleted.

0 comments on commit 8433d34

Please sign in to comment.