1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-01 05:45:59 +02:00

Beefy2D updates, file pack support

This commit is contained in:
Brian Fiete 2025-01-17 10:15:47 -08:00
parent 2131d97756
commit 2e40bab705
5 changed files with 946 additions and 4 deletions

View file

@ -0,0 +1,60 @@
using System.Collections;
namespace utils;
class StableIndexedList<T>
{
public List<T> mList = new .() ~ delete _;
public List<int32> mFreeIndices = new .() ~ delete _;
public this()
{
mList.Add(default); // Reserve idx 0
}
public ref T this[int idx]
{
get
{
return ref mList[idx];
}
set
{
mList[idx] = value;
}
}
public int Add(T val)
{
if (!mFreeIndices.IsEmpty)
{
int32 idx = mFreeIndices.PopBack();
mList[idx] = val;
return idx;
}
mList.Add(val);
return mList.Count - 1;
}
public void RemoveAt(int idx)
{
if (idx == mList.Count - 1)
{
mList.PopBack();
}
else
{
mList[idx] = default;
mFreeIndices.Add((.)idx);
}
}
public List<T>.Enumerator GetEnumerator() => mList.GetEnumerator();
public T SafeGet(int idx)
{
if ((idx < 0) || (idx > mList.Count))
return default;
return mList[idx];
}
}