public void ScheduleCancel()
        {
            var system = ActorSystem.Create("SchedulerTests");

            AutoResetEvent[] firedEvents = new AutoResetEvent[3];
            firedEvents[0] = new AutoResetEvent(false);
            firedEvents[1] = new AutoResetEvent(false);
            firedEvents[2] = new AutoResetEvent(false);

            var actor = system.ActorOf(typeof(SchedulerTestRepeating), Props.With((object)firedEvents));

            Cancellable schedule = system.Scheduler.Schedule(100, 100, actor, "FIRED");

            var fired1 = firedEvents[0].WaitOne(1000, false);
            var fired2 = firedEvents[1].WaitOne(1000, false);

            schedule.Cancel();

            var fired3 = firedEvents[2].WaitOne(1000, false);

            system.Stop(actor);

            system.Shutdown();

            Assert.IsTrue(fired1);
            Assert.IsTrue(fired2);
            Assert.IsFalse(fired3);
            Assert.IsTrue(schedule.Cancelled);
        }
Exemple #2
0
 public void DestroySpawned()
 {
     cT?.Cancel();
     cT = null;
     foreach (var sr in spriteRenders)
     {
         if (sr != null)
         {
             UnityEngine.Object.Destroy(sr.gameObject);
         }
     }
     spriteRenders = new SpriteRenderer[0];
 }
Exemple #3
0
        public static void TestCancellation()
        {
            CoroutineRegularUpdater cru = new GameObject().AddComponent <CoroutineRegularUpdater>();
            var cts = new Cancellable();

            cru.RunRIEnumerator(LeaveOnCancel(cts));
            cru.RegularUpdate();
            cru.RegularUpdate();
            Assert.AreEqual(cru.NumRunningCoroutines, 1);
            cts.Cancel();
            cru.RegularUpdate();
            Assert.AreEqual(cru.NumRunningCoroutines, 0);
        }
Exemple #4
0
        public void TestCancel()
        {
            var v    = new Vector2(-2, -2);
            var cors = new Coroutines();
            var ct   = new Cancellable();
            var tw   = (Tween.TweenTo(Vector2.Zero, Vector2.One, 20, x => v = x, Easers.ELinear, ct)).Run(cors);

            cors.Step();
            cors.Step();
            VecEq(v, Vector2.One / 20f);
            ct.Cancel(1);
            cors.Step();
            VecEq(v, Vector2.One);
            Assert.AreEqual(tw.Result, Completion.SoftSkip);

            ct = new Cancellable();
            tw = (Tween.TweenTo(Vector2.Zero, Vector2.One, 20, x => v = x, Easers.ELinear, ct)).Run(cors);
            cors.Step();
            cors.Step();
            VecEq(v, Vector2.One / 20f);
            ct.Cancel(2);
            cors.Step();
            VecEq(v, Vector2.One / 20f);
            Assert.IsTrue(tw.IsCanceled);


            ct = new Cancellable();
            var t0 = (Tween.TweenTo(Vector2.Zero, Vector2.One, 5, x => v = x, Easers.ELinear, ct));

            tw = t0.Then(t0.Reverse()).Run(cors);
            cors.Step();
            cors.Step();
            VecEq(v, new Vector2(0.2f, 0.2f));
            ct.Cancel(1);
            cors.Step();
            VecEq(v, Vector2.Zero);
            Assert.AreEqual(tw.Result, Completion.SoftSkip);

            ct = new Cancellable();
            t0 = (Tween.TweenTo(Vector2.Zero, Vector2.One, 5, x => v = x, Easers.ELinear, ct));
            tw = t0.Then(t0.Reverse()).Run(cors);
            cors.Step();
            cors.Step();
            VecEq(v, new Vector2(0.2f, 0.2f));
            ct.Cancel(2);
            cors.Step();
            VecEq(v, new Vector2(0.2f, 0.2f));
            Assert.IsTrue(tw.IsCanceled);
        }
Exemple #5
0
        public static IEnumerator WaitWhileWithCancellable(Func <bool> amIFinishedWaiting, Cancellable canceller, Func <bool> cancelIf, ICancellee cT, Action done, float delay = 0f)
        {
            while (!amIFinishedWaiting() && !cT.Cancelled)
            {
                if (delay < ETime.FRAME_YIELD && cancelIf())
                {
                    canceller.Cancel();
                    break;
                }
                yield return(null);

                delay -= ETime.FRAME_TIME;
            }
            done();
        }
