internal DynamicEntityDescriptor(bool isExtendible) : this()
        {
            var defaultEntities = EntityDescriptorTemplate <TType> .descriptor.entitiesToBuild;
            var length          = defaultEntities.Length;

            _entitiesToBuild = new IEntityBuilder[length + 1];

            Array.Copy(defaultEntities, 0, _entitiesToBuild, 0, length);

            //assign it after otherwise the previous copy will overwrite the value in case the item
            //is already present
            _entitiesToBuild[length] = new EntityBuilder <EntityStructInfoView>
                                       (
                new EntityStructInfoView
            {
                entitiesToBuild = _entitiesToBuild
            }
                                       );
        }
예제 #2
0
        ///--------------------------------------------

        void SwapEntityGroup(int entityID, int fromGroupID, int toGroupID)
        {
            DBC.ECS.Check.Require(fromGroupID != toGroupID,
                                  "can't move an entity to the same group where it already belongs to");

            var entityegid               = new EGID(entityID, fromGroupID);
            var groupedEntities          = _groupEntityDB[fromGroupID];
            var entityInfoViewDictionary = (TypeSafeDictionary <EntityInfoView>)groupedEntities[_typeEntityInfoView];
            var entityViewBuilders       = entityInfoViewDictionary[entityegid.entityID].entityToBuild;
            var entityViewBuildersCount  = entityViewBuilders.Length;

            Dictionary <Type, ITypeSafeDictionary> groupedEntityViewsTyped;

            if (_groupEntityDB.TryGetValue(toGroupID, out groupedEntityViewsTyped) == false)
            {
                groupedEntityViewsTyped = new Dictionary <Type, ITypeSafeDictionary>();

                _groupEntityDB.Add(toGroupID, groupedEntityViewsTyped);
            }

            ITypeSafeDictionary toSafeDic;

            for (var i = 0; i < entityViewBuildersCount; i++)
            {
                var entityViewBuilder = entityViewBuilders[i];
                var entityViewType    = entityViewBuilder.GetEntityType();

                var fromSafeDic = groupedEntities[entityViewType];
                if (groupedEntityViewsTyped.TryGetValue(entityViewType, out toSafeDic) == false)
                {
                    groupedEntityViewsTyped[entityViewType] = toSafeDic = fromSafeDic.Create();
                }

                entityViewBuilder.MoveEntityView(entityegid, toGroupID, fromSafeDic, toSafeDic);
            }

            if (groupedEntityViewsTyped.TryGetValue(_typeEntityInfoView, out toSafeDic) == false)
            {
                groupedEntityViewsTyped[_typeEntityInfoView] = toSafeDic = entityInfoViewDictionary.Create();
            }

            EntityBuilder <EntityInfoView> .MoveEntityView(entityegid, toGroupID, entityInfoViewDictionary, toSafeDic);
        }
예제 #3
0
        public DynamicEntityDescriptorInfo(FasterList <IEntityBuilder> extraEntities) : this()
        {
            DBC.ECS.Check.Require(extraEntities.Count > 0,
                                  "don't use a DynamicEntityDescriptorInfo if you don't need to use extra EntityViews");

            var defaultEntities = EntityDescriptorTemplate <TType> .descriptor.entitiesToBuild;
            var length          = defaultEntities.Length;

            entitiesToBuild = new IEntityBuilder[length + extraEntities.Count + 1];

            Array.Copy(defaultEntities, 0, entitiesToBuild, 0, length);
            Array.Copy(extraEntities.ToArrayFast(), 0, entitiesToBuild, length, extraEntities.Count);

            var _builder = new EntityBuilder <EntityInfoView>
            {
                _initializer = new EntityInfoView {
                    entitiesToBuild = entitiesToBuild
                }
            };

            entitiesToBuild[entitiesToBuild.Length - 1] = _builder;
        }
예제 #4
0
        public DynamicEntityDescriptorInfo(IEntityBuilder[] extraEntities)
        {
            DBC.ECS.Check.Require(extraEntities.Length > 0,
                                  "don't use a DynamicEntityDescriptorInfo if you don't need to use extra EntityViews");

            var defaultEntities = EntityDescriptorTemplate <TType> .descriptor.entitiesToBuild;
            var length          = defaultEntities.Length;

            entitiesToBuild = new IEntityBuilder[length + extraEntities.Length + 1];

            Array.Copy(defaultEntities, 0, entitiesToBuild, 0, length);
            Array.Copy(extraEntities, 0, entitiesToBuild, length, extraEntities.Length);

            var _builder = new EntityBuilder <EntityStructInfoView>
            {
                _initializer = new EntityStructInfoView
                {
                    entitiesToBuild = entitiesToBuild,
                    type            = typeof(TType)
                }
            };

            entitiesToBuild[entitiesToBuild.Length - 1] = _builder;
        }
예제 #5
0
        ///--------------------------------------------

        void Preallocate <T>(int groupID, int size) where T : IEntityDescriptor, new()
        {
            var entityViewsToBuild = EntityDescriptorTemplate <T> .descriptor.entitiesToBuild;
            var count = entityViewsToBuild.Length;

            //reserve space in the database
            Dictionary <Type, ITypeSafeDictionary> @group;

            if (_groupEntityDB.TryGetValue(groupID, out group) == false)
            {
                group = _groupEntityDB[groupID] = new Dictionary <Type, ITypeSafeDictionary>();
            }

            //reserve space in building buffer
            Dictionary <Type, ITypeSafeDictionary> @groupBuffer;

            if (_groupedEntityToAdd.current.TryGetValue(groupID, out @groupBuffer) == false)
            {
                @groupBuffer = _groupedEntityToAdd.current[groupID] = new Dictionary <Type, ITypeSafeDictionary>();
            }

            ITypeSafeDictionary dbList;

            for (var index = 0; index < count; index++)
            {
                var entityViewBuilder = entityViewsToBuild[index];
                var entityViewType    = entityViewBuilder.GetEntityType();

                if (group.TryGetValue(entityViewType, out dbList) == false)
                {
                    group[entityViewType] = entityViewBuilder.Preallocate(ref dbList, size);
                }
                else
                {
                    dbList.AddCapacity(size);
                }

                if (@groupBuffer.TryGetValue(entityViewType, out dbList) == false)
                {
                    @groupBuffer[entityViewType] = entityViewBuilder.Preallocate(ref dbList, size);
                }
                else
                {
                    dbList.AddCapacity(size);
                }
            }

            if (group.TryGetValue(_typeEntityInfoView, out dbList) == false)
            {
                group[_typeEntityInfoView] = EntityBuilder <EntityInfoView> .Preallocate(ref dbList, size);
            }
            else
            {
                dbList.AddCapacity(size);
            }

            if (@groupBuffer.TryGetValue(_typeEntityInfoView, out dbList) == false)
            {
                @groupBuffer[_typeEntityInfoView] = EntityBuilder <EntityInfoView> .Preallocate(ref dbList, size);
            }
            else
            {
                dbList.AddCapacity(size);
            }
        }