Example #1
0
        public void Update_ShouldUpdateDiagnosticsAfterUpdateOfAllSystemsAndAfterRecordingFrame()
        {
            // Arrange
            GameTime.FixedDeltaTime = TimeSpan.FromSeconds(0.1);
            var gameTime = new GameTime(TimeSpan.FromSeconds(0.15));

            _gameTimeProvider.GetGameTime().Returns(gameTime);

            var scene = TestSceneFactory.Create();

            _sceneManager.CurrentScene.Returns(scene);

            var gameLoop = GetGameLoop();

            // Act
            gameLoop.Update();

            // Assert
            Received.InOrder(() =>
            {
                _inputSystem.Received(1).ProcessInput(scene);
                _behaviorSystem.Received(1).ProcessBehaviorFixedUpdate(scene);
                _customSystem1.Received(1).ProcessFixedUpdate(scene);
                _customSystem2.Received(1).ProcessFixedUpdate(scene);
                _customSystem3.Received(1).ProcessFixedUpdate(scene);
                _physicsSystem.Received(1).ProcessPhysics(scene);
                _entityDestructionSystem.Received(1).DestroyEntitiesAfterFixedTimeStep(scene);
                _behaviorSystem.Received(1).ProcessBehaviorUpdate(scene, gameTime);
                _customSystem1.Received(1).ProcessUpdate(scene, gameTime);
                _customSystem2.Received(1).ProcessUpdate(scene, gameTime);
                _customSystem3.Received(1).ProcessUpdate(scene, gameTime);
                _physicsSystem.Received(1).PreparePhysicsDebugInformation();
                _audioSystem.Received(1).ProcessAudio(scene);
                _animationSystem.Received(1).ProcessAnimations(scene, gameTime);
                _renderingSystem.Received(1).RenderScene(scene);
                _entityDestructionSystem.Received(1).DestroyEntitiesAfterFullFrame(scene);

                _performanceStatisticsRecorder.RecordFrame();
                _coreDiagnosticInfoProvider.UpdateDiagnostics(scene);
            });
        }
Example #2
0
        public void Update()
        {
            _sceneManager.OnNextFrame();

            var scene = _sceneManager.CurrentScene;

            Debug.Assert(scene != null, nameof(scene) + "scene != null");

            var gameTime = _gameTimeProvider.GetGameTime();

            _timeToSimulate += gameTime.DeltaTime;
            var fixedUpdatesPerFrame = 0;

            while (_timeToSimulate >= GameTime.FixedDeltaTime && (fixedUpdatesPerFrame < _fixedUpdatesPerFrameLimit || _fixedUpdatesPerFrameLimit == 0))
            {
                using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.InputSystemName))
                {
                    _engineSystems.InputSystem.ProcessInput(scene);
                }

                using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.BehaviorSystemName))
                {
                    _engineSystems.BehaviorSystem.ProcessBehaviorFixedUpdate(scene);
                }

                foreach (var customSystem in _engineSystems.CustomSystems)
                {
                    using (_performanceStatisticsRecorder.RecordSystemExecution(customSystem.Name))
                    {
                        customSystem.ProcessFixedUpdate(scene);
                    }
                }

                using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.PhysicsSystemName))
                {
                    _engineSystems.PhysicsSystem.ProcessPhysics(scene);
                }

                using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.EntityDestructionSystemName))
                {
                    _engineSystems.EntityDestructionSystem.DestroyEntitiesAfterFixedTimeStep(scene);
                }

                _timeToSimulate -= GameTime.FixedDeltaTime;
                fixedUpdatesPerFrame++;
            }

            using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.BehaviorSystemName))
            {
                _engineSystems.BehaviorSystem.ProcessBehaviorUpdate(scene, gameTime);
            }

            foreach (var customSystem in _engineSystems.CustomSystems)
            {
                using (_performanceStatisticsRecorder.RecordSystemExecution(customSystem.Name))
                {
                    customSystem.ProcessUpdate(scene, gameTime);
                }
            }

            using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.PhysicsSystemName))
            {
                _engineSystems.PhysicsSystem.PreparePhysicsDebugInformation();
            }

            using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.AudioSystemName))
            {
                _engineSystems.AudioSystem.ProcessAudio(scene);
            }

            using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.AnimationSystemName))
            {
                _engineSystems.AnimationSystem.ProcessAnimations(scene, gameTime);
            }

            using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.RenderingSystemName))
            {
                _engineSystems.RenderingSystem.RenderScene(scene);
            }

            using (_performanceStatisticsRecorder.RecordSystemExecution(_engineSystems.EntityDestructionSystemName))
            {
                _engineSystems.EntityDestructionSystem.DestroyEntitiesAfterFullFrame(scene);
            }

            _performanceStatisticsRecorder.RecordFrame();
            _coreDiagnosticInfoProvider.UpdateDiagnostics(scene);
        }