Exemplo n.º 1
0
        public void should_correctly_remove_component_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());

            database.Remove(0, fakeEntityId);
            Assert.False(database.Has(0, fakeEntityId));
        }
Exemplo n.º 2
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.º 3
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);
        }