Exemplo n.º 1
0
        /// <summary>
        ///     Creates a <see cref="Constraint"/> object with an Component QueryConstraint.
        /// </summary>
        /// <typeparam name="T">
        ///     Type of the component to constrain.
        /// </typeparam>
        /// <returns>
        ///     A <see cref="Constraint"/> object.
        /// </returns>
        public static Constraint Component <T>() where T : ISpatialComponentData
        {
            var constraint = Default();

            constraint.ComponentConstraint = ComponentDatabase.GetComponentId <T>();
            return(new Constraint(constraint));
        }
Exemplo n.º 2
0
        public void should_get_specific_components_for_entity()
        {
            var expectedSize       = 10;
            var fakeEntityId       = 1;
            var otherEntityId      = 2;
            var fakeComponent1     = new TestComponentOne();
            var fakeComponentTypes = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };

            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes);

            var database = new ComponentDatabase(mockComponentLookup, expectedSize);

            database.Add(0, fakeEntityId, fakeComponent1);
            database.Add(0, otherEntityId, new TestComponentOne());

            var component = database.Get(0, fakeEntityId);

            Assert.Equal(fakeComponent1, component);
        }
Exemplo n.º 3
0
        public void should_correctly_add_component()
        {
            var expectedSize       = 10;
            var fakeEntityId       = 1;
            var fakeComponent      = new TestComponentOne();
            var fakeComponentTypes = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };

            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes);

            var database = new ComponentDatabase(mockComponentLookup, expectedSize);

            database.Add(0, fakeEntityId, fakeComponent);

            Assert.Equal(database.EntityComponents[0][1], fakeComponent);
            var nullCount = database.EntityComponents.Sum(x => x.Count(y => y == null));

            Assert.Equal(29, nullCount);
        }
Exemplo n.º 4
0
        public void should_get_all_components_for_entity()
        {
            var expectedSize       = 10;
            var fakeEntityId       = 1;
            var otherEntityId      = 2;
            var fakeComponent1     = new TestComponentOne();
            var fakeComponent2     = new TestComponentThree();
            var fakeComponentTypes = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };

            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes);

            var database = new ComponentDatabase(mockComponentLookup, expectedSize);

            database.Add(0, fakeEntityId, fakeComponent1);
            database.Add(2, fakeEntityId, fakeComponent2);
            database.Add(0, otherEntityId, new TestComponentOne());
            database.Add(1, otherEntityId, new TestComponentTwo());
            database.Add(2, otherEntityId, new TestComponentThree());

            var allComponents = database.GetAll(fakeEntityId).ToArray();

            Assert.True(allComponents.Contains(fakeComponent1));
            Assert.True(allComponents.Contains(fakeComponent2));
            Assert.Equal(allComponents.Length, 2);
        }
Exemplo n.º 5
0
        public void should_correctly_remove_all_components_for_entity()
        {
            var expectedSize       = 10;
            var fakeEntityId       = 1;
            var otherEntityId      = 2;
            var fakeComponentTypes = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };

            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes);

            var database = new ComponentDatabase(mockComponentLookup, expectedSize);

            database.Add(0, fakeEntityId, new TestComponentOne());
            database.Add(0, fakeEntityId, new TestComponentTwo());
            database.Add(0, fakeEntityId, new TestComponentThree());
            database.Add(0, otherEntityId, new TestComponentOne());
            database.Add(1, otherEntityId, new TestComponentOne());

            database.RemoveAll(fakeEntityId);
            Assert.False(database.Has(0, fakeEntityId));
            Assert.False(database.Has(1, fakeEntityId));
            Assert.False(database.Has(2, fakeEntityId));

            var allComponents = database.GetAll(fakeEntityId);

            Assert.Empty(allComponents);
        }
        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();
        }
