示例#1
0
        internal EntityDescriptorInfo(IEntityDescriptor descriptor)
        {
            name = descriptor.ToString();
            entityViewsToBuild = descriptor.entityViewsToBuild;

            removeEntityImplementor = new RemoveEntityImplementor(entityViewsToBuild);
        }
示例#2
0
        static void InternalBuildEntityViews(int entityID,
                                             Dictionary <Type, ITypeSafeList> entityViewsByType,
                                             IEntityDescriptorInfo eentityViewsToBuildDescriptor,
                                             object[] implementors, RemoveEntityImplementor removeEntityImplementor)
        {
            var entityViewsToBuildDescriptor = eentityViewsToBuildDescriptor as EntityDescriptorInfo;
            var entityViewsToBuild           = entityViewsToBuildDescriptor.entityViewsToBuild;
            int count = entityViewsToBuild.Length;

            for (int index = 0; index < count; index++)
            {
                var entityViewBuilder = entityViewsToBuild[index];
                var entityViewType    = entityViewBuilder.GetEntityViewType();

                //only class EntityView will be returned
                //struct EntityView cannot be filled so it will be null.
                var entityViewObjectToFill =
                    BuildEntityView(entityID, entityViewsByType, entityViewType, entityViewBuilder);

                //the semantic of this code must still be improved
                //but only classes can be filled, so I am aware
                //it's a EntityView
                if (entityViewObjectToFill != null)
                {
                    FillEntityView(entityViewObjectToFill as EntityView, implementors, removeEntityImplementor,
                                   entityViewsToBuildDescriptor.name);
                }
            }
        }
示例#3
0
        internal static void BuildGroupedEntityViews(int entityID, int groupID,
                                                     Dictionary <int, Dictionary <Type, ITypeSafeList> > groupEntityViewsByType,
                                                     IEntityDescriptorInfo eentityViewsToBuildDescriptor,
                                                     object[] implementors)
        {
            var entityViewsToBuildDescriptor = eentityViewsToBuildDescriptor as EntityDescriptorInfo;
            Dictionary <Type, ITypeSafeList> groupedEntityViewsTyped;

            if (groupEntityViewsByType.TryGetValue(groupID, out groupedEntityViewsTyped) == false)
            {
                groupedEntityViewsTyped = new Dictionary <Type, ITypeSafeList>();
                groupEntityViewsByType.Add(groupID, groupedEntityViewsTyped);
            }

            //I would like to find a better solution for this
            var removeEntityImplementor = new RemoveEntityImplementor(entityViewsToBuildDescriptor.entityViewsToBuild, groupID);

            InternalBuildEntityViews(entityID, groupedEntityViewsTyped, entityViewsToBuildDescriptor, implementors, removeEntityImplementor);
        }
示例#4
0
        static void FillEntityView(EntityView entityView, object[] implementors, RemoveEntityImplementor removeEntity,
                                   string entityDescriptorName)
        {
            for (int index = 0; index < implementors.Length; index++)
            {
                var implementor = implementors[index];

                if (implementor != null)
                {
                    var type = implementor.GetType();

                    Type[] interfaces;
                    if (_cachedTypes.TryGetValue(type, out interfaces) == false)
                    {
                        interfaces = _cachedTypes[type] = type.GetInterfacesEx();
                    }

                    for (int iindex = 0; iindex < interfaces.Length; iindex++)
                    {
                        var componentType = interfaces[iindex];
#if DEBUG && !PROFILER
                        Tuple <object, int> implementorHolder;

                        if (implementorsByType.TryGetValue(componentType, out implementorHolder) == true)
                        {
                            implementorHolder.item2++;
                        }
                        else
                        {
                            implementorsByType[componentType] = new Tuple <object, int>(implementor, 1);
                        }
#else
                        implementorsByType[componentType] = implementor;
#endif
                    }
                }
#if DEBUG && !PROFILER
                else
                {
                    Utility.Console.LogError(NULL_IMPLEMENTOR_ERROR.FastConcat(entityView.ToString()));
                }
#endif
            }

            int count;

            //Very efficent way to collect the fields of every EntityViewType
            KeyValuePair <Type, CastedAction <EntityView> >[] setters =
                FasterList <KeyValuePair <Type, CastedAction <EntityView> > > .NoVirt.ToArrayFast(entityView.entityViewBlazingFastReflection, out count);

            var removeEntityComponentType = typeof(IRemoveEntityComponent);

            for (int i = 0; i < count; i++)
            {
                var  keyValuePair = setters[i];
                Type fieldType    = keyValuePair.Key;

                if (fieldType != removeEntityComponentType)
                {
#if DEBUG && !PROFILER
                    Tuple <object, int> component;
#else
                    object component;
#endif

                    if (implementorsByType.TryGetValue(fieldType, out component) == false)
                    {
                        Exception e = new Exception(NOT_FOUND_EXCEPTION + " Component Type: " + fieldType.Name + " - EntityView: " +
                                                    entityView.GetType().Name + " - EntityDescriptor " + entityDescriptorName);

                        throw e;
                    }
#if DEBUG && !PROFILER
                    if (component.item2 > 1)
                    {
                        Utility.Console.LogError(DUPLICATE_IMPLEMENTOR_ERROR.FastConcat(
                                                     "Component Type: ", fieldType.Name, " implementor: ",
                                                     component.item1.ToString()) + " - EntityView: " +
                                                 entityView.GetType().Name + " - EntityDescriptor " + entityDescriptorName);
                    }
#endif
#if DEBUG && !PROFILER
                    keyValuePair.Value.Call(entityView, component.item1);
#else
                    keyValuePair.Value.Call(entityView, component);
#endif
                }
                else
                {
                    keyValuePair.Value.Call(entityView, removeEntity);
                }
            }

            implementorsByType.Clear();
        }