private static void Update()
    {
      _profiler.Start("Update");

      Physics();
      AI();
      AI();
      AI();

      // Simulate other work...
      Sleep(1);

      _profiler.Stop();
    }
Esempio n. 2
0
        // Updates the different sub-systems (input, physics, game logic, ...).
        protected override void Update(GameTime gameTime)
        {
            _deltaTime = gameTime.ElapsedGameTime;

            // Tell the profiler that a new frame has begun.
            _profiler.NewFrame();
            _profiler.Start("Update");

            // Update input manager. The input manager gets the device states and performs other work.
            // (Note: XNA requires that the input service is run on the main thread!)
            _profiler.Start("InputManager.Update             ");
            _inputManager.Update(_deltaTime);
            _profiler.Stop();

            // Update animations.
            // (The animation results are stored internally but not yet applied).
            _profiler.Start("AnimationManger.Update          ");
            _animationManager.Update(_deltaTime);
            _profiler.Stop();

            // Apply animations.
            // (The animation results are written to the objects and properties that
            // are being animated. ApplyAnimations() must be called at a point where
            // it is thread-safe to change the animated objects and properties.)
            _profiler.Start("AnimationManager.ApplyAnimations");
            _animationManager.ApplyAnimations();
            _profiler.Stop();

            // Run any task completion callbacks that have been scheduled.
            _profiler.Start("Parallel.RunCallbacks           ");
            Parallel.RunCallbacks();
            _profiler.Stop();


            // Update XNA GameComponents.
            _profiler.Start("base.Update                     ");
            base.Update(gameTime);
            _profiler.Stop();

            // Update UI manager. The UI manager updates all registered UIScreens.
            _profiler.Start("UIManager.Update                ");
            _uiManager.Update(_deltaTime);
            _profiler.Stop();

            // Update DigitalRune GameObjects.
            _profiler.Start("GameObjectManager.Update        ");
            _gameObjectManager.Update(_deltaTime);
            _profiler.Stop();

            _profiler.Stop();
        }
Esempio n. 3
0
        // Updates the different sub-systems (input, physics, game logic, ...).
        protected override void Update(GameTime gameTime)
        {
            _deltaTime = gameTime.ElapsedGameTime;

            // Tell the profiler that a new frame has begun.
            _profiler.NewFrame();
            _profiler.Start("Update");

            // Update input manager. The input manager gets the device states and performs other work.
            // (Note: XNA requires that the input service is run on the main thread!)
            _profiler.Start("InputManager.Update             ");
            _inputManager.Update(_deltaTime);
            _profiler.Stop();

            if (EnableParallelGameLoop)
            {
                // In a parallel game loop animation, physics and particles are started at
                // the end of the Update method. The services are now running in parallel.
                // --> Wait for services to finish.
                _updateAnimationTask.Wait();
                _updatePhysicsTask.Wait();
                _updateParticlesTask.Wait();

                // Now, nothing is running in parallel anymore and we can apply the animations.
                // (This means the animation values are written to the objects and properties
                // that are being animated.)
                _animationManager.ApplyAnimations();
            }
            else
            {
                // Update animation, physics, particles sequentially.

                // For debugging we can pause the physics and particle simulations with <P>,
                // and execute single simulation steps with <T>.
                if (_inputManager.IsPressed(Keys.P, true))
                {
                    _isSimulationPaused = !_isSimulationPaused;
                }

                if (!_isSimulationPaused || _inputManager.IsPressed(Keys.T, true))
                {
                    // Update physics simulation.
                    _profiler.Start("Simulation.Update               ");
                    _simulation.Update(_deltaTime);
                    _profiler.Stop();

                    // Update particles.
                    _profiler.Start("ParticleSystemManager.Update    ");
                    _particleSystemManager.Update(_deltaTime);
                    _profiler.Stop();
                }

                // Update animations.
                // (The animation results are stored internally but not yet applied).
                _profiler.Start("AnimationManger.Update          ");
                _animationManager.Update(_deltaTime);
                _profiler.Stop();

                // Apply animations.
                // (The animation results are written to the objects and properties that
                // are being animated. ApplyAnimations() must be called at a point where
                // it is thread-safe to change the animated objects and properties.)
                _profiler.Start("AnimationManager.ApplyAnimations");
                _animationManager.ApplyAnimations();
                _profiler.Stop();
            }

            // Run any task completion callbacks that have been scheduled.
            _profiler.Start("Parallel.RunCallbacks           ");
            Parallel.RunCallbacks();
            _profiler.Stop();

            // When the menu is visible, update SampleFramework before the game logic.
            if (_sampleFramework.IsMenuVisible)
            {
                _sampleFramework.Update();
            }

            // Update XNA GameComponents.
            _profiler.Start("base.Update                     ");
            base.Update(gameTime);
            _profiler.Stop();

            // Update UI manager. The UI manager updates all registered UIScreens.
            _profiler.Start("UIManager.Update                ");
            _uiManager.Update(_deltaTime);
            _profiler.Stop();

            // Update DigitalRune GameObjects.
            _profiler.Start("GameObjectManager.Update        ");
            _gameObjectManager.Update(_deltaTime);
            _profiler.Stop();

            // When the menu is hidden, update SampleFramework after the game logic.
            if (!_sampleFramework.IsMenuVisible)
            {
                _sampleFramework.Update();
            }

            if (EnableParallelGameLoop)
            {
                // Start animation, physics and particle simulation. They will be executed
                // parallel to the graphics rendering in Draw().
                _updateAnimationTask = Parallel.Start(_updateAnimation);
                _updatePhysicsTask   = Parallel.Start(_updatePhysics);
                _updateParticlesTask = Parallel.Start(_updateParticles);
            }

            _profiler.Stop();
        }