Exemplo n.º 7
0
        public void should_correctly_identify_if_component_exists_for_entity()
        {
            var expectedSize       = 10;
            var fakeEntityId       = 1;
            var otherEntityId      = 2;
            var fakeComponent1     = new TestComponentOne();
            var fakeComponentTypes = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };

            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes);

            var database = new ComponentDatabase(mockComponentLookup, expectedSize);

            database.Add(0, fakeEntityId, fakeComponent1);
            database.Add(0, otherEntityId, new TestComponentOne());
            database.Add(1, otherEntityId, new TestComponentOne());

            var hasComponent0 = database.Has(0, fakeEntityId);

            Assert.True(hasComponent0);

            var hasComponent1 = database.Has(1, fakeEntityId);

            Assert.False(hasComponent1);
        }
Exemplo n.º 8
0
    public static void MethodPropertyField(this SerializedProperty _methodProperty, int _index = 0)
    {
        GetProperties(_methodProperty);

        EditorGUILayout.PropertyField(objectType);
        if (objectType.enumValueIndex == (int)MethodProperty.ObjectType.Assigned)
        {
            //game object to use
            var goLabel = "Add Game Object To Begin";
            if (go.objectReferenceValue)
            {
                goLabel = "Game Object";
            }
            go.objectReferenceValue = EditorGUILayout.ObjectField(goLabel, go.objectReferenceValue, typeof(GameObject), true);

            if (go.objectReferenceValue)
            {
                var tempGo = go.objectReferenceValue as GameObject;
                MethodPropertyWithoutGameObjectField(_methodProperty, tempGo);
            }
        }
        else
        {
            componentNames = ComponentDatabase.GetAllComponentNames(true);
            componentTypes = ComponentDatabase.GetAllComponentAssemblyNames(true);
            behaviour.IndexStringField(componentNames);
            var indexValue = behaviour.FindPropertyRelative("indexValue");

            MethodPropertyField(_methodProperty, System.Type.GetType(componentTypes[indexValue.intValue]));
        }
    }
Exemplo n.º 9
0
    protected override void GetProperties()
    {
        base.GetProperties();
        behaviour = sourceRef.FindProperty("behaviour");
        enable    = sourceRef.FindProperty("enable");

        componentNames = ComponentDatabase.GetAllComponentNames();
    }
#pragma warning restore 649

        public GameObject Resolve(SpatialOSEntityInfo entityInfo, EntityManager manager)
        {
            var authComponent = ComponentDatabase.GetMetaclass(authComponentId).Authority;

            return(manager.HasComponent(entityInfo.Entity, authComponent)
                ? ownedPrefab
                : unownedPrefab);
        }
Exemplo n.º 11
0
    protected override void GetProperties()
    {
        base.GetProperties();
        behaviour = sourceRef.FindProperty("behaviour");
        method    = sourceRef.FindProperty("method");

        componentNames = ComponentDatabase.GetAllComponentNames(true);
        componentTypes = ComponentDatabase.GetAllComponentAssemblyNames(true);
    }
Exemplo n.º 12
0
        /// <summary>
        /// Update a component in the component database
        /// </summary>
        /// <param name="id">Component id to update</param>
        /// <param name="updateComponentViewModel">Values to change on the component</param>
        /// <returns></returns>
        public async Task UpdateComponent(int id, UpdateComponentViewModel updateComponentViewModel)
        {
            var component = await ComponentDatabase.GetById(id);

            if (component == null)
            {
                throw new Exception($"the requested id - {id} - was not found.");
            }

            component.Status = updateComponentViewModel.Status;
        }
