예제 #1
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();
        }
예제 #2
0
        static void FillEntityView(EntityView entityView
                                   , object[]   implementors
                                   , string entityDescriptorName)
        {
            int count;

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

            if (count == 0)
            {
                return;
            }

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

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

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

#if DEBUG && !PROFILER
                Tuple <object, int> component;
#else
                object component;
#endif

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

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

            implementorsByType.Clear();
        }