Exemple #6
0
 /// <summary>
 /// Outer waiter-- Will not cancel if cancelled
 /// </summary>
 public static void WaitThenCancel(CoroutineRegularUpdater Exec, ICancellee cT, float time, bool zeroToInfinity,
                                   Cancellable toCancel)
 {
     cT.ThrowIfCancelled();
     if (zeroToInfinity && time < float.Epsilon)
     {
         time = float.MaxValue;
     }
     Exec.RunRIEnumerator(WaitFor(time, cT, () => {
         if (!cT.Cancelled)
         {
             toCancel.Cancel();
         }
     }));
 }
Exemple #7
0
        public static IEnumerator TestAutoCancellation()
        {
            CoroutineRegularUpdater cru = new GameObject().AddComponent <CoroutineRegularUpdater>();
            var cts = new Cancellable();

            cru.RunRIEnumerator(NestLoC(cts));
            cts.Cancel();
            cru.gameObject.SetActive(false);
            Assert.AreEqual(cru.NumRunningCoroutines, 0);
            cru.gameObject.SetActive(true);
            cru.RunDroppableRIEnumerator(NestLoC(Cancellable.Null));
            cru.gameObject.SetActive(false);
            Assert.AreEqual(cru.NumRunningCoroutines, 0);
            cru.gameObject.SetActive(true);
            cru.RunRIEnumerator(NestLoC(Cancellable.Null));
            LogAssert.Expect(LogType.Error, new Regex(".*1 leftover coroutine.*"));
            cru.gameObject.SetActive(false);
            Assert.AreEqual(cru.NumRunningCoroutines, 1);
            yield return(null);
        }
Exemple #8
0
        public void OnCheckIfLevelCanAdvance(Cancellable canceller)
        {
            if (canceller.IsCancelled)
            {
                return;
            }

            var canAdvance = Plugin.AdvanceWhenAllPlayersFinish;

            foreach (var player in Plugin.Server.ValidPlayers)
            {
                if ((player.Car != null && !player.Car.Finished) || DistanceServerMain.UnixTime - player.RestartTime < 30)
                {
                    canAdvance = false;
                    break;
                }
            }

            if (canAdvance)
            {
                Log.Debug($"Advancing because all players with cars have finished.");
                Plugin.Server.SayChat(DistanceChat.Server("AutoServer:Advancing:Finished", "All players finished. Advancing to the next level in 10 seconds."));
                return;
            }

            canceller.Cancel();

            if (Plugin.AdvanceWhenStartingPlayersFinish)
            {
                if (!TimeoutStarted && Plugin.GetUnfinishedStartingPlayersCount() == 0)
                {
                    LevelEndTime   = DistanceServerMain.NetworkTime + 60.0;
                    TimeoutStarted = true;
                    Plugin.SetCountdownTime(Plugin.Server.ModeTime + 60.0);
                    Plugin.Server.SayChat(DistanceChat.Server("AutoServer:Warning:InitialFinished", Plugin.StartingPlayersFinishedMessageGetter()));
                }
            }
        }
Exemple #9
0
        public void TestLoopCancel()
        {
            var v    = new Vector2(-2, -2);
            var cors = new Coroutines();
            var ct   = new Cancellable();
            var t0   = Tween.TweenTo(Vector2.Zero, Vector2.One, 2, x => v = x, Easers.ELinear, ct);
            var tw   = TestSteps(t0.Then(t0.Reverse()).Loop(), cors, () => v, new[] {
                Vector2.Zero,
                Vector2.One * 0.5f,
                Vector2.One,
                Vector2.One * 0.5f,
                Vector2.Zero,
                Vector2.One * 0.5f,
                Vector2.One,
                Vector2.One * 0.5f,
                Vector2.Zero,
            }, VecEq, false);

            ct.Cancel(CancelHelpers.SoftSkipLevel);
            //Cancellation requires one step before it is processed
            Assert.IsFalse(tw.IsCanceled);
            cors.Step();
            Assert.AreEqual(tw.Result, Completion.SoftSkip);
        }
Exemple #10
0
 public void OnCheckIfModeCanAdvance(Cancellable canceller)
 {
     canceller.Cancel();
 }