Exemplo n.º 13
0
        public ref T AddComponent <T>(int componentTypeId) where T : IComponent, new()
        {
            var defaultComponent = ComponentTypeLookup.CreateDefault <T>();
            var allocationId     = ComponentDatabase.Allocate(componentTypeId);

            InternalComponentAllocations[componentTypeId] = allocationId;
            ComponentDatabase.Set(componentTypeId, allocationId, defaultComponent);

            _onComponentsAdded.OnNext(new [] { componentTypeId });

            return(ref ComponentDatabase.GetRef <T>(componentTypeId, allocationId));
        }
        public void should_corectly_get_matching_entities()
        {
            // easier to test with real stuff
            var componentLookups = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };
            var componentLookupType = new ComponentTypeLookup(componentLookups);
            var componentDatabase   = new ComponentDatabase(componentLookupType);
            var componentRepository = new ComponentRepository(componentLookupType, componentDatabase);

            var hasOneAndTwo = new Entity(1, componentRepository);

            hasOneAndTwo.AddComponent <TestComponentOne>();
            hasOneAndTwo.AddComponent <TestComponentTwo>();

            var hasAllComponents = new Entity(2, componentRepository);

            hasAllComponents.AddComponent <TestComponentOne>();
            hasAllComponents.AddComponent <TestComponentTwo>();
            hasAllComponents.AddComponent <TestComponentThree>();

            var hasOneAndThree = new Entity(3, componentRepository);

            hasOneAndThree.AddComponent <TestComponentOne>();
            hasOneAndThree.AddComponent <TestComponentThree>();

            var entityGroup = new [] { hasOneAndTwo, hasAllComponents, hasOneAndThree };

            var matchGroup1 = new Group(typeof(TestComponentOne), typeof(TestComponentTwo));
            var matchGroup2 = new Group(null, new [] { typeof(TestComponentOne), typeof(TestComponentTwo) }, new[] { typeof(TestComponentThree) });
            var matchGroup3 = new Group(null, new Type[0], new[] { typeof(TestComponentTwo) });


            var group1Results1 = entityGroup.MatchingGroup(matchGroup1).ToArray();

            Assert.Equal(2, group1Results1.Length);
            Assert.Contains(hasOneAndTwo, group1Results1);
            Assert.Contains(hasAllComponents, group1Results1);

            var group1Results2 = entityGroup.MatchingGroup(matchGroup2).ToArray();

            Assert.Equal(1, group1Results2.Length);
            Assert.Contains(hasOneAndTwo, group1Results2);

            var group1Results3 = entityGroup.MatchingGroup(matchGroup3).ToArray();

            Assert.Equal(1, group1Results3.Length);
            Assert.Contains(hasOneAndThree, group1Results3);
        }
