Exemplo n.º 1
0
        /// <summary>
        /// Preallocate memory to avoid the impact to resize arrays when many entities are submitted at once
        /// </summary>
        void Preallocate(ExclusiveGroupStruct groupID, uint size, IComponentBuilder[] entityComponentsToBuild)
        {
            void PreallocateEntitiesToAdd()
            {
                _groupedEntityToAdd.Preallocate(groupID, size, entityComponentsToBuild);
            }

            void PreallocateDBGroup()
            {
                var numberOfEntityComponents = entityComponentsToBuild.Length;
                FasterDictionary <RefWrapperType, ITypeSafeDictionary> group = GetOrAddDBGroup(groupID);

                for (var index = 0; index < numberOfEntityComponents; index++)
                {
                    var entityComponentBuilder = entityComponentsToBuild[index];
                    var entityComponentType    = entityComponentBuilder.GetEntityComponentType();

                    var refWrapper = new RefWrapperType(entityComponentType);
                    var dbList     = group.GetOrAdd(refWrapper, () => entityComponentBuilder.CreateDictionary(size));
                    entityComponentBuilder.Preallocate(dbList, size);

                    if (_groupsPerEntity.TryGetValue(refWrapper, out var groupedGroup) == false)
                    {
                        groupedGroup = _groupsPerEntity[refWrapper] =
                            new FasterDictionary <ExclusiveGroupStruct, ITypeSafeDictionary>();
                    }

                    groupedGroup[groupID] = dbList;
                }
            }

            PreallocateDBGroup();
            PreallocateEntitiesToAdd();
            _entityLocator.PreallocateReferenceMaps(groupID, size);
        }
Exemplo n.º 2
0
        static void BuildEntity
            (EGID entityID, FasterDictionary <RefWrapperType, ITypeSafeDictionary> group
            , IComponentBuilder componentBuilder, IEnumerable <object> implementors)
        {
            var entityComponentType            = componentBuilder.GetEntityComponentType();
            ITypeSafeDictionary safeDictionary = group.GetOrAdd(new RefWrapperType(entityComponentType)
                                                                , (ref IComponentBuilder cb) => cb.CreateDictionary(1)
                                                                , ref componentBuilder);

            //   if the safeDictionary hasn't been created yet, it will be created inside this method.
            componentBuilder.BuildEntityAndAddToList(safeDictionary, entityID, implementors);
        }