Пример #1
0
        public override void Update(GameTime gameTime)
        {
            int i = Player.Me.UnitArray.Length;

            // check for exit

            /*if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
             *  Game1.Game.Exit();
             * if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape))
             * {
             *  //Graphics.ToggleFullScreen();
             *  cleanup();
             *  returnControl("exit");
             *  return;
             * }*/

            //Cursor.Clip = new System.Drawing.Rectangle(winForm.Location, winForm.Size);
            Rts.gameTime = gameTime;

            if (!waitingForMessage)
            {
                GameClock += (float)gameTime.ElapsedGameTime.TotalSeconds * GameSpeed;
            }

            // count down
            if (doCountDown())
            {
                return;
            }

            // send time sync message if server
            checkToSync(gameTime);
            // just checkup if not server
            checkToCheckup(gameTime);

            // receive and process network messages
            receiveData(gameTime);

            // mute check
            checkForMute();

            // update mouse and keyboard state
            mouseState    = Mouse.GetState();
            keyboardState = Keyboard.GetState();

            // pause check

            /*if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.P))
             *  allowPause = true;
             * if (allowPause && Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.P))
             * {
             *  paused ^= true;
             *  allowPause = false;
             *  if (paused)
             *  {
             *      MediaPlayer.Volume /= 4;
             *      //GameTimer.Stop();
             *  }
             *  else
             *  {
             *      MediaPlayer.Volume *= 4;
             *      //GameTimer.Start();
             *  }
             * }*/

            // do cleanup of player unit/structure arrays
            Player.SetNullIDS();

            // pathfinding performance info
            if (Game1.DEBUG)
            {
                timeForPathFindingProfiling += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (timeForPathFindingProfiling >= 500)
                {
                    double pathFindingTime;
                    lock (Rts.pathFinder.TimeSpentPathFindingLock)
                    {
                        pathFindingTime = Rts.pathFinder.TimeSpentPathFinding.TotalMilliseconds;
                        Rts.pathFinder.TimeSpentPathFinding = TimeSpan.Zero;
                    }
                    pathFindingPercentage       = pathFindingTime / timeForPathFindingProfiling * 100;
                    timeForPathFindingProfiling = 0;

                    lock (PathFindRequest.HighPriorityPathFindRequests)
                    {
                        pathFindQueueSize = PathFindRequest.HighPriorityPathFindRequests.Count;
                    }
                }
            }

            //update fps
            fpsElapsedTime += gameTime.ElapsedGameTime;
            if (fpsElapsedTime > TimeSpan.FromSeconds(1))
            {
                //Game1.Game.Window.Title = "FPS: " + (frameCounter > 2 ? frameCounter.ToString() : "COOL");
                fpsMessage = "FPS: " + (frameCounter > 2 ? frameCounter.ToString() : "COOL");
                if (Game1.DEBUG)
                {
                    fpsMessage += " - Unit count: " + Unit.Units.Count;
                }
                fpsElapsedTime -= TimeSpan.FromSeconds(1);
                frameCounter    = 0;
            }

            // do nothing else if paused
            if (paused)
            {
                return;
            }

            // input processing
            checkForShift(gameTime);
            checkForCommands();
            SimpleButton.UpdateAll(mouseState, keyboardState);
            checkHotKeyGroups(gameTime);

            checkForLeftClick(gameTime);
            checkForRightClick();
            checkForTab();

            checkForMouseCameraScroll(gameTime);
            checkForCameraZoom(gameTime);
            checkForCameraRotate(gameTime);
            if (keyboardState.IsKeyDown(Keys.Space))
            {
                centerCameraOnSelectedUnits();
            }
            clampCameraToMap();

            updatePlacingStructure();
            updatePlacedStructures();

            if (!placingStructure)
            {
                SelectBox.Update(worldViewport, camera);
            }

            Shrinker.UpdateShrinkers(gameTime);

            // do nothing else if waiting for message
            if (waitingForMessage)
            {
                return;
            }

            doScheduledActions();

            checkForUnitStatusUpdates(gameTime);
            checkForStructureStatusUpdates(gameTime);

            //update stats
            updateStats(gameTime);

            map.UpdateBoundingBoxes();

            updateCogWheels(gameTime);

            RtsBullet.UpdateAll(gameTime);

            Resource.UpdateResources(gameTime);
            Structure.UpdateStructures(gameTime);
            Unit.UpdateUnits(gameTime, netPeer, connection);
            UnitAnimation.UpdateAll(gameTime);

            removeDeadUnitsFromSelections();

            applyVisibilityToMap();
        }