Example #1
0
        public void MoveEntityView(int entityID, ITypeSafeList fromSafeList, ITypeSafeList toSafeList)
        {
            var fromCastedList = fromSafeList as TypeSafeFasterListForECSForClasses <EntityViewType>;
            var toCastedList   = toSafeList as TypeSafeFasterListForECSForClasses <EntityViewType>;

            toCastedList.Add(fromCastedList[fromCastedList.GetIndexFromID(entityID)]);
        }
Example #2
0
        public void AddRange(ITypeSafeList entityViewListValue)
        {
            var index = Count;

            base.AddRange(entityViewListValue as FasterList <T>);

            for (var i = index; i < Count; ++i)
            {
                _mappedIndices[this[i].ID] = i;
            }
        }
Example #3
0
        public void FillWithIndexedEntityViews(ITypeSafeList entityViews)
        {
            int count;
            var buffer = FasterList <TValue> .NoVirt.ToArrayFast((FasterList <TValue>) entityViews, out count);

            for (int i = 0; i < count; i++)
            {
                var entityView = buffer[i];

                Add(entityView.ID, entityView);
            }
        }
        static void AddEntityViewToEntityViewsDictionary(Dictionary <Type, ITypeSafeDictionary> entityViewsDBdic,
                                                         ITypeSafeList entityViews, Type entityViewType)
        {
            ITypeSafeDictionary entityViewsDic;

            if (entityViewsDBdic.TryGetValue(entityViewType, out entityViewsDic) == false)
            {
                entityViewsDic = entityViewsDBdic[entityViewType] = entityViews.CreateIndexedDictionary();
            }

            entityViewsDic.FillWithIndexedEntityViews(entityViews);
        }
Example #5
0
        public ITypeSafeList Preallocate(ref ITypeSafeList list, int size)
        {
            if (list == null)
            {
                list = new TypeSafeFasterListForECSForStructs <EntityViewType>(size);
            }
            else
            {
                list.ReserveCapacity(size);
            }

            return(list);
        }
Example #6
0
        public void BuildEntityViewAndAddToList(ref ITypeSafeList list, int entityID, out IEntityView entityView)
        {
            if (list == null)
            {
                list = new TypeSafeFasterListForECSForClasses <EntityViewType>();
            }

            var castedList = list as TypeSafeFasterListForECSForClasses <EntityViewType>;

            var lentityView = EntityView <EntityViewType> .BuildEntityView(entityID);

            castedList.Add(lentityView);

            entityView = lentityView;
        }
        public void BuildEntityViewAndAddToList(ref ITypeSafeList list, EGID entityID, out IEntityView entityView)
        {
            _initializer.ID = entityID;

            if (list == null)
            {
                list = new TypeSafeFasterListForECSForStructs <EntityViewType>();
            }

            var castedList = list as TypeSafeFasterListForECSForStructs <EntityViewType>;

            castedList.Add(_initializer);

            entityView = null;
        }
Example #8
0
        public void BuildEntityViewAndAddToList(ref ITypeSafeList list, int entityID, out IEntityView entityView)
        {
            var structEntityView = default(EntityViewType);

            structEntityView.ID = entityID;

            if (list == null)
            {
                list = new TypeSafeFasterListForECSForStructs <EntityViewType>();
            }

            var castedList = list as TypeSafeFasterListForECSForStructs <EntityViewType>;

            castedList.Add(structEntityView);

            entityView = null;
        }
        void SwapEntityGroup <T>(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new()
        {
            DesignByContract.Check.Require(fromGroupID != toGroupID, "can't move an entity to the same group where it already belongs to");

            var entityViewBuilders      = ((EntityDescriptorInfo)EntityDescriptorTemplate <T> .Default).entityViewsToBuild;
            int entityViewBuildersCount = entityViewBuilders.Length;

            var dictionary = _groupEntityViewsDB[fromGroupID];

            Dictionary <Type, ITypeSafeList> groupedEntityViewsTyped;

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

                _groupEntityViewsDB.Add(toGroupID, groupedEntityViewsTyped);
            }

            for (int i = 0; i < entityViewBuildersCount; i++)
            {
                IEntityViewBuilder entityViewBuilder = entityViewBuilders[i];
                Type entityViewType = entityViewBuilder.GetEntityViewType();

                ITypeSafeList fromSafeList = dictionary[entityViewType];
                ITypeSafeList toSafeList;

                if (groupedEntityViewsTyped.TryGetValue(entityViewType, out toSafeList) == false)
                {
                    toSafeList = fromSafeList.Create();
                }

                entityViewBuilder.MoveEntityView(entityID, fromSafeList, toSafeList);

                if (fromSafeList.UnorderedRemove(entityID) == false)
                {
                    dictionary.Remove(entityViewType);
                }
            }

            if (dictionary.Count == 0)
            {
                _groupEntityViewsDB.Remove(fromGroupID);
            }
        }
Example #10
0
        public void FillWithIndexedEntityViews(ITypeSafeList entityViews)
        {
            int count;
            var buffer = FasterList <TValue> .NoVirt.ToArrayFast((FasterList <TValue>) entityViews, out count);

            try
            {
                for (var i = 0; i < count; i++)
                {
                    var entityView = buffer[i];

                    Add(entityView.ID, entityView);
                }
            }
            catch (Exception e)
            {
                throw new TypeSafeDictionaryException(e);
            }
        }
        public void AddRange(ITypeSafeList entityViewListValue)
        {
            var index = Count;

            base.AddRange(entityViewListValue as FasterList <T>);


            for (var i = index; i < Count; ++i)
            {
                try
                {
                    _mappedIndices.Add(this[i].ID.GID, i);
                }
                catch (Exception e)
                {
                    throw new TypeSafeFasterListForECSException(e);
                }
            }
        }
Example #12
0
        static void AddEntityViewToTheSuitableEngines(Dictionary <Type, FasterList <IHandleEntityViewEngine> > entityViewEngines, ITypeSafeList entityViewsList, Type entityViewType)
        {
            FasterList <IHandleEntityViewEngine> enginesForEntityView;

            if (entityViewEngines.TryGetValue(entityViewType, out enginesForEntityView))
            {
                int viewsCount;

                var entityViews = entityViewsList.ToArrayFast(out viewsCount);

                for (int i = 0; i < viewsCount; i++)
                {
                    int count;
                    var fastList = FasterList <IHandleEntityViewEngine> .NoVirt.ToArrayFast(enginesForEntityView, out count);

                    IEntityView entityView = entityViews[i];
                    for (int j = 0; j < count; j++)
                    {
#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
                        EngineProfiler.MonitorAddDuration(fastList[j], entityView);
#else
                        fastList[j].Add(entityView);
#endif
                    }
                }
            }
        }