protected override void ApplicationStarted()
        {
            _availableComponents = _groupFactory.GetComponentTypes
                                   .Select(x => Activator.CreateInstance(x) as IComponent)
                                   .ToArray();

            _availableComponentTypeIds = Enumerable.Range(0, _availableComponents.Length - 1).ToArray();

            var groups           = _groupFactory.CreateTestGroups(10).ToArray();
            var observableGroups = new List <IObservableGroup>();

            foreach (var group in groups)
            {
                var newGroup = ObservableGroupManager.GetObservableGroup(group);
                observableGroups.Add(newGroup);
            }

            var firstRun  = ProcessEntities(ProcessCount);
            var secondRun = ProcessEntities(ProcessCount);
            var thirdRun  = ProcessEntities(ProcessCount);

            Console.WriteLine($"Processing with {_availableComponents.Length} components and {observableGroups.Count} Observable groups");
            Console.WriteLine($"Finished In: {(firstRun + secondRun + thirdRun).TotalSeconds}s");
            Console.WriteLine($"First Took: {firstRun.TotalSeconds}s");
            Console.WriteLine($"Second Took: {secondRun.TotalSeconds}s");
            Console.WriteLine($"Third Took: {thirdRun.TotalSeconds}s");
        }
Ejemplo n.º 2
0
        protected override void ApplicationStarted()
        {
            var collection = EntityDatabase.GetCollection();

            for (var i = 0; i < _cubeCount; i++)
            {
                var viewEntity = collection.CreateEntity();
                viewEntity.AddComponents(new ViewComponent(), new RandomColorComponent());
            }

            var group = ObservableGroupManager.GetObservableGroup(new Group(typeof(ViewComponent), typeof(RandomColorComponent)));

            Debug.Log($"There are {group.Count} entities out of {collection.Count} matching");
        }
Ejemplo n.º 3
0
        public virtual void StartSystem()
        {
            ObservableGroup   = ObservableGroupManager.GetObservableGroup(Group);
            ShouldParallelize = this.ShouldMutliThread();

            var subscriptions = new CompositeDisposable();

            ProcessGroupSubscription(ObservableGroup.OnEntityAdded)
            .Subscribe(_ => RebuildBatch())
            .AddTo(subscriptions);

            ProcessGroupSubscription(ObservableGroup.OnEntityRemoved)
            .Subscribe(_ => RebuildBatch())
            .AddTo(subscriptions);

            RebuildBatch();
            ReactWhen().Subscribe(_ => RunBatch()).AddTo(subscriptions);

            Subscriptions = subscriptions;
        }
Ejemplo n.º 4
0
        private (IObservableGroupManager, IEntityDatabase, IComponentDatabase, IComponentTypeLookup) CreateFramework()
        {
            var componentLookups = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 },
                { typeof(ViewComponent), 3 },
                { typeof(TestStructComponentOne), 4 },
                { typeof(TestStructComponentTwo), 5 }
            };
            var componentLookupType    = new ComponentTypeLookup(componentLookups);
            var componentDatabase      = new ComponentDatabase(componentLookupType);
            var entityFactory          = new DefaultEntityFactory(new IdPool(), componentDatabase, componentLookupType);
            var collectionFactory      = new DefaultEntityCollectionFactory(entityFactory);
            var entityDatabase         = new EntityDatabase(collectionFactory);
            var observableGroupFactory = new DefaultObservableObservableGroupFactory();
            var observableGroupManager = new ObservableGroupManager(observableGroupFactory, entityDatabase, componentLookupType);

            return(observableGroupManager, entityDatabase, componentDatabase, componentLookupType);
        }
Ejemplo n.º 5
0
        protected override void ApplicationStarted()
        {
            _availableComponents = _groupFactory.GetComponentTypes
                                   .Select(x => Activator.CreateInstance(x) as IComponent)
                                   .ToArray();

            var groups = _groupFactory.CreateTestGroups().ToArray();

            foreach (var group in groups)
            {
                ObservableGroupManager.GetObservableGroup(group);
            }

            var firstRun  = ProcessEntities(10000);
            var secondRun = ProcessEntities(10000);
            var thirdRun  = ProcessEntities(10000);

            Console.WriteLine($"Finished In: {(firstRun + secondRun + thirdRun).TotalSeconds}s");
            Console.WriteLine($"First Took: {firstRun.TotalSeconds}s");
            Console.WriteLine($"Second Took: {secondRun.TotalSeconds}s");
            Console.WriteLine($"Third Took: {thirdRun.TotalSeconds}s");
        }