Exemplo n.º 15
0
        public void should_correctly_allocate_instance_when_adding()
        {
            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 }
            });
            var database   = new ComponentDatabase(mockComponentLookup);
            var allocation = database.Allocate(0);

            Assert.Equal(0, allocation);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Retrieve components from the component database
        /// </summary>
        /// <param name="listComponentViewModel">View Model containng information to shape the list request</param>
        /// <returns></returns>
        public async Task <ListComponentResponse> ListComponents(ListComponentViewModel listComponentViewModel)
        {
            // TODO Number 1 Sorting and Paging
            var components = await ComponentDatabase.GetComponents();

            var pageSize = listComponentViewModel.PageSize.GetValueOrDefault(9999);
            var pageNo   = listComponentViewModel.PageNumber.GetValueOrDefault(0);

            var sortBy        = listComponentViewModel.SortField ?? SortFieldConstants.SORT_FIELD_ID;
            var sortDirection = listComponentViewModel.SortDir ?? SortDirConstants.SORT_DIR_ASC;

            if (sortBy == SortFieldConstants.SORT_FIELD_ID && sortDirection == SortDirConstants.SORT_DIR_ASC)
            {
                components = components.OrderBy(x => x.Id).Skip(pageSize * pageNo).Take(pageSize).ToList();
            }
            else if (sortBy == SortFieldConstants.SORT_FIELD_ID && sortDirection == SortDirConstants.SORT_DIR_DESC)
            {
                components = components.OrderByDescending(x => x.Id).Skip(pageSize * pageNo).Take(pageSize).ToList();
            }
            else if (sortBy == SortFieldConstants.SORT_FIELD_NAME && sortDirection == SortDirConstants.SORT_DIR_ASC)
            {
                components = components.OrderBy(x => x.Name).ThenBy(x => x.Id).Skip(pageSize * pageNo).Take(pageSize).ToList();
            }
            else if (sortBy == SortFieldConstants.SORT_FIELD_NAME && sortDirection == SortDirConstants.SORT_DIR_DESC)
            {
                components = components.OrderByDescending(x => x.Name).ThenByDescending(x => x.Id).Skip(pageSize * pageNo).Take(pageSize).ToList();
            }
            else if (sortBy == SortFieldConstants.SORT_FIELD_TYPE && sortDirection == SortDirConstants.SORT_DIR_ASC)
            {
                components = components.OrderBy(x => x.Type).ThenBy(x => x.Id).Skip(pageSize * pageNo).Take(pageSize).ToList();
            }
            else if (sortBy == SortFieldConstants.SORT_FIELD_TYPE && sortDirection == SortDirConstants.SORT_DIR_DESC)
            {
                components = components.OrderByDescending(x => x.Type).ThenByDescending(x => x.Id).Skip(pageSize * pageNo).Take(pageSize).ToList();
            }
            else if (sortBy == SortFieldConstants.SORT_FIELD_STATUS && sortDirection == SortDirConstants.SORT_DIR_ASC)
            {
                components = components.OrderBy(x => x.Status).ThenBy(x => x.Id).Skip(pageSize * pageNo).Take(pageSize).ToList();
            }
            else if (sortBy == SortFieldConstants.SORT_FIELD_STATUS && sortDirection == SortDirConstants.SORT_DIR_DESC)
            {
                components = components.OrderByDescending(x => x.Status).ThenByDescending(x => x.Id).Skip(pageSize * pageNo).Take(pageSize).ToList();
            }


            return(new ListComponentResponse()
            {
                Total = components.Count(),
                Components = components
            });
        }
Exemplo n.º 17
0
        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);

            _componentRepository = new ComponentRepository(componentLookup, componentDatabase);
        }
Exemplo n.º 18
0
        protected override IDisposable ReactToPools()
        {
            var componentType1 = ComponentTypeLookup.GetComponentType(typeof(T1));
            var componentType2 = ComponentTypeLookup.GetComponentType(typeof(T2));
            var pool1          = ComponentDatabase.GetPoolFor <T1>(componentType1);
            var pool2          = ComponentDatabase.GetPoolFor <T2>(componentType2);

            var subscriptions = new CompositeDisposable();

            pool1.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions);
            pool2.OnPoolExtending.Subscribe(_ => Refresh()).AddTo(subscriptions);

            return(subscriptions);
        }
Exemplo n.º 19
0
        public void AddComponents(IReadOnlyList <IComponent> components)
        {
            var componentTypeIds = new int[components.Count];

            for (var i = 0; i < components.Count; i++)
            {
                var componentTypeId = ComponentTypeLookup.GetComponentType(components[i].GetType());
                var allocationId    = ComponentDatabase.Allocate(componentTypeId);
                InternalComponentAllocations[componentTypeId] = allocationId;
                ComponentDatabase.Set(componentTypeId, allocationId, components[i]);
            }

            _onComponentsAdded.OnNext(componentTypeIds);
        }
