Update() public method

public Update ( ) : void
return void
Beispiel #1
0
 public override void Update(Delta delta)
 {
     if (currentStatusEffectPartyMemberIndex < currentStatusEffectParty.Count)
     {
         if (currentStatusEffectParty[currentStatusEffectPartyMemberIndex].Alive)
         {
             PushState(new HandleStatusEffects(Battle, StatusEffectEvent.EndTurn, partyMember: currentStatusEffectParty[currentStatusEffectPartyMemberIndex]));
         }
         else
         {
             ++currentStatusEffectPartyMemberIndex;
         }
     }
     else if (currentStatusEffectParty == Battle.PlayerParty)
     {
         currentStatusEffectParty            = Battle.EnemyParty;
         currentStatusEffectPartyMemberIndex = 0;
     }
     else if (clockTime < clockHourTransistionTimeInSeconds)
     {
         clockTime += delta.Time;
         Clock.Update(delta.Time / clockHourTransistionTimeInSeconds);
     }
     else
     {
         Finish();
     }
 }
Beispiel #2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            Clock.Update(gameTime);
            ParticleEngine.Update(Clock);
        }
Beispiel #3
0
 void Update()
 {
     accumulator += Time.deltaTime;
     if (accumulator > updateFrequency)
     {
         accumulator -= updateFrequency;
         myThrottledClock.Update(updateFrequency);
     }
 }
 public void UpdateTree(float dt)
 {
     accumulator += dt;
     if (accumulator > updateFrequency)
     {
         accumulator -= updateFrequency;
         myThrottledClock.Update(updateFrequency);
     }
 }
Beispiel #5
0
        public static void Update(float delta)
        {
            internalClock.Update(delta);
            floatingTextList.ForEach(t => t.position.Y--);

            foreach (var item in floatingTextList.Where(e => e.finalTimestamp < internalClock.Value).ToList())
            {
                floatingTextList.Remove(item);
            }
        }
        public void Update()
        {
            clock.Update();

            // update each Pedestrian
            for (int i = 0; i < crowd.Count; i++)
            {
                crowd[i].Update(clock.TotalSimulationTime, clock.ElapsedSimulationTime);
            }
        }
Beispiel #7
0
        public override void Update(GameTime gameTime)
        {
            timer.Update(gameTime);
            pacman.Update(gameTime);
            ghost.Update(gameTime);

            // Move on to the actual game.
            if ((pacman.IsComplete() && ghost.IsComplete()) ||
                (Keyboard.GetState().IsKeyDown(Keys.Space) && timer.ElapsedTime >= wait))
            {
                stateManager.Pop();
                stateManager.Push(new PlayState(game, stateManager));
            }
        }
        public MainWindowViewModel()
        {
            Debtors = new ObservableCollection <Debtor>()
            {
                new Debtor("Annie", new DebtEntry(DateTime.Now, 100)),
                new Debtor("Charles", new DebtEntry(DateTime.Now, 300)),
                new Debtor("Johnny", new DebtEntry(DateTime.Now, 50)),
            };


            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += new EventHandler((object sender, EventArgs e) => Clock.Update());
            timer.Start();
        }
Beispiel #9
0
        public void HandleTouches(NSSet touches)
        {
            Clock.Update(true);

            if (touches.Count == 1)
            {
                handleUITouch((UITouch)touches.AnyObject);
            }
            else
            {
                foreach (UITouch u in touches.ToArray <UITouch>())
                {
                    handleUITouch(u);
                }
            }
        }
Beispiel #10
0
        public async Task AddClockAfter(
            Clock previousClock,
            StartClockMessage newClockMessage = null)
        {
            _log.LogInformation("-> SignalRHost.AddClockAfter");

            if (previousClock != null)
            {
                var index = CurrentSession.Clocks.IndexOf(previousClock);

                if (index > -1)
                {
                    var newClock = new Clock();

                    if (newClockMessage != null)
                    {
                        newClock.Update(newClockMessage, true);
                        newClock.CurrentLabel = newClockMessage.Label;
                    }
                    else
                    {
                        newClock.Message.Position = index + 1;
                    }

                    newClock.SelectionChanged += ClockSelectionChanged;
                    CurrentSession.Clocks.Insert(index + 1, newClock);

                    if (newClockMessage == null)
                    {
                        _log.LogTrace("Updating other hosts");
                        await UpdateRemoteHosts(
                            UpdateAction.AddClock,
                            null,
                            newClock.Message,
                            previousClock.Message.ClockId);

                        await _session.Save(CurrentSession, SessionKey, _log);
                    }
                }

                for (var clockIndex = 0; clockIndex > CurrentSession.Clocks.Count; clockIndex++)
                {
                    CurrentSession.Clocks[clockIndex].Message.Position = clockIndex;
                }
            }
        }
Beispiel #11
0
    void Update()
    {
        if (Time.time > lastDrawnTime + 1f)
        {
            int[] newNumbers = new int[8];
            var   hours      = DateTime.Now.ToString("HH");
            var   minutes    = DateTime.Now.ToString("mm");
            var   seconds    = DateTime.Now.ToString("ss");

            newNumbers[0] = int.Parse(hours.Substring(0, 1));
            newNumbers[1] = int.Parse(hours.Substring(1, 1));
            newNumbers[2] = -1;             //colon

            newNumbers[3] = int.Parse(minutes.Substring(0, 1));
            newNumbers[4] = int.Parse(minutes.Substring(1, 1));
            newNumbers[5] = -1;             //colon

            newNumbers[6] = int.Parse(seconds.Substring(0, 1));
            newNumbers[7] = int.Parse(seconds.Substring(1, 1));


            //debug
            //if (debug == 0)
            //	debug = 1;
            //else
            //	debug = 0;
            //newNumbers[0] = 1;
            //newNumbers[1] = 6;
            //newNumbers[2] = -1;
            //newNumbers[3] = 2;
            //newNumbers[4] = 0;
            //newNumbers[5] = -1;
            //newNumbers[6] = 0;
            //newNumbers[7] = debug;



            clock.DrawTime(newNumbers);
            lastDrawnTime = Time.time;
        }

        clock.Update();         //updates clock animation
    }
