mirror of
https://github.com/Ellpeck/Coroutine.git
synced 2024-11-21 21:33:29 +01:00
Revert "synchronize coroutines to allow interaction from different threads"
This reverts commit 708941ff
This commit is contained in:
parent
708941ff01
commit
99aab497e5
1 changed files with 26 additions and 37 deletions
|
@ -7,10 +7,8 @@ namespace Coroutine {
|
|||
|
||||
private static readonly List<ActiveCoroutine> TickingCoroutines = new List<ActiveCoroutine>();
|
||||
private static readonly List<ActiveCoroutine> EventCoroutines = new List<ActiveCoroutine>();
|
||||
private static readonly object Lock = new object();
|
||||
|
||||
public static ActiveCoroutine Start(IEnumerator<IWait> coroutine) {
|
||||
lock (Lock) {
|
||||
var inst = new ActiveCoroutine(coroutine);
|
||||
var type = inst.GetCurrentType();
|
||||
if (type == WaitType.Tick)
|
||||
|
@ -19,24 +17,20 @@ namespace Coroutine {
|
|||
EventCoroutines.Add(inst);
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Stop(ActiveCoroutine coroutine) {
|
||||
lock (Lock) {
|
||||
if (TickingCoroutines.Remove(coroutine) || EventCoroutines.Remove(coroutine)) {
|
||||
coroutine.Finish(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void InvokeLater(IWait wait, Action action) {
|
||||
Start(InvokeLaterImpl(wait, action));
|
||||
}
|
||||
|
||||
public static void Tick(double deltaSeconds) {
|
||||
lock (Lock) {
|
||||
for (var i = TickingCoroutines.Count - 1; i >= 0; i--) {
|
||||
var coroutine = TickingCoroutines[i];
|
||||
if (coroutine.Tick(deltaSeconds)) {
|
||||
|
@ -47,10 +41,8 @@ namespace Coroutine {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RaiseEvent(Event evt) {
|
||||
lock (Lock) {
|
||||
for (var i = EventCoroutines.Count - 1; i >= 0; i--) {
|
||||
var coroutine = EventCoroutines[i];
|
||||
if (coroutine.OnEvent(evt)) {
|
||||
|
@ -61,13 +53,10 @@ namespace Coroutine {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<ActiveCoroutine> GetActiveCoroutines() {
|
||||
lock (Lock) {
|
||||
return TickingCoroutines.Concat(EventCoroutines);
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerator<IWait> InvokeLaterImpl(IWait wait, Action action) {
|
||||
yield return wait;
|
||||
|
|
Loading…
Reference in a new issue