Exemplo n.º 20
0
        protected CommandReceiverSubscriptionManagerBase(World world, uint componentId) : base(world)
        {
            var componentMetaClass = ComponentDatabase.GetMetaclass(componentId);

            componentAuthType = componentMetaClass.Authority;

            entityManager = world.EntityManager;

            var constraintSystem = world.GetExistingSystem <ComponentConstraintsCallbackSystem>();

            constraintSystem.RegisterAuthorityCallback(componentId, authorityChange =>
            {
                if (authorityChange.Authority == Authority.Authoritative)
                {
                    if (!entitiesNotMatchingRequirements.Contains(authorityChange.EntityId))
                    {
                        return;
                    }

                    var entity = WorkerSystem.GetEntity(authorityChange.EntityId);

                    foreach (var subscription in entityIdToReceiveSubscriptions[authorityChange.EntityId])
                    {
                        subscription.SetAvailable(CreateReceiver(world, entity, authorityChange.EntityId));
                    }

                    entitiesMatchingRequirements.Add(authorityChange.EntityId);
                    entitiesNotMatchingRequirements.Remove(authorityChange.EntityId);
                }
                else if (authorityChange.Authority == Authority.NotAuthoritative)
                {
                    if (!entitiesMatchingRequirements.Contains(authorityChange.EntityId))
                    {
                        return;
                    }

                    foreach (var subscription in entityIdToReceiveSubscriptions[authorityChange.EntityId])
                    {
                        ResetValue(subscription);
                        subscription.SetUnavailable();
                    }

                    entitiesNotMatchingRequirements.Add(authorityChange.EntityId);
                    entitiesMatchingRequirements.Remove(authorityChange.EntityId);
                }
            });
        }
Exemplo n.º 21
0
        private IEntityCollectionManager CreateCollectionManager()
        {
            var componentLookups = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };
            var componentLookupType    = new ComponentTypeLookup(componentLookups);
            var componentDatabase      = new ComponentDatabase(componentLookupType);
            var componentRepository    = new ComponentRepository(componentLookupType, componentDatabase);
            var entityFactory          = new DefaultEntityFactory(new IdPool(), componentRepository);
            var collectionFactory      = new DefaultEntityCollectionFactory(entityFactory);
            var observableGroupFactory = new DefaultObservableObservableGroupFactory();

            return(new EntityCollectionManager(collectionFactory, observableGroupFactory, componentLookupType));
        }
Exemplo n.º 22
0
        public void should_correctly_remove_instance()
        {
            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 }
            });

            var mockExpandingArray = Substitute.For <IComponentPool>();

            var database = new ComponentDatabase(mockComponentLookup);

            database.ComponentData.SetValue(mockExpandingArray, 0);
            database.Remove(0, 0);

            mockExpandingArray.Received(1).Release(0);
        }
Exemplo n.º 23
0
        public void should_correctly_initialize()
        {
            var expectedSize       = 10;
            var fakeComponentTypes = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };

            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes);

            var database = new ComponentDatabase(mockComponentLookup, expectedSize);

            Assert.Equal(fakeComponentTypes.Count, database.ComponentData.Length);
            Assert.Equal(expectedSize, database.ComponentData[0].Count);
        }
Exemplo n.º 24
0
        protected EcsRxApplication()
        {
            // For sending events around
            EventSystem = new EventSystem(new MessageBroker());

            // For mapping component types to underlying indexes
            var componentTypeAssigner = new DefaultComponentTypeAssigner();
            var allComponents         = componentTypeAssigner.GenerateComponentLookups();

            var componentLookup = new ComponentTypeLookup(allComponents);
            // For interacting with the component databases
            var componentDatabase   = new ComponentDatabase(componentLookup);
            var componentRepository = new ComponentRepository(componentLookup, componentDatabase);

            // For creating entities, collections, observable groups and managing Ids
            var entityFactory           = new DefaultEntityFactory(new IdPool(), componentRepository);
            var entityCollectionFactory = new DefaultEntityCollectionFactory(entityFactory);
            var observableGroupFactory  = new DefaultObservableObservableGroupFactory();

            EntityCollectionManager = new EntityCollectionManager(entityCollectionFactory, observableGroupFactory, componentLookup);

            // All system handlers for the system types you want to support
            var reactsToEntityHandler = new ReactToEntitySystemHandler(EntityCollectionManager);
            var reactsToGroupHandler  = new ReactToGroupSystemHandler(EntityCollectionManager);
            var reactsToDataHandler   = new ReactToDataSystemHandler(EntityCollectionManager);
            var manualSystemHandler   = new ManualSystemHandler(EntityCollectionManager);
            var setupHandler          = new SetupSystemHandler(EntityCollectionManager);
            var teardownHandler       = new TeardownSystemHandler(EntityCollectionManager);

            var conventionalSystems = new List <IConventionalSystemHandler>
            {
                setupHandler,
                teardownHandler,
                reactsToEntityHandler,
                reactsToGroupHandler,
                reactsToDataHandler,
                manualSystemHandler
            };

            // The main executor which manages how systems are given information
            SystemExecutor = new SystemExecutor(conventionalSystems);
        }
