예제 #1
0
        public void SetupSystem(ISystem system)
        {
            var affinities                = system.GetGroupAffinities();
            var observableGroup           = EntityCollectionManager.GetObservableGroup(system.Group, affinities);
            var entitySubscriptions       = new Dictionary <int, IDisposable>();
            var entityChangeSubscriptions = new CompositeDisposable();

            _systemSubscriptions.Add(system, entityChangeSubscriptions);

            var castSystem = (IReactToEntitySystem)system;

            observableGroup.OnEntityAdded
            .Subscribe(x =>
            {
                var entitySubscription = ProcessEntity(castSystem, x);
                entitySubscriptions.Add(x.Id, entitySubscription);
            })
            .AddTo(entityChangeSubscriptions);

            observableGroup.OnEntityRemoved
            .Subscribe(x =>
            {
                entitySubscriptions.RemoveAndDispose(x.Id);
            })
            .AddTo(entityChangeSubscriptions);

            foreach (var entity in observableGroup)
            {
                var subscription = ProcessEntity(castSystem, entity);
                entitySubscriptions.Add(entity.Id, subscription);
            }

            _entitySubscriptions.Add(system, entitySubscriptions);
        }
        public void GlobalSetup()
        {
            var componentTypeAssigner = new DefaultComponentTypeAssigner();
            var allComponents         = componentTypeAssigner.GenerateComponentLookups();
            var componentLookup       = new ComponentTypeLookup(allComponents);

            _availableComponents = allComponents.Keys
                                   .Select(x => Activator.CreateInstance(x) as IComponent)
                                   .ToArray();

            var componentDatabase   = new ComponentDatabase(componentLookup);
            var componentRepository = new ComponentRepository(componentLookup, componentDatabase);

            var entityFactory          = new DefaultEntityFactory(new IdPool(), componentRepository);
            var poolFactory            = new DefaultEntityCollectionFactory(entityFactory);
            var observableGroupFactory = new DefaultObservableObservableGroupFactory();

            _entityCollectionManager = new EntityCollectionManager(poolFactory, observableGroupFactory, componentLookup);

            _availableComponents = _groupFactory.GetComponentTypes
                                   .Select(x => Activator.CreateInstance(x) as IComponent)
                                   .ToArray();

            _testGroups = _groupFactory.CreateTestGroups().ToArray();

            foreach (var group in _testGroups)
            {
                _entityCollectionManager.GetObservableGroup(group);
            }

            _defaultEntityCollection = _entityCollectionManager.GetCollection();
        }
예제 #3
0
        public TurnsSystem(GameConfiguration gameConfiguration, IEventSystem eventSystem, IEntityCollectionManager entityCollectionManager)
        {
            _gameConfiguration = gameConfiguration;
            _eventSystem       = eventSystem;

            _levelAccessor = entityCollectionManager.GetObservableGroup(new Group(typeof(LevelComponent)));
        }
예제 #4
0
 public UIManager(IEntityCollectionManager collectionManager, IEventSystem eventSystem)
 {
     CurrentScreen      = new ReactiveProperty <IEntity>();
     defaultConllection = collectionManager.GetCollection();
     this.eventSystem   = eventSystem;
     uiGroup            = collectionManager.GetObservableGroup(new Group(typeof(UIComponent)));
 }
        public DespawnAllBulletsEventSystem(IEventSystem eventSystem,
                                            IEntityCollectionManager entityCollectionManager) : base(eventSystem)
        {
            _entityCollectionManager = entityCollectionManager;

            _group           = new Group(typeof(BulletComponent), typeof(ViewComponent));
            _observableGroup = entityCollectionManager.GetObservableGroup(_group);
        }
        public void SetupSystem(ISystem system)
        {
            var entityChangeSubscriptions = new CompositeDisposable();

            SystemSubscriptions.Add(system, entityChangeSubscriptions);

            var castSystem      = (ITeardownSystem)system;
            var observableGroup = EntityCollectionManager.GetObservableGroup(system.Group);

            observableGroup.OnEntityRemoving
            .Subscribe(castSystem.Teardown)
            .AddTo(entityChangeSubscriptions);
        }
예제 #7
0
        public void SetupSystem(ISystem system)
        {
            var observableGroup    = EntityCollectionManager.GetObservableGroup(system.Group);
            var hasEntityPredicate = system.Group is IHasPredicate;
            var castSystem         = (IReactToGroupSystem)system;
            var reactObservable    = castSystem.ReactToGroup(observableGroup);

            if (!hasEntityPredicate)
            {
                var noPredicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x, castSystem));
                _systemSubscriptions.Add(system, noPredicateSub);
                return;
            }

            var groupPredicate = system.Group as IHasPredicate;
            var subscription   = reactObservable.Subscribe(x => ExecuteForGroup(x.Where(groupPredicate.CanProcessEntity), castSystem));

            _systemSubscriptions.Add(system, subscription);
        }
