code cleanup

This commit is contained in:
Ell 2023-02-23 19:04:16 +01:00
parent fe9e5c658a
commit 201369f167
6 changed files with 22 additions and 22 deletions

View file

@ -84,7 +84,7 @@ namespace Coroutine {
}
internal bool OnEvent(Event evt) {
if (!this.WasCanceled && Equals(this.current.Event, evt))
if (!this.WasCanceled && object.Equals(this.current.Event, evt))
this.MoveNext();
return this.IsFinished;
}

View file

@ -11,42 +11,42 @@ namespace Coroutine {
private static readonly CoroutineHandlerInstance Instance = new CoroutineHandlerInstance();
/// <inheritdoc cref="CoroutineHandlerInstance.TickingCount"/>
public static int TickingCount => Instance.TickingCount;
public static int TickingCount => CoroutineHandler.Instance.TickingCount;
/// <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)"/>
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)"/>
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"/>
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)"/>
public static void Tick(double deltaSeconds) {
Instance.Tick(deltaSeconds);
CoroutineHandler.Instance.Tick(deltaSeconds);
}
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(TimeSpan)"/>
public static void Tick(TimeSpan delta) {
Instance.Tick(delta);
CoroutineHandler.Instance.Tick(delta);
}
/// <inheritdoc cref="CoroutineHandlerInstance.RaiseEvent"/>
public static void RaiseEvent(Event evt) {
Instance.RaiseEvent(evt);
CoroutineHandler.Instance.RaiseEvent(evt);
}
/// <inheritdoc cref="CoroutineHandlerInstance.GetActiveCoroutines"/>
public static IEnumerable<ActiveCoroutine> GetActiveCoroutines() {
return Instance.GetActiveCoroutines();
return CoroutineHandler.Instance.GetActiveCoroutines();
}
}

View file

@ -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>
/// <returns>An active coroutine object representing this coroutine</returns>
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>

View file

@ -9,19 +9,19 @@ namespace Example {
private static readonly Event TestEvent = new Event();
public static void Main() {
var seconds = CoroutineHandler.Start(WaitSeconds(), "Awesome Waiting Coroutine");
CoroutineHandler.Start(PrintEvery10Seconds(seconds));
var seconds = CoroutineHandler.Start(Example.WaitSeconds(), "Awesome Waiting Coroutine");
CoroutineHandler.Start(Example.PrintEvery10Seconds(seconds));
CoroutineHandler.Start(EmptyCoroutine());
CoroutineHandler.Start(Example.EmptyCoroutine());
CoroutineHandler.InvokeLater(new Wait(5), () => {
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(TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2);
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("I am invoked after 'Example event received'"), priority: -5);
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2);
var lastTime = DateTime.Now;
while (true) {
@ -38,7 +38,7 @@ namespace Example {
Console.WriteLine("After 1 second " + DateTime.Now);
yield return new Wait(9);
Console.WriteLine("After 10 seconds " + DateTime.Now);
CoroutineHandler.Start(NestedCoroutine());
CoroutineHandler.Start(Example.NestedCoroutine());
yield return new Wait(5);
Console.WriteLine("After 5 more seconds " + DateTime.Now);
yield return new Wait(10);

View file

@ -128,7 +128,7 @@ namespace Tests {
var p = CoroutineHandler.Start(Parent());
CoroutineHandler.RaiseEvent(onParentCreated);
// Nested corotuine starting in OnFinished.
p.OnFinished += ac => {
p.OnFinished += _ => {
CoroutineHandler.Start(Child());
CoroutineHandler.RaiseEvent(onChildCreated);
};

View file

@ -164,7 +164,7 @@ namespace Tests {
// Nested corotuine starting.
var p = CoroutineHandler.Start(Parent());
// Nested corotuine starting in OnFinished.
p.OnFinished += ac => CoroutineHandler.Start(Child());
p.OnFinished += _ => CoroutineHandler.Start(Child());
}
var always = CoroutineHandler.Start(AlwaysRunning());
@ -408,7 +408,7 @@ namespace Tests {
var p = CoroutineHandler.Start(Parent());
CoroutineHandler.RaiseEvent(onParentCreated);
// Nested corotuine starting in OnFinished.
p.OnFinished += ac => {
p.OnFinished += _ => {
CoroutineHandler.Start(Child());
CoroutineHandler.RaiseEvent(onChildCreated);
};