Esempio n. 1
0
        public override void Process(PoolEntry <object[]> row)
        {
            if (InvokeBeforeTargetAdapterProcessRowEvent(row) == BeforeProcessRowResult.Abort)
            {
                return;
            }

            byte[] bytes;
            int    bytesWritten;

            try
            {
                bytes = RowToBytes(row.Value, out bytesWritten);
            }
            catch (Exception e)
            {
                if (AbortOnProcessException ?? false)
                {
                    throw;
                }
                InvokeProcessErrorEvent(row, e);
                return;
            }
            Target.Write(bytes, 0, bytesWritten);

            InvokeAfterTargetAdapterProcessRowEvent(row);
        }
Esempio n. 2
0
    private void ShowEntries(PoolObject targetObj)
    {
        GUILayout.BeginVertical();
        for (int i = 0; i < targetObj.poolItems.Length; i++)
        {
            GUILayout.Label("");
//			GUILayout.BeginHorizontal();
            PoolEntry entry;
            if (targetObj.poolItems[i] == null)
            {
                entry = new PoolEntry();
            }
            else
            {
                entry = targetObj.poolItems[i];
            }

            Debug.Log("entry.prefab" + entry.prefab);

            GUILayout.Label("Prefab Type " + i + " (" + (entry.prefab == null?"Empty":entry.prefab.name) + ")");

            entry.prefab             = EditorGUILayout.ObjectField("Prefab", entry.prefab, typeof(GameObject), true) as GameObject;
            entry.objectsInPool      = EditorGUILayout.IntField("Count", entry.objectsInPool);
            entry.instantiateIfEmpty = EditorGUILayout.Toggle("Instantiate if Null", entry.instantiateIfEmpty);

//			GUILayout.EndHorizontal();
        }

        GUILayout.EndVertical();
    }
        public void Insert(object[] obj, PoolEntry <object[]> .PoolEntryDelegate onReleaseOne)
        {
            WaitPrepared();
            var entry = AcquireEntry();

            entry.Value = obj;
            Insert(entry, onReleaseOne);
        }
Esempio n. 4
0
    private PoolEntry CreateNewEntry()
    {
        var gameObject = Object.Instantiate(original, root);
        var entry      = new PoolEntry(gameObject, this);

        entries.Add(gameObject, entry);
        return(entry);
    }
Esempio n. 5
0
    public PoolEntry <T> AddEmptyItem(int lockCount = 0)
    {
        var arr   = new T[SizePerArray];
        var entry = new PoolEntry <T>(arr, lockCount);

        Resources.Add(entry);

        return(entry);
    }
Esempio n. 6
0
 private void SetState(TPooledItem item, bool isActive)
 {
     for (int i = 0; i < _pool.Count; i++)
     {
         PoolEntry current = _pool[i];
         if (current.Item == item)
         {
             current.IsActive = isActive;
         }
     }
 }
Esempio n. 7
0
    private PoolEntry TakeEntry()
    {
        if (takeEntryCalls++ >= callsToClearUnloadedEntries)
        {
            RemoveUnloadedEntries();
        }

        PoolEntry result = FindReleasedEntry() ?? CreateNewEntry();

        result.transform.parent = root;
        return(result);
    }
        public static void Free(T[] array)
        {
            PoolEntry entry;

            if (!_unused.TryGetValue(array.Length, out entry))
            {
                entry = new PoolEntry();
                _unused.Add(array.Length, entry);
            }

            entry.Add(array);
        }
        uint Add(XmbFileBuilder builder, PoolEntry e)
        {
            uint size = e.CalculateSize();

            uint offset = mPoolSize += size;

            // In case the entry needs to be aligned
            mPoolSize += e.CalculatePadding(offset);

            mEntries.Add(offset, e);
            return(offset);
        }
Esempio n. 10
0
    private PoolEntry GrowPool()
    {
        PoolEntry  entry = new PoolEntry();
        GameObject o     = GameObject.Instantiate(prefab) as GameObject;

        o.name = component.name.ToString();
        o.transform.SetParent(parent.transform);
        o.SetActive(false);
        entry.gameObject = o;
        entry.behavior   = o.GetComponent(component.GetType());
        objects.Add(entry);
        return(entry);
    }
