Beispiel #1
0
 public void SetUp()
 {
     _animationSystem         = Substitute.For <IAnimationSystem>();
     _audioSystem             = Substitute.For <IAudioSystem>();
     _behaviorSystem          = Substitute.For <IBehaviorSystem>();
     _entityDestructionSystem = Substitute.For <IEntityDestructionSystem>();
     _inputSystem             = Substitute.For <IInputSystem>();
     _physicsSystem           = Substitute.For <IPhysicsSystem>();
     _renderingSystem         = Substitute.For <IRenderingSystem>();
 }
        public void SetUp()
        {
            _coreDiagnosticInfoProvider = Substitute.For <ICoreDiagnosticInfoProvider>();
            _gameTimeProvider           = Substitute.For <IGameTimeProvider>();
            _engineSystems = Substitute.For <IEngineSystems>();
            _sceneManager  = Substitute.For <ISceneManagerForGameLoop>();
            _performanceStatisticsRecorder = Substitute.For <IPerformanceStatisticsRecorder>();

            _animationSystem = Substitute.For <IAnimationSystem>();
            _engineSystems.AnimationSystem.Returns(_animationSystem);
            _engineSystems.AnimationSystemName.Returns(AnimationSystemName);
            _audioSystem = Substitute.For <IAudioSystem>();
            _engineSystems.AudioSystem.Returns(_audioSystem);
            _engineSystems.AudioSystemName.Returns(AudioSystemName);
            _behaviorSystem = Substitute.For <IBehaviorSystem>();
            _engineSystems.BehaviorSystem.Returns(_behaviorSystem);
            _engineSystems.BehaviorSystemName.Returns(BehaviorSystemName);
            _entityDestructionSystem = Substitute.For <IEntityDestructionSystem>();
            _engineSystems.EntityDestructionSystem.Returns(_entityDestructionSystem);
            _engineSystems.EntityDestructionSystemName.Returns(EntityDestructionSystemName);
            _inputSystem = Substitute.For <IInputSystem>();
            _engineSystems.InputSystem.Returns(_inputSystem);
            _engineSystems.InputSystemName.Returns(InputSystemName);
            _physicsSystem = Substitute.For <IPhysicsSystem>();
            _engineSystems.PhysicsSystem.Returns(_physicsSystem);
            _engineSystems.PhysicsSystemName.Returns(PhysicsSystemName);
            _renderingSystem = Substitute.For <IRenderingSystem>();
            _engineSystems.RenderingSystem.Returns(_renderingSystem);
            _engineSystems.RenderingSystemName.Returns(RenderingSystemName);
            _customSystem1 = Substitute.For <ICustomSystem>();
            _customSystem1.Name.Returns(CustomSystem1Name);
            _customSystem2 = Substitute.For <ICustomSystem>();
            _customSystem2.Name.Returns(CustomSystem2Name);
            _customSystem3 = Substitute.For <ICustomSystem>();
            _customSystem3.Name.Returns(CustomSystem3Name);
            _engineSystems.CustomSystems.Returns(new[] { _customSystem1, _customSystem2, _customSystem3 });
        }
        public EngineSystems(
            IAnimationSystem animationSystem,
            IAudioSystem audioSystem,
            IBehaviorSystem behaviorSystem,
            IEntityDestructionSystem entityDestructionSystem,
            IInputSystem inputSystem,
            IPhysicsSystem physicsSystem,
            IRenderingSystem renderingSystem,
            IEnumerable <ICustomSystem> customSystems,
            CoreConfiguration configuration)
        {
            AnimationSystem         = animationSystem;
            AudioSystem             = audioSystem;
            BehaviorSystem          = behaviorSystem;
            EntityDestructionSystem = entityDestructionSystem;
            InputSystem             = inputSystem;
            PhysicsSystem           = physicsSystem;
            RenderingSystem         = renderingSystem;

            var customSystemsExecutionOrder = configuration.CustomSystemsExecutionOrder;
            var customSystemsList           = customSystems.ToList();
            var customSystemsSortedList     = new List <ICustomSystem>();

            Log.Info("Searching for custom systems...");
            foreach (var customSystem in customSystemsList)
            {
                Log.Info($"Custom system found: {customSystem.Name}");
            }

            if (customSystemsExecutionOrder.Count != customSystemsExecutionOrder.Distinct().Count())
            {
                throw new ArgumentException("Configuration specifies duplicated custom systems. Each custom system can be specified only once.");
            }

            var customSystemsNames = customSystemsList.Select(cs => cs.Name).ToList();

            if (customSystemsNames.Count != customSystemsNames.Distinct().Count())
            {
                throw new ArgumentException("There are custom system with duplicated names. Each system must have unique name.");
            }

            foreach (var systemName in customSystemsExecutionOrder)
            {
                var customSystem = customSystemsList.SingleOrDefault(cs => cs.Name == systemName);
                if (customSystem == null)
                {
                    throw new ArgumentException($"Cannot find custom system specified in configuration. Custom system name: {systemName}");
                }

                customSystemsSortedList.Add(customSystem);
            }

            CustomSystems = customSystemsSortedList.AsReadOnly();

            SystemsNames = new[]
            {
                AnimationSystemName,
                AudioSystemName,
                BehaviorSystemName,
                EntityDestructionSystemName,
                InputSystemName,
                PhysicsSystemName,
                RenderingSystemName
            }.Concat(CustomSystems.Select(cs => cs.Name)).OrderBy(n => n).ToList().AsReadOnly();

            Log.Info("Custom systems has been configured to execute in following order:");
            foreach (var customSystem in CustomSystems)
            {
                Log.Info($"Custom system name: {customSystem.Name}");
            }
        }