Beispiel #12
0
    public void Update()
    {
        foreach (HomeObject dynamic_barn_object in m_DynamicBarnObjects)
        {
            dynamic_barn_object.Update();
        }

        foreach (NannyModel nanny in m_Nannies)
        {
            nanny.Update();
        }

        m_BarnClock.Update();

        time_since_view_clock_update += GameManager.m_Instance.m_GameDeltaTime;

        if (time_since_view_clock_update > 60f)
        {
            time_since_view_clock_update = 0;
            barn_date = m_BarnClock.CurrentDate;
            barn_time = m_BarnClock.CurrentTime;
        }
    }
Beispiel #13
0
        public async Task <bool> Duplicate(string sessionId, ILogger log)
        {
            log.LogInformation("-> Duplicate");

            var modelSession = CloudSessions
                               .FirstOrDefault(s => s.SessionId == sessionId);

            if (modelSession == null)
            {
                throw new ArgumentException($"Invalid sessionId {sessionId}");
            }

            var newSession = new SessionBase
            {
                BranchId    = modelSession.BranchId,
                Clocks      = new List <Clock>(),
                SessionId   = Guid.NewGuid().ToString(),
                SessionName = $"{modelSession.SessionName} (copy)"
            };

            foreach (var clock in modelSession.Clocks)
            {
                var duplicatedClock = new Clock();
                duplicatedClock.Update(clock.Message, false);
                duplicatedClock.CurrentLabel = clock.Message.Label;
                newSession.Clocks.Add(duplicatedClock);
            }

            var success = await Save(newSession, SignalRHost.HostSessionKey, log);

            if (success)
            {
                CloudSessions.Add(newSession);
            }

            return(success);
        }
 void Timer_Tick(object sender, EventArgs e)
 {
     clock.Update();
 }
