Ejemplo n.º 1
0
        public TimedGameEvent(TimePeriod timeSpan, GameEvent gameEvent)
        {
            this.timeSpan = timeSpan;
            GameEvent     = gameEvent;

            timeOfCreation = StaticTimer.GetElapsedMilliseconds();
        }
        public void RepeatedTestPauseTimer()
        {
            var testTimer = new Stopwatch();

            StaticTimer.RestartTimer();

            for (int i = 0; i < 10; i++)
            {
                StaticTimer.ResumeTimer();
                Assert.GreaterOrEqual(StaticTimer.GetElapsedMilliseconds(), 1000 * i, $"test {i} (1)");
                Assert.Less(StaticTimer.GetElapsedMilliseconds(), 50 + 1000 * i, $"test {i} (2)");
                Wait(testTimer, 1000);
                StaticTimer.PauseTimer();
            }
        }
        public void TestPauseTimer()
        {
            var testTimer = new Stopwatch();

            StaticTimer.RestartTimer();
            Wait(testTimer, 1000);
            StaticTimer.PauseTimer();
            Assert.GreaterOrEqual(StaticTimer.GetElapsedMilliseconds(), 1000, "test 1");

            Wait(testTimer, 1000);
            StaticTimer.ResumeTimer();
            Wait(testTimer, 1000);
            //Assert.AreEqual(2000, StaticTimer.GetElapsedMilliseconds(), "test 2 første");
            Assert.GreaterOrEqual(StaticTimer.GetElapsedMilliseconds(), 2000, "test 2");
        }
        public void TestSingleEvent(int timeSpan)
        {
            container.AddTimedEvent(TimeSpanType.Milliseconds, timeSpan, "msg", "par1", "par2");

            // elapse timeSpan for events to expire
            var startTime = StaticTimer.GetElapsedMilliseconds();
            var nowTime   = 0.0;

            // save some space, because system timers are never 100% precise
            while ((nowTime = StaticTimer.GetElapsedMilliseconds()) - startTime < timeSpan + 10)
            {
            }

            container.ProcessTimedEvents();
            bus.ProcessEventsSequentially(); // events must be processed on the main thread!
            Assert.AreEqual(1, processor.ObservedEvents);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Render this ImageStride object onto the currently active drawing window
        /// </summary>
        /// <param name="shape">The Shape object for the rendered image</param>
        public void Render(Shape shape)
        {
            // measure elapsed time
            double elapsed = StaticTimer.GetElapsedMilliseconds() + timerOffset;

            // the desired number of milliseconds has passed, change texture stride
            if (animFrequency > 0 && animate && elapsed - lastTime > animFrequency)
            {
                lastTime = elapsed;

                currentImageCount =
                    (currentImageCount >= maxImageCount) ? 0 : currentImageCount + 1;
            }

            // render the current texture object
            textures[currentImageCount].Render(shape);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Measure time and check if the event is ready for processing.
        /// </summary>
        public bool HasExpired()
        {
            var now = StaticTimer.GetElapsedMilliseconds();

            return((now - timeOfCreation) > timeSpan.ToMilliseconds());
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Restart animation for this ImageStride object
 /// </summary>
 public void StartAnimation()
 {
     animate  = true;
     lastTime = StaticTimer.GetElapsedMilliseconds();
 }
Ejemplo n.º 8
0
 public void ResetAnimation()
 {
     timeOfCreation = StaticTimer.GetElapsedMilliseconds();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// The animation is still considered active if the specified duration
 /// in milliseconds has not yet passed.
 /// </summary>
 public bool IsActive()
 {
     return(timeOfCreation + Duration > StaticTimer.GetElapsedMilliseconds());
 }