public DynamicEntityDescriptorInfo(FasterList <IEntityViewBuilder> extraEntityViews)
        {
            Check.Require(extraEntityViews.Count > 0,
                          "don't use a DynamicEntityDescriptorInfo if you don't need to use extra EntityViews");

            var descriptor = new TType();
            var length     = descriptor.entityViewsToBuild.Length;

            entityViewsToBuild = new IEntityViewBuilder[length + extraEntityViews.Count];

            Array.Copy(descriptor.entityViewsToBuild, 0, entityViewsToBuild, 0, length);
            Array.Copy(extraEntityViews.ToArrayFast(), 0, entityViewsToBuild, length, extraEntityViews.Count);

            name = descriptor.ToString();
        }
        public DynamicEntityDescriptorInfo(FasterList <IEntityViewBuilder> extraEntityViews)
        {
            Check.Require(extraEntityViews.Count > 0,
                          "don't use a DynamicEntityDescriptorInfo if you don't need to use extra EntityViews");

            var defaultEntityViewsToBuild = EntityDescriptorTemplate <TType> .Default.entityViewsToBuild;
            var length = defaultEntityViewsToBuild.Length;

            entityViewsToBuild = new IEntityViewBuilder[length + extraEntityViews.Count];

            Array.Copy(defaultEntityViewsToBuild, 0, entityViewsToBuild, 0, length);
            Array.Copy(extraEntityViews.ToArrayFast(), 0, entityViewsToBuild, length, extraEntityViews.Count);

            name = EntityDescriptorTemplate <TType> .Default.name;
        }
        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);
            }
        }
Exemple #4
0
        static IEntityView BuildEntityView(int entityID, Dictionary <Type, ITypeSafeList> entityViewsByType,
                                           Type entityViewType, IEntityViewBuilder entityViewBuilder)
        {
            ITypeSafeList entityViewsList;

            var entityViewsPoolWillBeCreated =
                entityViewsByType.TryGetValue(entityViewType, out entityViewsList) == false;

            IEntityView entityViewObjectToFill;

            //passing the undefined entityViewsByType inside the entityViewBuilder will allow
            //it to be created with the correct type and casted back to the undefined list.
            //that's how the list will be eventually of the target type.
            entityViewBuilder.BuildEntityViewAndAddToList(ref entityViewsList, entityID, out entityViewObjectToFill);

            if (entityViewsPoolWillBeCreated)
            {
                entityViewsByType.Add(entityViewType, entityViewsList);
            }

            return(entityViewObjectToFill as IEntityView);
        }
Exemple #5
0
 static GenericEntityDescriptor()
 {
     entityViewBuilders = new IEntityViewBuilder[] { new EntityViewBuilder <T>() };
 }
Exemple #6
0
 static MixedEntityDescriptor()
 {
     _entityViewsToBuild = new IEntityViewBuilder[] { new T() };
 }