예제 #8
0
        public void SetupSystem(ISystem system)
        {
            var entitySubscriptions = new Dictionary <int, IDisposable>();

            _entitySubscriptions.Add(system, entitySubscriptions);
            var entityChangeSubscriptions = new CompositeDisposable();

            _systemSubscriptions.Add(system, entityChangeSubscriptions);

            var castSystem      = (ISetupSystem)system;
            var observableGroup = EntityCollectionManager.GetObservableGroup(system.Group);

            observableGroup.OnEntityAdded
            .Subscribe(x =>
            {
                var possibleSubscription = ProcessEntity(castSystem, x);
                if (possibleSubscription != null)
                {
                    entitySubscriptions.Add(x.Id, possibleSubscription);
                }
            })
            .AddTo(entityChangeSubscriptions);

            observableGroup.OnEntityRemoved
            .Subscribe(x =>
            {
                if (entitySubscriptions.ContainsKey(x.Id))
                {
                    entitySubscriptions.RemoveAndDispose(x.Id);
                }
            })
            .AddTo(entityChangeSubscriptions);

            foreach (var entity in observableGroup)
            {
                var possibleSubscription = ProcessEntity(castSystem, entity);
                if (possibleSubscription != null)
                {
                    entitySubscriptions.Add(entity.Id, possibleSubscription);
                }
            }
        }
예제 #9
0
        public void SetupSystem(ISystem system)
        {
            var affinities         = system.GetGroupAffinities();
            var observableGroup    = _entityCollectionManager.GetObservableGroup(system.Group, affinities);
            var hasEntityPredicate = system.Group is IHasPredicate;
            var isExtendedSystem   = system is IReactToGroupExSystem;
            var castSystem         = (IReactToGroupSystem)system;
            var reactObservable    = castSystem.ReactToGroup(observableGroup);
            var runParallel        = system.ShouldMutliThread();

            if (!hasEntityPredicate)
            {
                IDisposable noPredicateSub;

                if (isExtendedSystem)
                {
                    noPredicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x, (IReactToGroupExSystem)castSystem, runParallel));
                }
                else
                {
                    noPredicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x, castSystem, runParallel));
                }

                _systemSubscriptions.Add(system, noPredicateSub);
                return;
            }

            var         groupPredicate = system.Group as IHasPredicate;
            IDisposable predicateSub;

            if (isExtendedSystem)
            {
                predicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x.Where(groupPredicate.CanProcessEntity).ToList(), (IReactToGroupExSystem)castSystem, runParallel));
            }
            else
            {
                predicateSub = reactObservable.Subscribe(x => ExecuteForGroup(x.Where(groupPredicate.CanProcessEntity).ToList(), castSystem, runParallel));
            }

            _systemSubscriptions.Add(system, predicateSub);
        }
예제 #10
0
        public void SetupSystem(ISystem system)
        {
            var observableGroup      = EntityCollectionManager.GetObservableGroup(system.Group);
            var hasEntityPredicate   = system.Group is IHasPredicate;
            var castSystem           = (SpriteBatchSystem)system;
            var renderTargetId       = castSystem.GetRenderTexture2dId();
            var currentRenderTargets = _graphicsDevice.GetRenderTargets();

            var drawSubscription = _gameScheduler.OnRender.Subscribe(x =>
            {
                if (renderTargetId >= 0)
                {
                    var renderTarget = _renderTarget2dRegistry.GetRenderTarget(renderTargetId);
                    _graphicsDevice.SetRenderTarget(renderTarget);
                }

                castSystem.PreDraw();

                if (!hasEntityPredicate)
                {
                    ExecuteForGroup(observableGroup, castSystem);
                }
                else
                {
                    var groupPredicate = system.Group as IHasPredicate;
                    ExecuteForGroup(observableGroup.Where(groupPredicate.CanProcessEntity), castSystem);
                }

                castSystem.PostDraw();

                if (renderTargetId >= 0)
                {
                    _graphicsDevice.SetRenderTargets(currentRenderTargets);
                }
            });

            _systemSubscriptions.Add(system, drawSubscription);
        }
        public void SetupSystem(ISystem system)
        {
            var processEntityFunction = CreateEntityProcessorFunction(system);

            var entityChangeSubscriptions = new CompositeDisposable();

            _systemSubscriptions.Add(system, entityChangeSubscriptions);

            var entitySubscriptions = new Dictionary <int, IDisposable>();

            _entitySubscriptions.Add(system, entitySubscriptions);

            var observableGroup = EntityCollectionManager.GetObservableGroup(system.Group);

            observableGroup.OnEntityAdded
            .Subscribe(x =>
            {
                var subscription = processEntityFunction(x);
                entitySubscriptions.Add(x.Id, subscription);
            })
            .AddTo(entityChangeSubscriptions);

            observableGroup.OnEntityRemoved
            .Subscribe(x =>
            {
                entitySubscriptions.RemoveAndDispose(x.Id);
            })
            .AddTo(entityChangeSubscriptions);


            foreach (var entity in observableGroup)
            {
                var subscription = processEntityFunction(entity);
                entitySubscriptions.Add(entity.Id, subscription);
            }
        }