123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Veldrid.Common
- {
- public class BatchGroup
- {
- private BatchItem[] _items;
- public BatchGroup()
- {
- _items = new BatchItem[64];
- }
- public int Count { get; private set; }
- public ref BatchItem Add()
- {
- if (Count >= _items.Length)
- {
- var lastSize = _items.Length;
- var newSize = (lastSize + lastSize / 2 + 63) & (~63);
- Array.Resize(ref _items, newSize);
- }
- return ref _items[Count++];
- }
- public void Clear()
- {
- Count = 0;
- }
- public ReadOnlySpan<BatchItem> GetSpan() => new ReadOnlySpan<BatchItem>(_items, 0, Count);
- public Enumerator GetEnumerator() => new Enumerator(_items, Count);
- public struct Enumerator
- {
- private readonly BatchItem[] _items;
- private readonly int _count;
- private int _index;
- internal Enumerator(BatchItem[] items, int count)
- {
- _items = items;
- _count = count;
- _index = -1;
- }
- public BatchItem Current => _items[_index];
- public bool MoveNext()
- {
- if (_index >= _count)
- return false;
- _index++;
- return true;
- }
- public void Reset()
- {
- _index = -1;
- }
- }
- }
- }
|