Exemple #1
0
        public void TestAddRange()
        {
            FasterList <int> listA = new FasterList <int>();
            FasterList <int> listB = new FasterList <int>();

            for (int i = 0; i < 10; i++)
            {
                listA.Add(i);
            }

            for (int i = 0; i < 11; i++)
            {
                listB.Add(i);
            }

            listA.AddRange(listB);

            for (int i = 0; i < 10; i++)
            {
                Assert.That(listA[i], Is.EqualTo(i));
            }

            for (int i = 10; i < 21; i++)
            {
                Assert.That(listA[i], Is.EqualTo(i - 10));
            }
        }
Exemple #2
0
        void SubmitEntityViews()
        {
            using (var profiler = new PlatformProfiler("Svelto.ECS - Entities Submission"))
            {
                if (_entitiesOperations.Count > 0)
                {
                    using (profiler.Sample("Remove and Swap operations"))
                    {
                        _transientEntitiesOperations.FastClear();
                        var entitySubmitOperations = _entitiesOperations.GetValuesArray(out var count);
                        _transientEntitiesOperations.AddRange(entitySubmitOperations, count);
                        _entitiesOperations.FastClear();

                        var entitiesOperations = _transientEntitiesOperations.ToArrayFast();
                        for (var i = 0; i < _transientEntitiesOperations.Count; i++)
                        {
                            try
                            {
                                switch (entitiesOperations[i].type)
                                {
                                case EntitySubmitOperationType.Swap:
                                    SwapEntityGroup(entitiesOperations[i].builders,
                                                    entitiesOperations[i].entityDescriptor,
                                                    entitiesOperations[i].fromID,
                                                    entitiesOperations[i].toID);
                                    break;

                                case EntitySubmitOperationType.Remove:
                                    MoveEntity(entitiesOperations[i].builders,
                                               entitiesOperations[i].fromID,
                                               entitiesOperations[i].entityDescriptor, null);
                                    break;

                                case EntitySubmitOperationType.RemoveGroup:
                                    if (entitiesOperations[i].entityDescriptor == null)
                                    {
                                        RemoveGroupAndEntitiesFromDB(entitiesOperations[i].fromID.groupID);
                                    }
                                    else
                                    {
                                        RemoveGroupAndEntitiesFromDB(entitiesOperations[i].fromID.groupID,
                                                                     entitiesOperations[i].entityDescriptor);
                                    }

                                    break;
                                }
                            }
                            catch (Exception e)
                            {
                                var str = "Crash while executing Entity Operation "
                                          .FastConcat(entitiesOperations[i].type.ToString());
#if RELAXED_ECS && !PROFILER
                                Console.LogException(str.FastConcat(" "
#if DEBUG && !PROFILER
                                                                    , entitiesOperations[i].trace
#endif
                                                                    ), e);
#else
                                throw new ECSException(str.FastConcat(" ")
#if DEBUG && !PROFILER
                                                       .FastConcat(entitiesOperations[i].trace)
#endif
                                                       , e);
#endif
                            }
                        }
                    }
                }

                if (_groupedEntityToAdd.currentEntitiesCreatedPerGroup.Count > 0)
                {
                    using (profiler.Sample("Add operations"))
                    {
                        //use other as source from now on current will be use to write new entityViews
                        _groupedEntityToAdd.Swap();

                        try
                        {
                            //Note: if N entity of the same type are added on the same frame the Add callback is called
                            //N times on the same frame. if the Add callback builds a new entity, that entity will not
                            //be available in the database until the N callbacks are done. Solving this could be
                            //complicated as callback and database update must be interleaved.
                            AddEntityViewsToTheDBAndSuitableEngines(_groupedEntityToAdd, profiler);
                        }
                        finally
                        {
                            //other can be cleared now, but let's avoid deleting the dictionary every time
                            _groupedEntityToAdd.ClearOther();
                        }
                    }
                }
            }
        }