Beispiel #1
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));
        }
Beispiel #2
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);
        }
        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);
        }