public void TimerReset()
        {
            ManualClock clock = new ManualClock();

            clock.Start();

            FixedStepTimer timer = new FixedStepTimer(clock)
            {
                StepSize         = TimeSpan.FromMilliseconds(10),
                MaxNumberOfSteps = 5,
            };

            timer.Idle        += timer_Idle;
            timer.TimeChanged += timer_TimeChanged;
            timer.Reset();
            timer.Start();

            clock.Update(TimeSpan.FromMilliseconds(10));
            CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10));

            timer.Reset();
            Assert.IsFalse(timer.IsRunning);
            Assert.AreEqual(TimeSpan.Zero, timer.Time);
            Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime);

            timer.Start();
            clock.Update(TimeSpan.FromMilliseconds(10));
            clock.Update(TimeSpan.FromMilliseconds(10));
            CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(10));

            timer.Stop();
            Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time);
            Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime);

            timer.Reset();
            Assert.AreEqual(TimeSpan.Zero, timer.Time);
            Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime);
        }
        public void AccumulatedStepsAndPendingSteps()
        {
            ManualClock clock = new ManualClock();

            clock.Start();

            FixedStepTimer timer = new FixedStepTimer(clock)
            {
                StepSize         = TimeSpan.FromMilliseconds(10),
                MaxNumberOfSteps = 5,
            };

            timer.Idle        += timer_Idle;
            timer.TimeChanged += timer_TimeChanged;
            timer.Start();

            timer.AccumulateTimeSteps = true;

            int desiredPendingSteps    = 0;
            int desiredAccumlatedSteps = 2;

            timer.TimeChanged += (s, e) =>
            {
                Assert.AreEqual(desiredPendingSteps, timer.PendingSteps);
                Assert.AreEqual(desiredAccumlatedSteps, timer.AccumulatedSteps);
                desiredPendingSteps--;
            };

            clock.Update(TimeSpan.FromMilliseconds(22));

            timer.Reset();
            timer.Start();

            timer.AccumulateTimeSteps = false;

            desiredPendingSteps    = 3;
            desiredAccumlatedSteps = 1;
            clock.Update(TimeSpan.FromMilliseconds(42));

            Assert.AreEqual(-1, desiredPendingSteps);
        }
Example #3
0
        public void AccumulatedStepsAndPendingSteps()
        {
            ManualClock clock = new ManualClock();
              clock.Start();

              FixedStepTimer timer = new FixedStepTimer(clock)
              {
            StepSize = TimeSpan.FromMilliseconds(10),
            MaxNumberOfSteps = 5,
              };
              timer.Idle += timer_Idle;
              timer.TimeChanged += timer_TimeChanged;
              timer.Start();

              timer.AccumulateTimeSteps = true;

              int desiredPendingSteps = 0;
              int desiredAccumlatedSteps = 2;

              timer.TimeChanged += (s, e) =>
              {
            Assert.AreEqual(desiredPendingSteps, timer.PendingSteps);
            Assert.AreEqual(desiredAccumlatedSteps, timer.AccumulatedSteps);
            desiredPendingSteps--;
              };

              clock.Update(TimeSpan.FromMilliseconds(22));

              timer.Reset();
              timer.Start();

              timer.AccumulateTimeSteps = false;

              desiredPendingSteps = 3;
              desiredAccumlatedSteps = 1;
              clock.Update(TimeSpan.FromMilliseconds(42));

              Assert.AreEqual(-1, desiredPendingSteps);
        }
Example #4
0
        public void TimerReset()
        {
            ManualClock clock = new ManualClock();
              clock.Start();

              FixedStepTimer timer = new FixedStepTimer(clock)
              {
            StepSize = TimeSpan.FromMilliseconds(10),
            MaxNumberOfSteps = 5,
              };
              timer.Idle += timer_Idle;
              timer.TimeChanged += timer_TimeChanged;
              timer.Reset();
              timer.Start();

              clock.Update(TimeSpan.FromMilliseconds(10));
              CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10));

              timer.Reset();
              Assert.IsFalse(timer.IsRunning);
              Assert.AreEqual(TimeSpan.Zero, timer.Time);
              Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime);

              timer.Start();
              clock.Update(TimeSpan.FromMilliseconds(10));
              clock.Update(TimeSpan.FromMilliseconds(10));
              CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(10));

              timer.Stop();
              Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time);
              Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime);

              timer.Reset();
              Assert.AreEqual(TimeSpan.Zero, timer.Time);
              Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime);
        }