public void Update(GameTime time) { if (this.currentMove != null && !this.currentMove.IsFinished) { return; } do { if (this.remainingRound.Count <= 0) { this.PopulateRound(); } this.currentEntity = this.remainingRound.Dequeue(); if (this.currentEntity.IsDead) { continue; } var turn = this.currentEntity.MakeTurn(this); if (turn == null) { continue; } this.currentMove = CoroutineHandler.Start(turn.GetEnumerator()); break; } while (true); }
public void DisplayCaption(string[] text, Action <GameImpl> afterDisplay = null) { IEnumerator <IWait> CaptionImpl() { foreach (var par in text) { this.caption.RemoveChildren(); var lines = par.Split("\n"); var paragraphs = new Paragraph[lines.Length]; for (var i = 0; i < lines.Length; i++) { paragraphs[i] = this.caption.AddChild(new Paragraph(Anchor.AutoCenter, 1, lines[i], true)); } this.caption.DrawAlpha = 0; while (this.caption.DrawAlpha < 1) { this.caption.DrawAlpha += 0.01F; yield return(new WaitEvent(CoroutineEvents.Update)); } yield return(new WaitSeconds(3)); while (this.caption.DrawAlpha > 0) { this.caption.DrawAlpha -= 0.01F; yield return(new WaitEvent(CoroutineEvents.Update)); } yield return(new WaitSeconds(1)); } afterDisplay?.Invoke(this); } this.cutscene = CoroutineHandler.Start(CaptionImpl()); }
private static IEnumerator <Wait> PrintEvery10Seconds(ActiveCoroutine first) { while (true) { yield return(new Wait(10)); Console.WriteLine("The time is " + DateTime.Now); if (first.IsFinished) { Console.WriteLine("By the way, the first coroutine has finished!"); Console.WriteLine($"{first.Name} data: {first.MoveNextCount} moves, " + $"{first.TotalMoveNextTime.TotalMilliseconds} total time, " + $"{first.LastMoveNextTime.TotalMilliseconds} last time"); Environment.Exit(0); } } }
public void Fade(float speed, Action <GameImpl> afterFade = null) { IEnumerator <IWait> FadeImpl() { var fadingIn = this.fade.DrawAlpha >= 0.5F; if (fadingIn) { speed *= -1; } while (fadingIn ? this.fade.DrawAlpha > 0 : this.fade.DrawAlpha < 1) { this.fade.DrawAlpha += speed; yield return(new WaitEvent(CoroutineEvents.Update)); } afterFade?.Invoke(this); } this.cutscene = CoroutineHandler.Start(FadeImpl()); }
public void TestCoroutineReturningWeirdYields() { var counter = 0; IEnumerator <Wait> OnTimeTickNeverReturnYield() { counter++; // 1 // condition that's expected to be false if (counter == 100) { yield return(new Wait(0.1d)); } counter++; // 2 } IEnumerator <Wait> OnTimeTickYieldBreak() { counter++; // 3 yield break; } var cr = new ActiveCoroutine[2]; cr[0] = CoroutineHandler.Start(OnTimeTickNeverReturnYield()); cr[1] = CoroutineHandler.Start(OnTimeTickYieldBreak()); for (var i = 0; i < 5; i++) { CoroutineHandler.Tick(1); } Assert.AreEqual(3, counter, "Incorrect counter value."); for (var i = 0; i < cr.Length; i++) { Assert.AreEqual(true, cr[i].IsFinished, $"Incorrect IsFinished value on index {i}."); Assert.AreEqual(false, cr[i].WasCanceled, $"Incorrect IsCanceled value on index {i}"); Assert.AreEqual(1, cr[i].MoveNextCount, $"Incorrect MoveNextCount value on index {i}"); } }
public SampleOverlay() { myRoutine1 = CoroutineHandler.Start(TickServiceAsync(), name: "MyRoutine-1"); myRoutine2 = CoroutineHandler.Start(EventServiceAsync(), name: "MyRoutine-2"); }