Beispiel #1
0
        private void CreatePool(Type type, IEnumerable <Attribute> attributes)
        {
            ComponentPoolAttribute propertyComponentPool = null;

            foreach (var artemisComponentPool in attributes.OfType <ComponentPoolAttribute>())
            {
                propertyComponentPool = artemisComponentPool;
            }
            var methods = type.GetMethods();

            var methodInfos = from methodInfo in methods
                              let methodAttributes = methodInfo.GetCustomAttributes(false)
                                                     from attribute in methodAttributes.OfType <ComponentCreateAttribute>()
                                                     select methodInfo;

            Func <Type, ComponentPoolable> create = null;

            foreach (var methodInfo in methodInfos)
            {
                create = (Func <Type, ComponentPoolable>)Delegate.CreateDelegate(typeof(Func <Type, ComponentPoolable>), methodInfo);
            }

            if (create == null)
            {
                create = CreateInstance;
            }

            IComponentPool <ComponentPoolable> pool;

            if (propertyComponentPool == null)
            {
                throw new NullReferenceException("propertyComponentPool is null.");
            }

            if (!propertyComponentPool.IsSupportMultiThread)
            {
                pool = new ComponentPool <ComponentPoolable>(propertyComponentPool.InitialSize, propertyComponentPool.ResizeSize, propertyComponentPool.IsResizable, create, type);
            }
            else
            {
                pool = new ComponentPoolMultiThread <ComponentPoolable>(propertyComponentPool.InitialSize, propertyComponentPool.ResizeSize, propertyComponentPool.IsResizable, create, type);
            }

            _entityWorld.SetPool(type, pool);
        }
Beispiel #2
0
 public ComponentPoolMultiThread(int initialSize, int resizePool, bool resizes, Func <Type, T> allocateFunc, Type innerType)
 {
     _pool = new ComponentPool <T>(initialSize, resizePool, resizes, allocateFunc, innerType);
     _sync = new object();
 }