-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventQueue.cs
40 lines (32 loc) · 861 Bytes
/
EventQueue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
namespace MelonECS
{
public interface IEventQueue
{
void Clear();
int Count { get; }
}
public class EventQueue<T> : IEventQueue where T : struct
{
public int Count { get; private set; }
private T[] events = new T[1];
public void Push(T evt)
{
if (Count >= events.Length)
{
var temp = new T[events.Length * 2];
Array.Copy(events, temp, events.Length);
events = temp;
}
events[Count] = evt;
Count++;
}
public void Clear()
{
for (int i = 0; i < Count; i++)
events[i] = default;
Count = 0;
}
public ArrayRef<T> Read() => new ArrayRef<T>(events, 0, Count);
}
}