Exemplo n.º 25
0
        private (IEntityCollectionManager, 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 observableGroupFactory = new DefaultObservableObservableGroupFactory();
            var collectionManager      = new EntityCollectionManager(collectionFactory, observableGroupFactory, componentLookupType);

            return(collectionManager, componentDatabase, componentLookupType);
        }
Exemplo n.º 26
0
        public void RemoveComponents(IReadOnlyList <int> componentsTypeIds)
        {
            var sanitisedComponentsIds = componentsTypeIds.Where(HasComponent).ToArray();

            if (sanitisedComponentsIds.Length == 0)
            {
                return;
            }

            _onComponentsRemoving.OnNext(sanitisedComponentsIds);

            for (var i = 0; i < sanitisedComponentsIds.Length; i++)
            {
                var componentId     = sanitisedComponentsIds[i];
                var allocationIndex = InternalComponentAllocations[componentId];
                ComponentDatabase.Remove(componentId, allocationIndex);
                InternalComponentAllocations[componentId] = NotAllocated;
            }

            _onComponentsRemoved.OnNext(sanitisedComponentsIds);
        }
Exemplo n.º 27
0
        public void should_correctly_expand_for_new_entities()
        {
            var startingSize       = 10;
            var expectedSize       = 20;
            var fakeComponentTypes = new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 },
                { typeof(TestComponentTwo), 1 },
                { typeof(TestComponentThree), 2 }
            };

            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(fakeComponentTypes);

            var database = new ComponentDatabase(mockComponentLookup, startingSize);

            database.AccommodateMoreEntities(expectedSize);

            Assert.Equal(expectedSize, database.CurrentEntityBounds);
            Assert.Equal(fakeComponentTypes.Count, database.EntityComponents.Length);
            Assert.Equal(expectedSize, database.EntityComponents[0].Count);
            Assert.All(database.EntityComponents, x => x.All(y => y == null));
        }
Exemplo n.º 28
0
        private void UpdateComponentSet()
        {
            using (var components = world.EntityManager.GetComponentTypes(selected.Value.Entity, allocator: Allocator.Temp))
            {
                var spatialComponents = components
                                        .Where(type => typeof(ISpatialComponentData).IsAssignableFrom(type.GetManagedType()))
                                        .OrderBy(type => ComponentDatabase.GetComponentId(type.GetManagedType()));

                if (AreSameComponents(spatialComponents, visualElements))
                {
                    return;
                }

                componentContainer.Clear();
                visualElements.Clear();

                foreach (var componentType in spatialComponents)
                {
                    var componentElement = Cache.Get(componentType);
                    componentContainer.Add(componentElement);
                    visualElements.Add(componentElement);
                }
            }
        }
Exemplo n.º 29
0
        public IComponent GetComponent(int componentTypeId)
        {
            var allocationIndex = InternalComponentAllocations[componentTypeId];

            return(ComponentDatabase.Get(allocationIndex, componentTypeId));
        }
Exemplo n.º 30
0
        public void UpdateComponent <T>(int componentTypeId, T newValue) where T : struct, IComponent
        {
            var allocationId = InternalComponentAllocations[componentTypeId];

            ComponentDatabase.Set(componentTypeId, allocationId, newValue);
        }