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

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

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

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

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

                    groupedGroup[groupID] = dbList;
                }
            }

            PreallocateDBGroup();
            PreallocateEntitiesToAdd();
            _entityLocator.PreallocateReferenceMaps(groupID, numberOfEntities);
        }
Example #2
0
        public static bool MonitorUpdateDuration <T>(ISveltoTask <T> sveltoTask, string runnerName) where T : IEnumerator
        {
            var taskName = sveltoTask.ToString();

#if ENABLE_PIX_EVENTS
            PixWrapper.PIXBeginEventEx(0x11000000, key);
#endif
            _stopwatch.Value.Start();
            var result = sveltoTask.MoveNext();
            _stopwatch.Value.Stop();
#if ENABLE_PIX_EVENTS
            PixWrapper.PIXEndEventEx();
#endif
            lock (LockObject)
            {
                ref var infosPerRunnner =
                    ref taskInfos.GetOrCreate(runnerName, () => new FasterDictionary <string, TaskInfo>());
                if (infosPerRunnner.TryGetValue(taskName, out var info) == false)
                {
                    info = new TaskInfo(taskName, runnerName);
                    infosPerRunnner.Add(taskName, info);
                }
                else
                {
                    info.AddUpdateDuration((float)_stopwatch.Value.Elapsed.TotalMilliseconds);

                    infosPerRunnner[taskName] = info;
                }
            }
Example #3
0
        static void BuildEntity(EGID entityID, FasterDictionary <RefWrapperType, ITypeSafeDictionary> group
                                , IComponentBuilder componentBuilder, IEnumerable <object> implementors)
        {
            var entityComponentType = componentBuilder.GetEntityComponentType();
            var safeDictionary      = group.GetOrCreate(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);
        }
            internal void Preallocate
                (ExclusiveGroupStruct groupID, uint numberOfEntities, IComponentBuilder[] entityComponentsToBuild)
            {
                void PreallocateDictionaries(FasterDictionary <uint, FasterDictionary <RefWrapperType, ITypeSafeDictionary> > fasterDictionary1)
                {
                    FasterDictionary <RefWrapperType, ITypeSafeDictionary> group =
                        fasterDictionary1.GetOrCreate((uint)groupID, () => new FasterDictionary <RefWrapperType, ITypeSafeDictionary>());

                    foreach (var componentBuilder in entityComponentsToBuild)
                    {
                        var entityComponentType = componentBuilder.GetEntityComponentType();
                        var safeDictionary      = @group.GetOrCreate(new RefWrapperType(entityComponentType)
                                                                     , () => componentBuilder.CreateDictionary(numberOfEntities));
                        componentBuilder.Preallocate(safeDictionary, numberOfEntities);
                    }
                }

                PreallocateDictionaries(current);
                PreallocateDictionaries(other);

                currentEntitiesCreatedPerGroup.GetOrCreate(groupID);
                otherEntitiesCreatedPerGroup.GetOrCreate(groupID);
            }
 internal void IncrementEntityCount(ExclusiveGroupStruct groupID)
 {
     currentEntitiesCreatedPerGroup.GetOrCreate(groupID)++;
 }