Exemple #1
0
        public void should_return_valid_subscription_collection()
        {
            var dummyGroup = new GroupBuilder().WithComponent <TestComponentOne>().Build();
            var mockEntity = Substitute.For <IEntity>();

            var mockPoolManager = Substitute.For <IPoolManager>();

            mockPoolManager.CreateGroupAccessor(dummyGroup).Returns(new GroupAccessor(null, new[] { mockEntity }));

            var mockSystem = Substitute.For <IEntityReactionSystem>();

            mockSystem.TargetGroup.Returns(dummyGroup);

            var mockSubscription = Substitute.For <IObservable <IEntity> >();

            mockSystem.Impact(mockEntity).Returns(mockSubscription);

            var handler = new EntityReactionSystemHandler(mockPoolManager);

            var subscriptionTokens = handler.Setup(mockSystem);

            Assert.That(subscriptionTokens.Count(), Is.EqualTo(1));
            //Assert.That(subscriptionTokens.ElementAt(0).AssociatedObject, Is.EqualTo(mockEntity));
            //Assert.That(subscriptionTokens.ElementAt(0).Disposable, Is.Not.Null);
        }
        public void AddSystemsToEntity(IEntity entity, ISystemContainer container)
        {
            for (int i = 0; i < container.SetupSystems.Length; i++)
            {
                var system       = container.SetupSystems[i];
                var subscription = SetupSystemHandler.ProcessEntity(system, entity);
                if (subscription != null)
                {
                    _entitySubscribtionsOnSystems[system].Add(entity, subscription);
                }
            }

            for (int i = 0; i < container.EntityReactionSystems.Length; i++)
            {
                var system       = container.EntityReactionSystems[i];
                var subscription = EntityReactionSystemHandler.ProcessEntity(system, entity);
                if (subscription != null)
                {
                    _entitySubscribtionsOnSystems[system].Add(entity, subscription);
                }
            }

            for (int i = 0; i < container.InteractReactionSystems.Length; i++)
            {
                var system       = container.InteractReactionSystems[i];
                var subscription = InteractReactionSystemHandler.ProcessEntity(system, entity);
                if (subscription != null)
                {
                    _entitySubscribtionsOnSystems[system].Add(entity, subscription);
                }
            }
        }
 public void AddSystem(ISystem system)
 {
     _systems.Add(system);
     if (system is ISetupSystem)
     {
         _entitySubscribtionsOnSystems.Add(system, SetupSystemHandler.Setup((ISetupSystem)system)
                                           .ToDictionary(x => x.AssociatedObject as IEntity));
     }
     else if (system is IGroupReactionSystem)
     {
         _nonEntitySubscriptions.Add(system, GroupReactionSystemHandler.Setup((IGroupReactionSystem)system));
     }
     else if (system is IEntityReactionSystem)
     {
         _entitySubscribtionsOnSystems.Add(system, EntityReactionSystemHandler.Setup((IEntityReactionSystem)system)
                                           .ToDictionary(x => x.AssociatedObject as IEntity));
     }
     else if (system is IInteractReactionSystem)
     {
         _entitySubscribtionsOnSystems.Add(system, InteractReactionSystemHandler.Setup((IInteractReactionSystem)system)
                                           .ToDictionary(x => x.AssociatedObject as IEntity));
     }
     else if (system is IManualSystem)
     {
         ManualSystemHandler.Start((IManualSystem)system);
     }
 }
Exemple #4
0
        public void should_return_valid_subscription_token_when_processing()
        {
            var mockPoolManager  = Substitute.For <IPoolManager>();
            var mockEntity       = Substitute.For <IEntity>();
            var mockSystem       = Substitute.For <IEntityReactionSystem>();
            var mockSubscription = Substitute.For <IObservable <IEntity> >();

            mockSystem.Impact(mockEntity).Returns(mockSubscription);

            var handler           = new EntityReactionSystemHandler(mockPoolManager);
            var subscriptionToken = handler.ProcessEntity(mockSystem, mockEntity);

            Assert.That(subscriptionToken, Is.Not.Null);
            //Assert.That(subscriptionToken.AssociatedObject, Is.EqualTo(mockEntity));
            //Assert.That(subscriptionToken.Disposable, Is.Not.Null);
        }
Exemple #5
0
        private SystemExecutor CreateExecutor()
        {
            var messageBroker           = new EventSystem(new MessageBroker());
            var entityFactory           = new DefaultEntityFactory(messageBroker);
            var poolFactory             = new DefaultPoolFactory(entityFactory, messageBroker);
            var groupAccessorFactory    = new DefaultGroupAccessorFactory(messageBroker);
            var poolManager             = new PoolManager(messageBroker, poolFactory, groupAccessorFactory);
            var reactsToEntityHandler   = new EntityReactionSystemHandler(poolManager);
            var reactsToGroupHandler    = new GroupReactionSystemHandler(poolManager);
            var reactToComponentHandler = new InteractReactionSystemHandler(poolManager);
            var manualSystemHandler     = new ManualSystemHandler(poolManager);
            var setupHandler            = new SetupSystemHandler(poolManager);

            return(new SystemExecutor(poolManager, messageBroker, reactsToEntityHandler,
                                      reactsToGroupHandler, setupHandler, reactToComponentHandler, manualSystemHandler));
        }
        protected ReactorApplication()
        {
            var messageBroker = new MessageBroker();

            EventSystem    = new EventSystem(messageBroker);
            SystemExecutor = new SystemExecutor(EventSystem);

            var entityFactory        = new DefaultEntityFactory();
            var entityIndexPool      = new EntityIndexPool();
            var poolFactory          = new DefaultPoolFactory(entityFactory, EventSystem, entityIndexPool, SystemExecutor);
            var groupAccessorFactory = new DefaultGroupAccessorFactory(EventSystem);

            PoolManager = new PoolManager(EventSystem, poolFactory, groupAccessorFactory);

            var entitySytemHandler    = new EntityReactionSystemHandler(PoolManager);
            var groupSystemHandler    = new GroupReactionSystemHandler(PoolManager);
            var setupSystemHandler    = new SetupSystemHandler(PoolManager);
            var interactSystemHandler = new InteractReactionSystemHandler(PoolManager);
            var manualSystemHandler   = new ManualSystemHandler(PoolManager);
            var systemHandlerManager  = new SystemHandlerManager(entitySytemHandler, groupSystemHandler, setupSystemHandler, interactSystemHandler, manualSystemHandler);

            CoreManager = new CoreManager(PoolManager, systemHandlerManager, SystemExecutor);
        }