resizeable message store

pull/3/head
Evan Hemsley 2020-03-22 16:07:58 -07:00
parent 5bc0294158
commit e4d4df9fdd
1 changed files with 5 additions and 1 deletions

View File

@ -14,7 +14,7 @@ namespace Encompass
// messages are placed in a contiguous region
// so we can return the collection as a Span
private int _nextIndex = 0;
private readonly TMessage[] _store = new TMessage[128];
private TMessage[] _store = new TMessage[128];
private readonly List<(TMessage, double)> _delayedStore = new List<(TMessage, double)>(128);
private readonly List<(TMessage, double)> _delayedStoreIgnoringTimeDilation = new List<(TMessage, double)>(128);
private readonly Dictionary<int, List<int>> _entityToIndices = new Dictionary<int, List<int>>();
@ -59,6 +59,10 @@ namespace Encompass
public void Add(in TMessage message)
{
var index = _nextIndex++;
if (index >= _store.Length)
{
Array.Resize(ref _store, _store.Length * 2);
}
_store[index] = message;
if (message is IHasEntity entityMessage)
{