Пример #1
0
        } // BeginRun

        #endregion
        
        #region Update

        /// <summary>
        /// Called when the game has determined that game logic needs to be processed.
        /// </summary>
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (ResetDevice)
            {
                GraphicsDeviceManager.ApplyChanges();
                ResetDevice = false;
            }

            if (UseGamerServices)
                GamerServicesDispatcher.Update();

            if (ShowExceptionsWithGuide) // If we want to show exception in the Guide.
            {
                // If no exception was raised.
                if (exception == null)
                {
                    try
                    {
                        GameLoop.Update(gameTime);
                    }
                    catch (Exception e)
                    {
                        Time.PauseGame();
                        exception = e;
                    }
                }
            }
            else // If not then the StarEngine method will managed them.
                GameLoop.Update(gameTime);
        } // Update
Пример #2
0
        void UpdateNetworkSession(GameTime gameTime)
        {
            GamerServicesDispatcher.Update();

            // TODO: Work out how to do this right...
            BroadcastLocalShips();

            networkSession.Update();

            if (networkSession == null)
            {
                // If here, then network session has ended.
                //Go back to join/new session menu
                //mainGame.setGameState(MainGame.GameState.Menu);
                return;
            }

            foreach (LocalNetworkGamer gamer in networkSession.LocalGamers)
            {
                ReadIncomingPackets(gamer);
            }
        }
Пример #3
0
        /// <summary>
        /// Updates the object and its contained resources.
        /// </summary>
        /// <param name="gameTime"/>
        public override void Update(GameTime gameTime)
        {
            GamerServicesDispatcher.Update();

            base.Update(gameTime);
        }
Пример #4
0
 /// <summary>
 /// Helper method to call <see cref="GamerServicesDispatcher.Update"/> every frame.
 /// </summary>
 /// <param name="sender">object that invoked the event</param>
 /// <param name="e">per-frame specfic arguments</param>
 private void Update(object sender, FrameEventArgs e)
 {
     GamerServicesDispatcher.Update();
 }
Пример #5
0
        /// <summary>
        /// Update
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            // Process different phases.
            switch (phase)
            {
            case ConnectionPahse.EnsureSignedIn:
                GamerServicesDispatcher.Update();
                break;

            case ConnectionPahse.FindSessions:
                GamerServicesDispatcher.Update();
                if (asyncResult.IsCompleted)
                {
                    AvailableNetworkSessionCollection sessions =
                        NetworkSession.EndFind(asyncResult);

                    if (sessions.Count > 0)
                    {
                        asyncResult = NetworkSession.BeginJoin(sessions[0],
                                                               null, null);
                        commandHost.EchoError("Connecting to the host...");
                        phase = ConnectionPahse.Joining;
                    }
                    else
                    {
                        commandHost.EchoError("Couldn't find a session.");
                        phase = ConnectionPahse.None;
                    }
                }
                break;

            case ConnectionPahse.Joining:
                GamerServicesDispatcher.Update();
                if (asyncResult.IsCompleted)
                {
                    NetworkSession = NetworkSession.EndJoin(asyncResult);
                    NetworkSession.SessionEnded +=
                        new EventHandler <NetworkSessionEndedEventArgs>(
                            NetworkSession_SessionEnded);

                    OwnsNetworkSession = true;
                    commandHost.EchoError("Connected to the host.");
                    phase       = ConnectionPahse.None;
                    asyncResult = null;

                    ConnectedToRemote();
                }
                break;
            }

            // Update Network session.
            if (OwnsNetworkSession)
            {
                GamerServicesDispatcher.Update();
                NetworkSession.Update();

                if (NetworkSession != null)
                {
                    // Process received packets.
                    foreach (LocalNetworkGamer gamer in NetworkSession.LocalGamers)
                    {
                        while (gamer.IsDataAvailable)
                        {
                            NetworkGamer sender;
                            gamer.ReceiveData(packetReader, out sender);
                            if (!sender.IsLocal)
                            {
                                ProcessRecievedPacket(packetReader.ReadString());
                            }
                        }
                    }
                }
            }

            base.Update(gameTime);
        }