Esempio n. 11
0
 public ObjectPool(int maxObjects,
                   CreateObjectDelegate creator,
                   AllocObjectDelegate allocator,
                   DisposeObjectDelegate disposer)
 {
     if (creator == null)
     {
         throw new ArgumentNullException("CreateObjectDelegate creator");
     }
     _creator   = creator;
     _allocator = allocator;
     _disposer  = disposer;
     _pool      = new PoolEntry[maxObjects];
 }
        public uint Add(XmbFileBuilder builder, int v)
        {
            foreach (var kv in mEntries)
            {
                if (kv.Value.Equals(v))
                {
                    return(kv.Key);
                }
            }

            var entry = PoolEntry.New(v);

            return(Add(builder, entry));
        }
        PoolEntry DeBuffer(XmbVariantType type, uint offset, byte flags = 0)
        {
            if (!ValidOffset(offset))
            {
                throw new ArgumentOutOfRangeException("offset", string.Format("{0} > {1}",
                                                                              offset.ToString("X8"), mPoolSize.ToString("X6")));
            }

            PoolEntry e;

            if (!mEntries.TryGetValue(offset, out e))
            {
                if (mBufferedDataRemaining == 0)
                {
                    throw new InvalidOperationException("No data left in buffer");
                }
                else if (mBuffer == null)
                {
                    throw new InvalidOperationException("No underlying buffer");
                }

                // Create our new entry, setting any additional properties
                e = PoolEntry.New(type);
                if (type == XmbVariantType.String)
                {
                    e.IsUnicode = flags != 0;
                }
                else if (type == XmbVariantType.Vector)
                {
                    e.VectorLength = flags;
                }
                // Great, now read the entry's value data
                mBuffer.Seek32(offset);
                e.Read(mBuffer);

                // Update how much data is still remaining
                uint bytes_read = (uint)(mBuffer.BaseStream.Position - offset);
                mBufferedDataRemaining -= bytes_read;

                if (mBufferedDataRemaining == 0)
                {
                    DisposeBuffer();
                }

                mEntries.Add(offset, e);
            }

            return(e);
        }
        public uint Add(XmbFileBuilder builder, string v, bool isUnicode = false)
        {
            foreach (var kv in mEntries)
            {
                if (kv.Value.Equals(v))
                {
                    return(kv.Key);
                }
            }

            var entry = PoolEntry.New(v);

            entry.IsUnicode = isUnicode;
            return(Add(builder, entry));
        }
        public void TestBlockingQueueSourceAdapterCreateWithArraysOfPoolEntryArray()
        {
            var data = new object[100];

            for (var i = 0; i < data.Length; i++)
            {
                data[i] = new PoolEntry <object[]>(new [] { (object)i });
            }
            var adapter = new BlockingQueueSourceAdapter(data);
            var itemNo  = 0;

            foreach (var item in adapter.RowsEnumerable)
            {
                Assert.AreEqual(itemNo++, item.Value[0]);
            }
        }
        PoolEntry DeBuffer(BinaryDataTreeVariantTypeDesc desc, uint offset, bool sizeIsIndirect = false)
        {
            if (!ValidOffset(offset))
            {
                throw new ArgumentOutOfRangeException("offset", string.Format("{0} > {1}",
                                                                              offset.ToString("X8"), mPoolSize.ToString("X6")));
            }

            PoolEntry e;

            if (!mEntries.TryGetValue(offset, out e))
            {
                if (mBufferedDataRemaining == 0)
                {
                    throw new InvalidOperationException("No data left in buffer");
                }
                else if (mBuffer == null)
                {
                    throw new InvalidOperationException("No underlying buffer");
                }

                // Create our new entry, setting any additional properties
                e = PoolEntry.New(desc);
                if (sizeIsIndirect)
                {
                    uint size = GetSizeValue(offset);
                    e.ArrayLength = (int)(size >> desc.SizeBit);
                }
                // Great, now read the entry's value data
                mBuffer.Seek32(offset);
                e.Read(mBuffer);

                // Update how much data is still remaining
                uint bytes_read = (uint)(mBuffer.BaseStream.Position - offset);
                mBufferedDataRemaining -= bytes_read;

                if (mBufferedDataRemaining == 0)
                {
                    DisposeBuffer();
                }

                mEntries.Add(offset, e);
            }

            return(e);
        }
