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);
     }
 }
        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);
                }
            }
        }
Exemple #3
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);
        }