mirror of
https://github.com/Ellpeck/Coroutine.git
synced 2024-11-23 14:08:33 +01:00
code cleanup
This commit is contained in:
parent
fe9e5c658a
commit
201369f167
6 changed files with 22 additions and 22 deletions
|
@ -84,7 +84,7 @@ namespace Coroutine {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool OnEvent(Event evt) {
|
internal bool OnEvent(Event evt) {
|
||||||
if (!this.WasCanceled && Equals(this.current.Event, evt))
|
if (!this.WasCanceled && object.Equals(this.current.Event, evt))
|
||||||
this.MoveNext();
|
this.MoveNext();
|
||||||
return this.IsFinished;
|
return this.IsFinished;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,42 +11,42 @@ namespace Coroutine {
|
||||||
private static readonly CoroutineHandlerInstance Instance = new CoroutineHandlerInstance();
|
private static readonly CoroutineHandlerInstance Instance = new CoroutineHandlerInstance();
|
||||||
|
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.TickingCount"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.TickingCount"/>
|
||||||
public static int TickingCount => Instance.TickingCount;
|
public static int TickingCount => CoroutineHandler.Instance.TickingCount;
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.EventCount"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.EventCount"/>
|
||||||
public static int EventCount => Instance.EventCount;
|
public static int EventCount => CoroutineHandler.Instance.EventCount;
|
||||||
|
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerable{Wait},string,int)"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerable{Wait},string,int)"/>
|
||||||
public static ActiveCoroutine Start(IEnumerable<Wait> coroutine, string name = "", int priority = 0) {
|
public static ActiveCoroutine Start(IEnumerable<Wait> coroutine, string name = "", int priority = 0) {
|
||||||
return Instance.Start(coroutine, name, priority);
|
return CoroutineHandler.Instance.Start(coroutine, name, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerator{Wait},string,int)"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerator{Wait},string,int)"/>
|
||||||
public static ActiveCoroutine Start(IEnumerator<Wait> coroutine, string name = "", int priority = 0) {
|
public static ActiveCoroutine Start(IEnumerator<Wait> coroutine, string name = "", int priority = 0) {
|
||||||
return Instance.Start(coroutine, name, priority);
|
return CoroutineHandler.Instance.Start(coroutine, name, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.InvokeLater"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.InvokeLater"/>
|
||||||
public static ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) {
|
public static ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) {
|
||||||
return Instance.InvokeLater(wait, action, name, priority);
|
return CoroutineHandler.Instance.InvokeLater(wait, action, name, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(double)"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(double)"/>
|
||||||
public static void Tick(double deltaSeconds) {
|
public static void Tick(double deltaSeconds) {
|
||||||
Instance.Tick(deltaSeconds);
|
CoroutineHandler.Instance.Tick(deltaSeconds);
|
||||||
}
|
}
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(TimeSpan)"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(TimeSpan)"/>
|
||||||
public static void Tick(TimeSpan delta) {
|
public static void Tick(TimeSpan delta) {
|
||||||
Instance.Tick(delta);
|
CoroutineHandler.Instance.Tick(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.RaiseEvent"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.RaiseEvent"/>
|
||||||
public static void RaiseEvent(Event evt) {
|
public static void RaiseEvent(Event evt) {
|
||||||
Instance.RaiseEvent(evt);
|
CoroutineHandler.Instance.RaiseEvent(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="CoroutineHandlerInstance.GetActiveCoroutines"/>
|
/// <inheritdoc cref="CoroutineHandlerInstance.GetActiveCoroutines"/>
|
||||||
public static IEnumerable<ActiveCoroutine> GetActiveCoroutines() {
|
public static IEnumerable<ActiveCoroutine> GetActiveCoroutines() {
|
||||||
return Instance.GetActiveCoroutines();
|
return CoroutineHandler.Instance.GetActiveCoroutines();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace Coroutine {
|
||||||
/// <param name="priority">The <see cref="ActiveCoroutine.Priority"/> that the underlying coroutine should have. The higher the priority, the earlier it is advanced compared to other coroutines that advance around the same time. Defaults to 0.</param>
|
/// <param name="priority">The <see cref="ActiveCoroutine.Priority"/> that the underlying coroutine should have. The higher the priority, the earlier it is advanced compared to other coroutines that advance around the same time. Defaults to 0.</param>
|
||||||
/// <returns>An active coroutine object representing this coroutine</returns>
|
/// <returns>An active coroutine object representing this coroutine</returns>
|
||||||
public ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) {
|
public ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) {
|
||||||
return this.Start(InvokeLaterImpl(wait, action), name, priority);
|
return this.Start(CoroutineHandlerInstance.InvokeLaterImpl(wait, action), name, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -9,19 +9,19 @@ namespace Example {
|
||||||
private static readonly Event TestEvent = new Event();
|
private static readonly Event TestEvent = new Event();
|
||||||
|
|
||||||
public static void Main() {
|
public static void Main() {
|
||||||
var seconds = CoroutineHandler.Start(WaitSeconds(), "Awesome Waiting Coroutine");
|
var seconds = CoroutineHandler.Start(Example.WaitSeconds(), "Awesome Waiting Coroutine");
|
||||||
CoroutineHandler.Start(PrintEvery10Seconds(seconds));
|
CoroutineHandler.Start(Example.PrintEvery10Seconds(seconds));
|
||||||
|
|
||||||
CoroutineHandler.Start(EmptyCoroutine());
|
CoroutineHandler.Start(Example.EmptyCoroutine());
|
||||||
|
|
||||||
CoroutineHandler.InvokeLater(new Wait(5), () => {
|
CoroutineHandler.InvokeLater(new Wait(5), () => {
|
||||||
Console.WriteLine("Raising test event");
|
Console.WriteLine("Raising test event");
|
||||||
CoroutineHandler.RaiseEvent(TestEvent);
|
CoroutineHandler.RaiseEvent(Example.TestEvent);
|
||||||
});
|
});
|
||||||
CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("Example event received"));
|
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("Example event received"));
|
||||||
|
|
||||||
CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("I am invoked after 'Example event received'"), priority: -5);
|
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("I am invoked after 'Example event received'"), priority: -5);
|
||||||
CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2);
|
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2);
|
||||||
|
|
||||||
var lastTime = DateTime.Now;
|
var lastTime = DateTime.Now;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -38,7 +38,7 @@ namespace Example {
|
||||||
Console.WriteLine("After 1 second " + DateTime.Now);
|
Console.WriteLine("After 1 second " + DateTime.Now);
|
||||||
yield return new Wait(9);
|
yield return new Wait(9);
|
||||||
Console.WriteLine("After 10 seconds " + DateTime.Now);
|
Console.WriteLine("After 10 seconds " + DateTime.Now);
|
||||||
CoroutineHandler.Start(NestedCoroutine());
|
CoroutineHandler.Start(Example.NestedCoroutine());
|
||||||
yield return new Wait(5);
|
yield return new Wait(5);
|
||||||
Console.WriteLine("After 5 more seconds " + DateTime.Now);
|
Console.WriteLine("After 5 more seconds " + DateTime.Now);
|
||||||
yield return new Wait(10);
|
yield return new Wait(10);
|
||||||
|
|
|
@ -128,7 +128,7 @@ namespace Tests {
|
||||||
var p = CoroutineHandler.Start(Parent());
|
var p = CoroutineHandler.Start(Parent());
|
||||||
CoroutineHandler.RaiseEvent(onParentCreated);
|
CoroutineHandler.RaiseEvent(onParentCreated);
|
||||||
// Nested corotuine starting in OnFinished.
|
// Nested corotuine starting in OnFinished.
|
||||||
p.OnFinished += ac => {
|
p.OnFinished += _ => {
|
||||||
CoroutineHandler.Start(Child());
|
CoroutineHandler.Start(Child());
|
||||||
CoroutineHandler.RaiseEvent(onChildCreated);
|
CoroutineHandler.RaiseEvent(onChildCreated);
|
||||||
};
|
};
|
||||||
|
|
|
@ -164,7 +164,7 @@ namespace Tests {
|
||||||
// Nested corotuine starting.
|
// Nested corotuine starting.
|
||||||
var p = CoroutineHandler.Start(Parent());
|
var p = CoroutineHandler.Start(Parent());
|
||||||
// Nested corotuine starting in OnFinished.
|
// Nested corotuine starting in OnFinished.
|
||||||
p.OnFinished += ac => CoroutineHandler.Start(Child());
|
p.OnFinished += _ => CoroutineHandler.Start(Child());
|
||||||
}
|
}
|
||||||
|
|
||||||
var always = CoroutineHandler.Start(AlwaysRunning());
|
var always = CoroutineHandler.Start(AlwaysRunning());
|
||||||
|
@ -408,7 +408,7 @@ namespace Tests {
|
||||||
var p = CoroutineHandler.Start(Parent());
|
var p = CoroutineHandler.Start(Parent());
|
||||||
CoroutineHandler.RaiseEvent(onParentCreated);
|
CoroutineHandler.RaiseEvent(onParentCreated);
|
||||||
// Nested corotuine starting in OnFinished.
|
// Nested corotuine starting in OnFinished.
|
||||||
p.OnFinished += ac => {
|
p.OnFinished += _ => {
|
||||||
CoroutineHandler.Start(Child());
|
CoroutineHandler.Start(Child());
|
||||||
CoroutineHandler.RaiseEvent(onChildCreated);
|
CoroutineHandler.RaiseEvent(onChildCreated);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue