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
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            if (keyAction == "KEY_PRESS")
            {
                switch (keyValue)
                {
                case "KEY_UP":
                    if (activeMenuButton > 0)
                    {
                        menuButtons[activeMenuButton].SetColor(new Vec3F(1.0f, 0.0f, 0.0f));
                        activeMenuButton--;
                        menuButtons[activeMenuButton].SetColor(new Vec3F(0.0f, 1.0f, 0.0f));
                    }
                    break;

                case "KEY_DOWN":
                    if (activeMenuButton < maxMenuButtons - 1)
                    {
                        menuButtons[activeMenuButton].SetColor(new Vec3F(1.0f, 0.0f, 0.0f));
                        activeMenuButton++;
                        menuButtons[activeMenuButton].SetColor(new Vec3F(0.0f, 1.0f, 0.0f));
                    }
                    break;

                case "KEY_ENTER":
                    StaticTimer.ResumeTimer();
                    if (activeMenuButton == 1)
                    {
                        LevelContainer.GetInstance().Restart();
                        SpaceTaxiBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent,
                                this, "CHANGE_STATE", "MAIN_MENU", ""));
                    }
                    else if (activeMenuButton == 0)
                    {
                        SpaceTaxiBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent,
                                this, "CHANGE_STATE", "GAME_RUNNING", ""));
                    }
                    break;
                }
            }
        }
Ejemplo n.º 7
0
        public void KeyPress(string key)
        {
            switch (key)
            {
            case "KEY_ESCAPE":
                StaticTimer.PauseTimer();
                eventBus.RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_PAUSED", ""));
                break;

            case "KEY_F12":
                eventBus.RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.WindowEvent, this, "SAVE_SCREENSHOT", "", ""));
                break;

            case "KEY_UP":
                eventBus.RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_UPWARDS", "", ""));
                break;

            case "KEY_LEFT":
                eventBus.RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_TO_LEFT", "", ""));
                break;

            case "KEY_RIGHT":
                eventBus.RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_TO_RIGHT", "", ""));
                break;
            }
        }
Ejemplo n.º 8
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.º 9
0
 /// <summary>
 /// Restart animation for this ImageStride object
 /// </summary>
 public void StartAnimation()
 {
     animate  = true;
     lastTime = StaticTimer.GetElapsedMilliseconds();
 }
Ejemplo n.º 10
0
 public void ResetAnimation()
 {
     timeOfCreation = StaticTimer.GetElapsedMilliseconds();
 }
Ejemplo n.º 11
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());
 }