Esempio n. 17
0
    public TPooledItem GetPooledItem()
    {
        TPooledItem result = null;

        for (int i = 0; i < _pool.Count; i++)
        {
            PoolEntry current = _pool[i];
            if (!current.IsActive)
            {
                result = current.Item;
                Activate(result);
                break;
            }
        }

        return(result);
    }
        private void InsertGeneric <T>(T obj, PoolEntry <object[]> .PoolEntryDelegate onReleaseOne, Serializer <T> serializer)
        {
            switch (obj)
            {
            case object[] objArray:
                InsertArray(objArray, onReleaseOne);
                return;

            default:
                WaitForPumpStartAndSourceAdapterPrepared();
                var entry = _blockingQueueSourceAdapter.AcquireEntry();
                entry.Value = serializer?.ToValues(obj, entry.Value) ?? (typeof(T) == typeof(object)
                        ? Serializer <object> .ToValues(obj, entry.Value)
                        : Serializer <T> .ToValues(obj, entry.Value));
                _blockingQueueSourceAdapter.Insert(entry, onReleaseOne);
                return;
            }
        }
Esempio n. 19
0
    public void AddFrame(byte[] colorData, ushort[] depthData, byte[] indexData)
    {
        var colorCount = Convert.ToInt32(SaveColor) + Convert.ToInt32(SaveTracked);
        var depthCount = Convert.ToInt32(SaveDepth) + Convert.ToInt32(SaveTracked);

        PoolEntry <byte>   _color = null;
        PoolEntry <ushort> _depth = null;

        if (SaveColor || SaveTracked)
        {
            _color = colorPool.RequestResource(colorCount);
            colorData.CopyTo(_color.Resource, 0);

            if (SaveColor)
            {
                color.Frames.Enqueue(_color);
            }
        }


        if (SaveDepth || SaveTracked)
        {
            _depth = depthPool.RequestResource(depthCount);
            depthData.CopyTo(_depth.Resource, 0);

            if (SaveDepth)
            {
                depth.Frames.Enqueue(_depth);
            }
        }

        if (SaveTracked)
        {
            tracked.AddFrame(_depth, _color);
        }

        if (SaveIndex)
        {
            var _index = indexPool.RequestResource(1);
            indexData.CopyTo(_index.Resource, 0);
            index.Frames.Enqueue(_index);
        }
    }
Esempio n. 20
0
    // Query the big pool to get the entry which contain the requested prefab
    // If such entry not existed, create it, and put into the big pool.
    public static GameObject GetFreeObject(GameObject prefab)
    {
        PoolEntry result = null;

        foreach (PoolEntry entry in entries)
        {
            if (entry.prefab == prefab)
            {
                result = entry;
                break;
            }
        }

        if (result == null)
        {
            result = new PoolEntry(prefab);
            entries.Add(result);
        }

        return(GetFreeObjectFromEntry(result, prefab));
    }
Esempio n. 21
0
    // Get the list object from the pool for a certain prefab
    public static List <GameObject> GetObjectList(GameObject prefab)
    {
        PoolEntry result = null;

        foreach (PoolEntry entry in entries)
        {
            if (entry.prefab == prefab)
            {
                result = entry;
                break;
            }
        }

        if (result == null)
        {
            result = new PoolEntry(prefab);
            entries.Add(result);
        }

        return(result.list);
    }
Esempio n. 22
0
        private static void TestBag()
        {
            ConcurrentList <PoolEntry> connectionList = new ConcurrentList <PoolEntry>();
            int num = 100;

            Task[]   tasks = new Task[num];
            Task[]   read  = new Task[num];
            DateTime start = DateTime.Now;

            //写入
            for (int i = 0; i < num; i++)
            {
                var r = Task.Factory.StartNew(() => {
                    for (int j = 0; j < 10000; j++)
                    {
                        PoolEntry poolEntry = new PoolEntry(null, null);
                        connectionList.Push(poolEntry);
                    }
                });
                tasks[i] = r;
            }

            //读取
            for (int i = 0; i < num; i++)
            {
                var r = Task.Factory.StartNew(() =>
                {
                    PoolEntry poolEntry = null;
                    while (!connectionList.IsEmpty)
                    {
                        connectionList.TryPop(out poolEntry);
                    }
                });
                read[i] = r;
            }
            Task.WaitAll(read);
            Task.WaitAll(tasks);

            Console.WriteLine("时间:" + (DateTime.Now - start).TotalSeconds);
        }
