Code/Core/FrameList.cs

Lightweight internal collection for Frame structs. Stores frames in an array, exposes Count and indexer by ref, allows reserving a new slot with automatic resizing, and can Reset to clear used slots.

using System;

namespace Goo;

internal sealed class FrameList
{
    Frame[] _items = new Frame[4];
    int _count;
    public int Count => _count;
    public ref Frame this[int i] => ref _items[i];

    public ref Frame Reserve()
    {
        if (_count == _items.Length) Array.Resize(ref _items, _items.Length * 2);
        return ref _items[_count++];
    }

    internal void Reset()
    {
        Array.Clear(_items, 0, _count);
        _count = 0;
    }
}