Beispiel #15
0
        // Update is called once per frame
        void Update()
        {
            m_time = TimeUtils.Timestamp();

            if (m_timeRuns)
            {
                // Detect click on ground
                if (Input.GetMouseButtonDown(0))
                {
                    if (EventSystem.current.IsPointerOverGameObject())
                    {
                        return;
                    }
                    RaycastHit hit;

                    if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
                    {
                        if (hit.transform.gameObject.tag == "Ground")
                        {
                            SetPlayerAction(hit.point);
                        }
                    }
                }
            }

            m_idleWorksClock.Update();

            //ductTapeStock.text = "" + _gameState.ductTape.amount.ToString("0.00");
            //scrapStock.text = "" + _gameState.scrap.amount.ToString("0");

            m_playerAnimator.SetFloat("speed", (m_player.position - m_lastPlayerPosition).magnitude / ((float)Time.deltaTime));
            m_lastPlayerPosition = m_player.position;

            if (m_playerWalking && m_playerAgent.remainingDistance < 0.1f)
            {
                m_playerWalking = false;
                AudioManager.Instance.StopSound("characterWalking");
            }

            if (OnboardingStep < m_onboardingFirstSection)
            {
                if ((m_player.position - m_marsBase.position).magnitude < 2.0f)
                {
                    ActivateBase();
                }
            }
            else
            {
                Vector3 diffWithBase = (m_marsBase.position - m_player.position);
                if (CameraController.Instance.mode == CameraMode.EXPLORE && (Mathf.Abs(diffWithBase.x) < m_maxDistanceToBase.x || Mathf.Abs(diffWithBase.z) < m_maxDistanceToBase.z))
                {
                    ReachBase();
                }
                if (CameraController.Instance.mode == CameraMode.BASE && (Mathf.Abs(diffWithBase.x) > m_maxDistanceToBase.x || Mathf.Abs(diffWithBase.z) > m_maxDistanceToBase.z))
                {
                    LeaveBase();
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (m_pauseMenu)
                {
                    GetComponent <Scene>().QuitGame();
                }
                else
                {
                    PauseMenu();
                }
            }
        }
        /// <summary>
        /// Starts the block rendering worker.
        /// </summary>
        private void StartBlockRenderingWorker()
        {
            if (BlockRenderingWorkerExit != null)
            {
                return;
            }

            BlockRenderingWorkerExit = WaitEventFactory.Create(isCompleted: false, useSlim: true);

            // Holds the main media type
            var main = Container.Components.Main.MediaType;

            // Holds all components
            var all = Renderers.Keys.ToArray();

            // Holds a snapshot of the current block to render
            var currentBlock = new MediaTypeDictionary <MediaBlock>();

            // Keeps track of how many blocks were rendered in the cycle.
            var renderedBlockCount = new MediaTypeDictionary <int>();

            // reset render times for all components
            foreach (var t in all)
            {
                InvalidateRenderer(t);
            }

            // Ensure packet reading is running
            PacketReadingCycle.Wait();

            // wait for main component blocks or EOF or cancellation pending
            while (CanReadMoreFramesOf(main) && Blocks[main].Count <= 0)
            {
                FrameDecodingCycle.Wait();
            }

            // Set the initial clock position
            Clock.Update(Blocks[main].RangeStartTime);
            var wallClock = WallClock;

            // Wait for renderers to be ready
            foreach (var t in all)
            {
                Renderers[t]?.WaitForReadyState();
            }

            // The Render timer is responsible for sending frames to renders
            BlockRenderingWorker = new Timer((s) =>
            {
                #region Detect Exit/Skip Conditions

                if (Commands.IsStopWorkersPending || BlockRenderingWorkerExit.IsCompleted || IsDisposed)
                {
                    BlockRenderingWorkerExit?.Complete();
                    return;
                }

                // Skip the cycle if it's already running
                if (BlockRenderingCycle.IsInProgress)
                {
                    Log(MediaLogMessageType.Trace, $"SKIP: {nameof(BlockRenderingWorker)} alredy in a cycle. {WallClock}");
                    return;
                }

                #endregion

                #region Run the Rendering Cycle

                try
                {
                    #region 1. Control and Capture

                    // Wait for the seek op to finish before we capture blocks
                    Commands.WaitForActiveSeekCommand();

                    // Signal the start of a block rendering cycle
                    BlockRenderingCycle.Begin();

                    // Skip the cycle if we are running a priority command
                    if (Commands.IsExecutingDirectCommand)
                    {
                        return;
                    }

                    // Updatete Status Properties
                    main = Container.Components.Main.MediaType;
                    all  = Renderers.Keys.ToArray();

                    // Reset the rendered count to 0
                    foreach (var t in all)
                    {
                        renderedBlockCount[t] = 0;
                    }

                    #endregion

                    #region 2. Handle Block Rendering

                    // capture the wall clock for this cycle
                    wallClock = WallClock;

                    // Capture the blocks to render
                    foreach (var t in all)
                    {
                        if (t == MediaType.Subtitle && PreloadedSubtitles != null)
                        {
                            // Get the preloaded, cached subtitle block
                            currentBlock[t] = PreloadedSubtitles[wallClock];
                        }
                        else
                        {
                            // Get the regular audio, video, or sub block
                            currentBlock[t] = Blocks[t][wallClock];
                        }
                    }

                    // Render each of the Media Types if it is time to do so.
                    foreach (var t in all)
                    {
                        // Skip rendering for nulls
                        if (currentBlock[t] == null || currentBlock[t].IsDisposed)
                        {
                            continue;
                        }

                        // Render by forced signal (TimeSpan.MinValue) or because simply it is time to do so
                        if (LastRenderTime[t] == TimeSpan.MinValue || currentBlock[t].StartTime != LastRenderTime[t])
                        {
                            renderedBlockCount[t] += SendBlockToRenderer(currentBlock[t], wallClock, main);
                        }
                    }

                    #endregion

                    #region 6. Finalize the Rendering Cycle

                    // Call the update method on all renderers so they receive what the new wall clock is.
                    foreach (var t in all)
                    {
                        Renderers[t]?.Update(wallClock);
                    }

                    #endregion
                }
                catch { throw; }
                finally
                {
                    // Always exit notifying the cycle is done.
                    BlockRenderingCycle.Complete();

                    // Notify position changes continuously on the state object
                    // only if we are not currently seeking
                    if (State.IsSeeking == false)
                    {
                        State.UpdatePosition(wallClock);
                    }
                }

                #endregion
            },
                                             this, // the state argument passed on to the ticker
                                             0,
                                             Convert.ToInt32(Constants.Interval.HighPriority.TotalMilliseconds));
        }
Beispiel #17
0
        public override void Update(GameTime gameTime)
        {
            var state = Keyboard.GetState();

            if (state.IsKeyDown(Keys.Escape))
            {
                back.Play();
                stateManager.Pop();
            }
            else if ((state.IsKeyDown(Keys.Right) || state.IsKeyDown(Keys.Space)) && timer.ElapsedTime >= wait)
            {
                timer.Reset();
                if (selection == OptionSelection.Fullscreen)
                {
                    enter.Play();
                    game.FlipWindowMode();
                }
                else if (selection == OptionSelection.Volume)
                {
                    enter.Play();
                }
            }
            else if (state.IsKeyDown(Keys.Left) && timer.ElapsedTime >= wait)
            {
                timer.Reset();
                if (selection == OptionSelection.Fullscreen)
                {
                    enter.Play();
                    game.FlipWindowMode();
                }
                else if (selection == OptionSelection.Volume)
                {
                    enter.Play();
                }
            }

            if (state.IsKeyDown(Keys.Down) && timer.ElapsedTime >= wait)
            {
                select.Play();
                timer.Reset();
                if (selection == OptionSelection.Controls)
                {
                    dotLocation = new Point(dotLocation.X, dotLocation.Y - 30);
                    selection   = selection - 2;
                }
                else
                {
                    dotLocation = new Point(dotLocation.X, dotLocation.Y + 15);
                    selection   = selection + 1;
                }
            }
            if (state.IsKeyDown(Keys.Up) && timer.ElapsedTime >= wait)
            {
                select.Play();
                timer.Reset();
                if (selection == OptionSelection.Fullscreen)
                {
                    dotLocation = new Point(dotLocation.X, dotLocation.Y + 30);
                    selection   = selection + 2;
                }
                else
                {
                    dotLocation = new Point(dotLocation.X, dotLocation.Y - 15);
                    selection   = selection - 1;
                }
            }
            dot = new Rectangle(dotLocation, dot.Size);

            // Update timer.
            timer.Update(gameTime);
        }
Beispiel #18
0
        public override void Update(GameTime gameTime)
        {
            // Play audio
            if (!audioPlaying)
            {
                introInstance.Play();
                MediaPlayer.Play(radioStatic);
                MediaPlayer.IsRepeating = true;
                audioPlaying            = true;
            }

            // Handle input.
            var state = Keyboard.GetState();

            if (state.IsKeyDown(Keys.Enter) || (state.IsKeyDown(Keys.Space) && timer.ElapsedTime >= wait))
            {
                if (selection == Selection.Play)
                {
                    introInstance.Pause();
                    MediaPlayer.Stop();
                    audioPlaying = false;
                    sfxPlay.Play();
                    stateManager.Push(new IntroState(game, stateManager));
                }
                else if (selection == Selection.Options)
                {
                    sfxEnter.Play();
                    stateManager.Push(new OptionState(game, stateManager));
                }
                else if (selection == Selection.Scoreboard)
                {
                    sfxEnter.Play();
                    stateManager.Push(new ScoreState(game, stateManager));
                }
                else if (selection == Selection.Quit)
                {
                    game.Exit();
                }
            }

            if (state.IsKeyDown(Keys.Down) && timer.ElapsedTime >= wait)
            {
                sfxSelect.Play();
                timer.Reset();
                if (selection == Selection.Quit)
                {
                    arrowLocation = new Vector2(arrowLocation.X, arrowLocation.Y - 33);
                    selection     = selection - 3;
                }
                else
                {
                    arrowLocation = new Vector2(arrowLocation.X, arrowLocation.Y + 11);
                    selection     = selection + 1;
                }
            }
            if (state.IsKeyDown(Keys.Up) && timer.ElapsedTime >= wait)
            {
                sfxSelect.Play();
                timer.Reset();
                if (selection == Selection.Play)
                {
                    arrowLocation = new Vector2(arrowLocation.X, arrowLocation.Y + 33);
                    selection     = selection + 3;
                }
                else
                {
                    arrowLocation = new Vector2(arrowLocation.X, arrowLocation.Y - 11);
                    selection     = selection - 1;
                }
            }

            // Update timer.
            timer.Update(gameTime);
        }
Beispiel #19
0
        /// <summary>
        /// Starts the block rendering worker.
        /// </summary>
        private void StartBlockRenderingWorker()
        {
            if (HasBlockRenderingWorkerExited != null)
            {
                return;
            }

            HasBlockRenderingWorkerExited = new ManualResetEvent(false);

            // Synchronized access to parts of the run cycle
            var isRunningRenderingCycle = false;

            // Holds the main media type
            var main = Container.Components.Main.MediaType;

            // Holds the auxiliary media types
            var auxs = Container.Components.MediaTypes.ExcludeMediaType(main);

            // Holds all components
            var all = Container.Components.MediaTypes.DeepCopy();

            // Holds a snapshot of the current block to render
            var currentBlock = new MediaTypeDictionary <MediaBlock>();

            // Keeps track of how many blocks were rendered in the cycle.
            var renderedBlockCount = new MediaTypeDictionary <int>();

            // reset render times for all components
            foreach (var t in all)
            {
                LastRenderTime[t] = TimeSpan.MinValue;
            }

            // Ensure packet reading is running
            PacketReadingCycle.WaitOne();

            // wait for main component blocks or EOF or cancellation pending
            while (CanReadMoreFramesOf(main) && Blocks[main].Count <= 0)
            {
                FrameDecodingCycle.WaitOne();
            }

            // Set the initial clock position
            // TODO: maybe update media start time offset to this Minimum, initial Start Time intead of relying on contained meta?
            Clock.Update(Blocks[main].RangeStartTime); // .GetMinStartTime()
            var wallClock = WallClock;

            // Wait for renderers to be ready
            foreach (var t in all)
            {
                Renderers[t]?.WaitForReadyState();
            }

            // The Render timer is responsible for sending frames to renders
            BlockRenderingWorker = new Timer((s) =>
            {
                #region Detect a Timer Stop

                if (IsTaskCancellationPending || HasBlockRenderingWorkerExited.IsSet() || IsDisposed)
                {
                    HasBlockRenderingWorkerExited.Set();
                    return;
                }

                #endregion

                #region Run the Rendering Cycle

                // Updatete Status  Properties
                State.UpdateBufferingProperties();

                // Don't run the cycle if it's already running
                if (isRunningRenderingCycle)
                {
                    // TODO: Maybe Log a frame skip here?
                    return;
                }

                try
                {
                    #region 1. Control and Capture

                    // Flag the current rendering cycle
                    isRunningRenderingCycle = true;

                    // Reset the rendered count to 0
                    foreach (var t in all)
                    {
                        renderedBlockCount[t] = 0;
                    }

                    // Capture current clock position for the rest of this cycle
                    BlockRenderingCycle.Reset();

                    #endregion

                    #region 2. Handle Block Rendering

                    // Wait for the seek op to finish before we capture blocks
                    if (HasDecoderSeeked)
                    {
                        SeekingDone.WaitOne();
                    }

                    // capture the wall clock for this cycle
                    wallClock = WallClock;

                    // Capture the blocks to render
                    foreach (var t in all)
                    {
                        currentBlock[t] = Blocks[t][wallClock];
                    }

                    // Render each of the Media Types if it is time to do so.
                    foreach (var t in all)
                    {
                        // Skip rendering for nulls
                        if (currentBlock[t] == null)
                        {
                            continue;
                        }

                        // Render by forced signal (TimeSpan.MinValue)
                        if (LastRenderTime[t] == TimeSpan.MinValue)
                        {
                            renderedBlockCount[t] += SendBlockToRenderer(currentBlock[t], wallClock);
                            continue;
                        }

                        // Render because we simply have not rendered
                        if (currentBlock[t].StartTime != LastRenderTime[t])
                        {
                            renderedBlockCount[t] += SendBlockToRenderer(currentBlock[t], wallClock);
                            continue;
                        }
                    }

                    #endregion

                    #region 6. Finalize the Rendering Cycle

                    // Call the update method on all renderers so they receive what the new wall clock is.
                    foreach (var t in all)
                    {
                        Renderers[t]?.Update(wallClock);
                    }

                    #endregion
                }
                catch (ThreadAbortException) { /* swallow */ }
                catch { if (!IsDisposed)
                        {
                            throw;
                        }
                }
                finally
                {
                    // Always exit notifying the cycle is done.
                    BlockRenderingCycle.Set();
                    isRunningRenderingCycle = false;
                }

                #endregion
            },
                                             this, // the state argument passed on to the ticker
                                             0,
                                             (int)Constants.Interval.HighPriority.TotalMilliseconds);
        }
 void Update()
 {
     _clock?.Update(Time.deltaTime);
 }
 public void Update(float dt)
 {
     clock.Update(Time.deltaTime);
 }
Beispiel #22
0
 void TimerOnTick(object sender, EventArgs eventArgs)
 {
     clock.Update();
 }
        /// <summary>
        /// Continually decodes the available packet buffer to have as
        /// many frames as possible in each frame queue and
        /// up to the MaxFrames on each component
        /// </summary>
        internal void RunFrameDecodingWorker()
        {
            #region Worker State Setup

            // The delay provider prevents 100% core usage
            var delay = new DelayProvider();

            // State variables
            var decodedFrameCount = 0;
            var wallClock         = TimeSpan.Zero;
            var rangePercent      = 0d;
            var isInRange         = false;

            // Holds the main media type
            var main = Container.Components.Main.MediaType;

            // Holds the auxiliary media types
            var auxs = Container.Components.MediaTypes.Except(main);

            // State properties
            var isBuffering = false;
            var resumeClock = false;

            MediaComponent   comp   = null;
            MediaBlockBuffer blocks = null;

            #endregion

            #region Worker Loop

            try
            {
                while (Commands.IsStopWorkersPending == false)
                {
                    #region 1. Setup the Decoding Cycle

                    // Determine what to do on a priority command
                    if (Commands.IsExecutingDirectCommand)
                    {
                        if (Commands.IsClosing)
                        {
                            break;
                        }
                        if (Commands.IsChanging)
                        {
                            Commands.WaitForDirectCommand();
                        }
                    }

                    // Update state properties -- this must be after processing commanmds as
                    // a direct command might have changed the components
                    main = Container.Components.Main.MediaType;
                    auxs = Container.Components.MediaTypes.Except(main);

                    // Execute the following command at the beginning of the cycle
                    Commands.ExecuteNextQueuedCommand();

                    // Signal a Seek starting operation
                    FrameDecodingCycle.Begin();

                    // Set initial state
                    wallClock         = WallClock;
                    decodedFrameCount = 0;

                    #endregion

                    if (State.HasMediaEnded == false)
                    {
                        #region 2. Main Component Decoding

                        // Capture component and blocks for easier readability
                        // comp is current component, blocks is the block collection for the component
                        comp   = Container.Components[main];
                        blocks = Blocks[main];

                        // Detect if we are in range for the main component
                        isInRange = blocks.IsInRange(wallClock);

                        if (isInRange == false)
                        {
                            // Signal the start of a sync-buffering scenario
                            isBuffering = true;
                            State.SignalBufferingStarted();
                            resumeClock = Clock.IsRunning;
                            Clock.Pause();
                            Log(MediaLogMessageType.Debug, $"SYNC-BUFFER: Started.");

                            // Read some frames and try to get a valid range
                            do
                            {
                                // Try to get more packets by waiting for read cycles.
                                WaitForPackets(comp, 1);

                                // Decode some frames and check if we are in reange now
                                if (AddNextBlock(main) == false)
                                {
                                    break;
                                }

                                decodedFrameCount += 1;
                                isInRange          = blocks.IsInRange(wallClock);

                                // Break the cycle if we are in range
                                if (isInRange || CanReadMorePackets == false || ShouldReadMorePackets == false)
                                {
                                    break;
                                }
                            }while (blocks.IsFull == false);

                            // Unfortunately at this point we will need to adjust the clock after creating the frames.
                            // to ensure tha mian component is within the clock range if the decoded
                            // frames are not with range. This is normal while buffering though.
                            if (isInRange == false)
                            {
                                // Update the wall clock to the most appropriate available block.
                                if (blocks.Count > 0)
                                {
                                    wallClock = blocks[wallClock].StartTime;
                                }
                                else
                                {
                                    resumeClock = false; // Hard stop the clock.
                                }
                                // Update the clock to what the main component range mandates
                                Clock.Update(wallClock);

                                // Force renderer invalidation
                                InvalidateRenderer(main);

                                // Try to recover the regular loop
                                isInRange = true;
                            }
                        }

                        if (isInRange)
                        {
                            // Check if we need more blocks for the current components
                            rangePercent = blocks.GetRangePercent(wallClock);

                            // Read as much as we can for this cycle but always within range.
                            while (blocks.IsFull == false || (blocks.IsFull && rangePercent > 0.75d && rangePercent < 1d))
                            {
                                if (AddNextBlock(main) == false)
                                {
                                    break;
                                }

                                decodedFrameCount += 1;
                                rangePercent       = blocks.GetRangePercent(wallClock);
                                continue;
                            }
                        }

                        #endregion

                        #region 3. Auxiliary Component Decoding

                        foreach (var t in auxs)
                        {
                            if (State.IsSeeking)
                            {
                                continue;
                            }

                            // Capture the current block buffer and component
                            // for easier readability
                            comp      = Container.Components[t];
                            blocks    = Blocks[t];
                            isInRange = blocks.IsInRange(wallClock);

                            // wait for component to get there if we only have furutre blocks
                            // in auxiliary component.
                            if (blocks.Count > 0 && blocks.RangeStartTime > wallClock)
                            {
                                continue;
                            }

                            // We need the other components to catch up with the main
                            while (blocks.Count == 0 || blocks.RangeEndTime <= wallClock ||
                                   (Blocks[main].Count > 0 && blocks.RangeEndTime < Blocks[main].RangeEndTime))
                            {
                                // give up if we never received frames for the expected component
                                if (AddNextBlock(t) == false)
                                {
                                    break;
                                }
                            }

                            // Check if we are finally within range
                            isInRange = blocks.IsInRange(wallClock);

                            // Invalidate the renderer if we don't have the block.
                            if (isInRange == false)
                            {
                                InvalidateRenderer(t);
                            }

                            // Move to the next component if we don't meet a regular conditions
                            if (isInRange == false || isBuffering)
                            {
                                continue;
                            }

                            // Decode as much as we can off the packet buffer for this cycle.
                            rangePercent = blocks.GetRangePercent(wallClock);
                            while (blocks.IsFull == false || (blocks.IsFull && rangePercent > 0.75d && rangePercent < 1d))
                            {
                                if (AddNextBlock(t) == false)
                                {
                                    break;
                                }

                                rangePercent = blocks.GetRangePercent(wallClock);
                            }
                        }

                        #endregion
                    }

                    #region 4. Detect End of Media

                    // Detect end of block rendering
                    // TODO: Maybe this detection should be performed on the BlockRendering worker?
                    if (isBuffering == false &&
                        decodedFrameCount <= 0 &&
                        State.IsSeeking == false &&
                        CanReadMoreFramesOf(main) == false &&
                        Blocks[main].IndexOf(wallClock) == Blocks[main].Count - 1)
                    {
                        if (State.HasMediaEnded == false)
                        {
                            // Rendered all and nothing else to read
                            Clock.Pause();
                            wallClock = Blocks[main].RangeEndTime;
                            Clock.Update(wallClock);

                            if (State.NaturalDuration != null &&
                                State.NaturalDuration != TimeSpan.MinValue &&
                                State.NaturalDuration < wallClock)
                            {
                                Log(MediaLogMessageType.Warning,
                                    $"{nameof(State.HasMediaEnded)} conditions met at {wallClock.Format()} but " +
                                    $"{nameof(State.NaturalDuration)} reports {State.NaturalDuration.Value.Format()}");
                            }

                            State.UpdateMediaEnded(true);
                            State.UpdateMediaState(PlaybackStatus.Stop, wallClock);
                            SendOnMediaEnded();
                        }
                    }
                    else
                    {
                        State.UpdateMediaEnded(false);
                    }

                    #endregion

                    #region 6. Finish the Cycle

                    // complete buffering notifications
                    if (isBuffering)
                    {
                        // Always reset the buffering flag
                        isBuffering = false;

                        // Resume the clock if it was playing
                        if (resumeClock)
                        {
                            Clock.Play();
                        }

                        // log some message
                        Log(MediaLogMessageType.Debug, $"SYNC-BUFFER: Finished. Clock set to {wallClock.Format()}");
                    }

                    // If not already set, guess the 1-second buffer length
                    State.GuessBufferingProperties();

                    // Complete the frame decoding cycle
                    FrameDecodingCycle.Complete();

                    // Give it a break if there was nothing to decode.
                    // We probably need to wait for some more input
                    if (Commands.IsStopWorkersPending == false &&
                        decodedFrameCount <= 0 &&
                        Commands.HasQueuedCommands == false)
                    {
                        delay.WaitOne();
                    }

                    #endregion
                }
            }
            catch { throw; }
            finally
            {
                // Always exit notifying the cycle is done.
                FrameDecodingCycle.Complete();
                delay.Dispose();
            }

            #endregion
        }
Beispiel #24
0
 public void Update()
 {
     clock.Update();
 }
Beispiel #25
0
        public void Update(GameTime gameTime, Camera camera)
        {
            Clock.Update(gameTime);
            //list to separate the two types of sprites that need to be updated
            //need to do this in two steps to make sure they don't call update on an entity that was moving but then stop due to a collision
            ISet <IEntity> moving = entities.MovingEntities(camera.DrawRectangle);

            moving.UnionWith(enemies);//add any enemies that are out of the screen
            ISet <IEntity> animated = entities.EntitiesNeedingUpdated(camera.DrawRectangle);

            foreach (IEntity entity in moving)
            {
                Point     location    = new Point(entity.CollisionBox.X - entity.TrueWidth(), entity.CollisionBox.Y - entity.TrueHeight());
                Point     size        = new Point(3 * entity.TrueWidth(), 3 * entity.TrueHeight());
                Rectangle checkRegion = new Rectangle(location, size);//incase it somehow moved out of a square before removing itself.
                entities.Remove(entity, checkRegion);
                entity.Update(gameTime);
                //check for thecollision

                if (entity is Fireball || entity is AbstractItem || entity is BulletBill)
                {
                    if (entity.Position.X > camera.DrawRectangle.Right || entity.Position.X + entity.TrueWidth() < camera.DrawRectangle.Left)
                    {
                        entity.Collect = true;
                    }
                }
                else
                {
                    CollisionDetection.CheckAndFixEntityOutOfBounds(entity, entity.CollisionBox.Width, entity.CollisionBox.Height, (Rectangle)camera.Limits);
                }

                if (!entity.Collect)//check if the entity should be put back into the world
                {
                    entities.Insert(entity);
                    if (entity is AbstractEnemy)//try to add it to enemies, set will takes care of duplicates
                    {
                        enemies.Add((AbstractEnemy)entity);
                    }
                }
                if (entity.Collidable)
                {
                    CollisionDetection.SetOnGround(entity, entities);
                    if (entity is Goomba && !entity.OnGround)
                    {
                    }
                }
            }
            if (moving.Count > 0)
            {
                CollisionDetection.CollisionsCheckAndFix(moving, entities);
            }
            foreach (IEntity entity in animated)
            {
                entity.Update(gameTime);

                if (entity.Collect)//check if the entity should be removed from the world
                {
                    entities.Remove(entity);
                    if (entity is AbstractEnemy)
                    {
                        enemies.Remove((AbstractEnemy)entity);
                    }
                }
            }
            camera.LookAt(Stage.mario.Position);
            // Overlay.Update(gameTime);
            foreach (Layer layer in layers)
            {
                foreach (ISprite sprite in layer.Sprites)
                {
                    sprite.Update(gameTime);
                }
            }
            if (Clock.Time == 0)
            {
                OnRaiseLevelEvent(null);
            }
        }
Beispiel #26
0
 public void Update()
 {
     clock.Update(Time.deltaTime);
 }
Beispiel #27
0
 public void Update(float realSecondsRatio, float deltaTime)
 {
     previousTimeValue = timeObserver.Value;
     minuteTimer.Update(realSecondsRatio * deltaTime);
 }
Beispiel #28
0
 public override void Update(int t)
 {
     _clock.Update(t);
 }
        /// <summary>
        /// Continually decodes the available packet buffer to have as
        /// many frames as possible in each frame queue and
        /// up to the MaxFrames on each component
        /// </summary>
        internal void RunFrameDecodingWorker()
        {
            #region Worker State Setup

            // The delay provider prevents 100% core usage
            var delay = new DelayProvider();

            // State variables
            var decodedFrameCount = 0;
            var wallClock         = TimeSpan.Zero;
            var rangePercent      = 0d;
            var isInRange         = false;
            var playAfterSeek     = false;

            // Holds the main media type
            var main = Container.Components.Main.MediaType;

            // Holds the auxiliary media types
            var auxs = Container.Components.MediaTypes.ExcludeMediaType(main);

            // Holds all components
            var all = Container.Components.MediaTypes.DeepCopy();

            var isBuffering     = false;
            var resumeClock     = false;
            var hasPendingSeeks = false;

            MediaComponent   comp   = null;
            MediaBlockBuffer blocks = null;

            #endregion

            #region Worker Loop

            try
            {
                while (IsTaskCancellationPending == false)
                {
                    #region 1. Setup the Decoding Cycle

                    // Singal a Seek starting operation
                    hasPendingSeeks = Commands.PendingCountOf(MediaCommandType.Seek) > 0;
                    if (State.IsSeeking == false && hasPendingSeeks)
                    {
                        playAfterSeek   = State.IsPlaying;
                        State.IsSeeking = true;
                        SendOnSeekingStarted();
                    }

                    // Execute the following command at the beginning of the cycle
                    Commands.ProcessNext();

                    // Wait for a seek operation to complete (if any)
                    // and initiate a frame decoding cycle.
                    SeekingDone.Wait();

                    // Set initial state
                    wallClock         = WallClock;
                    decodedFrameCount = 0;

                    // Signal a Seek ending operation
                    // TOD: Maybe this should go on the block rendering worker?
                    hasPendingSeeks = Commands.PendingCountOf(MediaCommandType.Seek) > 0;
                    if (State.IsSeeking && hasPendingSeeks == false)
                    {
                        // Detect a end of seek cycle and update to the final position
                        wallClock = SnapToFramePosition(WallClock);
                        Clock.Update(wallClock);
                        State.UpdatePosition(wallClock);

                        // Call the seek method on all renderers
                        foreach (var kvp in Renderers)
                        {
                            LastRenderTime[kvp.Key] = TimeSpan.MinValue;
                            kvp.Value.Seek();
                        }

                        SendOnSeekingEnded();
                        State.IsSeeking = false;
                        if (playAfterSeek)
                        {
                            Clock.Play();
                            State.UpdateMediaState(PlaybackStatus.Play);
                        }
                        else
                        {
                            State.UpdateMediaState(PlaybackStatus.Pause);
                        }
                    }
                    else if (State.IsSeeking == false)
                    {
                        // Notify position changes
                        State.UpdatePosition(wallClock);
                    }

                    // Initiate the frame docding cycle
                    FrameDecodingCycle.Begin();

                    #endregion

                    #region 2. Main Component Decoding

                    // Capture component and blocks for easier readability
                    comp   = Container.Components[main];
                    blocks = Blocks[main];

                    // Handle the main component decoding; Start by checking we have some packets
                    while (comp.PacketBufferCount <= 0 && CanReadMorePackets && ShouldReadMorePackets)
                    {
                        PacketReadingCycle.Wait(Constants.Interval.LowPriority);
                    }

                    if (comp.PacketBufferCount > 0)
                    {
                        // Detect if we are in range for the main component
                        isInRange = blocks.IsInRange(wallClock);

                        if (isInRange == false)
                        {
                            // Signal the start of a sync-buffering scenario
                            HasDecoderSeeked = true;
                            isBuffering      = true;
                            resumeClock      = Clock.IsRunning;
                            Clock.Pause();
                            Log(MediaLogMessageType.Debug, $"SYNC-BUFFER: Started.");

                            // Read some frames and try to get a valid range
                            do
                            {
                                // Try to get more packets by waiting for read cycles.
                                if (CanReadMorePackets && comp.PacketBufferCount <= 0)
                                {
                                    PacketReadingCycle.Wait();
                                }

                                // Decode some frames and check if we are in reange now
                                decodedFrameCount += AddBlocks(main);
                                isInRange          = blocks.IsInRange(wallClock);

                                // Break the cycle if we are in range
                                if (isInRange || CanReadMorePackets == false)
                                {
                                    break;
                                }
                            }while (decodedFrameCount <= 0 && blocks.IsFull == false);

                            // Unfortunately at this point we will need to adjust the clock after creating the frames.
                            // to ensure tha mian component is within the clock range if the decoded
                            // frames are not with range. This is normal while buffering though.
                            if (isInRange == false)
                            {
                                // Update the wall clock to the most appropriate available block.
                                if (blocks.Count > 0)
                                {
                                    wallClock = blocks[wallClock].StartTime;
                                }
                                else
                                {
                                    resumeClock = false; // Hard stop the clock.
                                }
                                // Update the clock to what the main component range mandates
                                Clock.Update(wallClock);

                                // Call seek to invalidate renderer
                                LastRenderTime[main] = TimeSpan.MinValue;
                                Renderers[main].Seek();

                                // Try to recover the regular loop
                                isInRange = true;
                                while (CanReadMorePackets && comp.PacketBufferCount <= 0)
                                {
                                    PacketReadingCycle.Wait();
                                }
                            }
                        }

                        if (isInRange)
                        {
                            // Check if we need more blocks for the current components
                            rangePercent = blocks.GetRangePercent(wallClock);

                            // Read as much as we can for this cycle.
                            while (comp.PacketBufferCount > 0)
                            {
                                rangePercent = blocks.GetRangePercent(wallClock);

                                if (blocks.IsFull == false || (blocks.IsFull && rangePercent > 0.75d && rangePercent < 1d))
                                {
                                    decodedFrameCount += AddBlocks(main);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region 3. Auxiliary Component Decoding

                    foreach (var t in auxs)
                    {
                        if (State.IsSeeking)
                        {
                            continue;
                        }

                        // Capture the current block buffer and component
                        // for easier readability
                        comp      = Container.Components[t];
                        blocks    = Blocks[t];
                        isInRange = blocks.IsInRange(wallClock);

                        // Invalidate the renderer if we don't have the block.
                        if (isInRange == false)
                        {
                            LastRenderTime[t] = TimeSpan.MinValue;
                            Renderers[t].Seek();
                        }

                        // wait for component to get there if we only have furutre blocks
                        // in auxiliary component.
                        if (blocks.Count > 0 && blocks.RangeStartTime > wallClock)
                        {
                            continue;
                        }

                        // Try to catch up with the wall clock
                        while (blocks.Count == 0 || blocks.RangeEndTime <= wallClock)
                        {
                            // Wait for packets if we don't have enough packets
                            if (CanReadMorePackets && comp.PacketBufferCount <= 0)
                            {
                                PacketReadingCycle.Wait();
                            }

                            if (comp.PacketBufferCount <= 0)
                            {
                                break;
                            }
                            else
                            {
                                decodedFrameCount += AddBlocks(t);
                            }
                        }

                        isInRange = blocks.IsInRange(wallClock);

                        // Move to the next component if we don't meet a regular conditions
                        if (isInRange == false || isBuffering || comp.PacketBufferCount <= 0)
                        {
                            continue;
                        }

                        // Read as much as we can for this cycle.
                        while (comp.PacketBufferCount > 0)
                        {
                            rangePercent = blocks.GetRangePercent(wallClock);

                            if (blocks.IsFull == false || (blocks.IsFull && rangePercent > 0.75d && rangePercent < 1d))
                            {
                                decodedFrameCount += AddBlocks(t);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    #endregion

                    #region 4. Detect End of Media

                    // Detect end of block rendering
                    // TODO: Maybe this detection should be performed on the BlockRendering worker?
                    if (isBuffering == false &&
                        State.IsSeeking == false &&
                        CanReadMoreFramesOf(main) == false &&
                        Blocks[main].IndexOf(wallClock) == Blocks[main].Count - 1)
                    {
                        if (State.HasMediaEnded == false)
                        {
                            // Rendered all and nothing else to read
                            Clock.Pause();

                            if (State.NaturalDuration != null && State.NaturalDuration != TimeSpan.MinValue)
                            {
                                wallClock = State.NaturalDuration.Value;
                            }
                            else
                            {
                                wallClock = Blocks[main].RangeEndTime;
                            }

                            Clock.Update(wallClock);
                            State.HasMediaEnded = true;
                            State.UpdateMediaState(PlaybackStatus.Stop, wallClock);
                            SendOnMediaEnded();
                        }
                    }
                    else
                    {
                        State.HasMediaEnded = false;
                    }

                    #endregion

                    #region 6. Finish the Cycle

                    // complete buffering notifications
                    if (isBuffering)
                    {
                        // Reset the buffering flag
                        isBuffering = false;

                        // Resume the clock if it was playing
                        if (resumeClock)
                        {
                            Clock.Play();
                        }

                        // log some message
                        Log(
                            MediaLogMessageType.Debug,
                            $"SYNC-BUFFER: Finished. Clock set to {wallClock.Format()}");
                    }

                    // Complete the frame decoding cycle
                    FrameDecodingCycle.Complete();

                    // After a seek operation, always reset the has seeked flag.
                    HasDecoderSeeked = false;

                    // If not already set, guess the 1-second buffer length
                    State.GuessBufferingProperties();

                    // Give it a break if there was nothing to decode.
                    // We probably need to wait for some more input
                    if (decodedFrameCount <= 0 && Commands.PendingCount <= 0)
                    {
                        delay.WaitOne();
                    }

                    #endregion
                }
            }
            catch (ThreadAbortException) { /* swallow */ }
            catch { if (!IsDisposed)
                    {
                        throw;
                    }
            }
            finally
            {
                // Always exit notifying the cycle is done.
                FrameDecodingCycle.Complete();
                delay.Dispose();
            }

            #endregion
        }
Beispiel #30
0
 public virtual void Update(GameClock time)
 {
     Clock.Update(time);
 }