public void SetupSystem(ISystem system)
        {
            var accessor                  = EntityCollectionManager.CreateObservableGroup(system.TargetGroup);
            var entitySubscriptions       = new Dictionary <Guid, IDisposable>();
            var entityChangeSubscriptions = new CompositeDisposable();

            _systemSubscriptions.Add(system, entityChangeSubscriptions);

            var castSystem = (IReactToEntitySystem)system;

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

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

            foreach (var entity in accessor.Entities)
            {
                var entitySubscription = ProcessEntity(castSystem, entity);
                entitySubscriptions.Add(entity.Id, entitySubscription);
            }

            _entitySubscriptions.Add(system, entitySubscriptions);
        }
示例#2
0
        public void SetupSystem(ISystem system)
        {
            var entityChangeSubscriptions = new CompositeDisposable();

            _systemSubscriptions.Add(system, entityChangeSubscriptions);

            var castSystem = (ITeardownSystem)system;
            var accessor   = EntityCollectionManager.CreateObservableGroup(system.TargetGroup);

            accessor.OnEntityRemoved
            .Subscribe(castSystem.Teardown)
            .AddTo(entityChangeSubscriptions);
        }
        public void SetupSystem(ISystem system)
        {
            var groupAccessor      = EntityCollectionManager.CreateObservableGroup(system.TargetGroup);
            var hasEntityPredicate = system.TargetGroup is IHasPredicate;
            var castSystem         = (IReactToGroupSystem)system;
            var reactObservable    = castSystem.ReactToGroup(groupAccessor);

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

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

            _systemSubscriptions.Add(system, subscription);
        }
        public void GlobalSetup()
        {
            _eventSystem = new EventSystem(new MessageBroker());

            var entityFactory        = new DefaultEntityFactory(_eventSystem);
            var poolFactory          = new DefaultEntityCollectionFactory(entityFactory, _eventSystem);
            var groupAccessorFactory = new DefaultObservableObservableGroupFactory(_eventSystem);

            _entityCollectionManager = new EntityCollectionManager(_eventSystem, poolFactory, groupAccessorFactory);

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

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

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

            _defaultEntityCollection = _entityCollectionManager.GetCollection();
        }
        public void SetupSystem(ISystem system)
        {
            var processEntityFunction = CreateEntityProcessorFunction(system);

            var entityChangeSubscriptions = new CompositeDisposable();

            _systemSubscriptions.Add(system, entityChangeSubscriptions);

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

            _entitySubscriptions.Add(system, entitySubscriptions);

            var groupAccessor = EntityCollectionManager.CreateObservableGroup(system.TargetGroup);

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

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


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