Esempio n. 23
0
        private GameObject CreateObject(PoolEntry poolEntry)
        {
            if (poolEntry.PrefabObject == null)
            {
                Debug.LogErrorFormat("'{0}' has not been associated with a prefab.", poolEntry.ObjectName);
                return(null);
            }

            var instantinatedObject = poolEntry.ParentObject != null?Instantiate(poolEntry.PrefabObject, poolEntry.ParentObject.transform) : Instantiate(poolEntry.PrefabObject);

            instantinatedObject.SetActive(false);

            poolEntry.PooledObjects.Add(instantinatedObject);

            if (!_isCoroutineActive && poolEntry.PooledObjects.Count > poolEntry.PoolAmount)
            {
                StartCoroutine(ClearExcess());
                _isCoroutineActive = true;
            }

            return(instantinatedObject);
        }
Esempio n. 24
0
        public override void Process(PoolEntry <object[]> row)
        {
            if (OverflowStringFieldWidthBehaviors != null)
            {
                for (var i = 0; i < row.Value.Length; i++)
                {
                    if (!(row.Value[i] is string) || ((string)row.Value[i]).Length <= Math.Abs(FieldSizes[i]))
                    {
                        continue;
                    }
                    var strValue = (string)row.Value[i];
                    if (OverflowStringFieldWidthBehaviors[i] == OverflowStringFieldWidthBehavior.Error)
                    {
                        throw new DataPipelineException(
                                  $"Field {Source.ColumnMetadatas[i].ColumnName} size overflow streaming using fixed length streamer");
                    }
                    row.Value[i] = strValue.Remove(FieldSizes[i], strValue.Length - FieldSizes[i]);
                }
            }

            base.Process(row);
        }
Esempio n. 25
0
        public GameObject this[string name]
        {
            get
            {
                PoolEntry poolEntry = poolEntries.First(pooledObject => pooledObject.objectName == name);

                if (poolEntry == null)
                {
                    return(null);
                }

                foreach (GameObject pooledObject in poolEntry.pooledObjects)
                {
                    if (!pooledObject.gameObject.activeInHierarchy)
                    {
                        return(pooledObject.gameObject);
                    }
                }

                return(!poolEntry.automaticGrowth ? null : CreateObject(poolEntry));
            }
        }
Esempio n. 26
0
        public void Add(PoolItem item)
        {
            PoolEntry entry;

            // Using autoKey and does not yet exist as an item...
            if (item.useAutoKey && !m_items.Any(x => Equals(x.key, item.key)))
            {
                entry = new PoolEntry(item.key, item.maxCount);
                m_items.Add(entry);
            }
            // Otherwise, find appropriate entry
            else
            {
                entry = m_items.FirstOrDefault(x => Equals(x.key, item.key));
            }

            if (entry == null)
            {
                return;
            }

            entry.Add(item);
        }
Esempio n. 27
0
    // Get the actual object from the small pool in the entry.
    // If not existed, create the object and put into the small pool
    private static GameObject GetFreeObjectFromEntry(PoolEntry entry, GameObject prefab)
    {
        GameObject result = null;

        foreach (GameObject gameObject in entry.list)
        {
            if (gameObject != null && !gameObject.activeSelf)
            {
                result = gameObject;
                break;
            }
        }

        if (result == null)
        {
            result = Instantiate(prefab);
            entry.list.Add(result);
        }

        result.SetActive(true);

        return(result);
    }
 public override void ReleaseRow(PoolEntry <object[]> row)
 {
     _rowsPool.Release(row);
 }
 private void InsertArray(object[] obj, PoolEntry <object[]> .PoolEntryDelegate onReleaseOne)
 {
     WaitForPumpStartAndSourceAdapterPrepared();
     _blockingQueueSourceAdapter.Insert(obj, onReleaseOne);
 }
Esempio n. 30
0
 public void AddFrame(PoolEntry <ushort> depth, PoolEntry <byte> color)
 {
     Frames.Enqueue(depth);
     ColorFrames.Enqueue(color);
 }