Add project files.
This commit is contained in:
47
Assets/Cryville/Crtr/Event/EventBatch.cs
Normal file
47
Assets/Cryville/Crtr/Event/EventBatch.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Crtr.Event {
|
||||
public class EventBatch : IComparable<EventBatch>, IEnumerable<StampedEvent> {
|
||||
public float Time {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
readonly List<StampedEvent> queue = new List<StampedEvent>();
|
||||
public int Count {
|
||||
get { return queue.Count; }
|
||||
}
|
||||
|
||||
public EventBatch(float time) {
|
||||
Time = time;
|
||||
}
|
||||
|
||||
public StampedEvent this[int index] {
|
||||
get { return queue[index]; }
|
||||
}
|
||||
|
||||
public void Add(StampedEvent ev) {
|
||||
Enqueue(ev);
|
||||
}
|
||||
|
||||
public void Enqueue(StampedEvent ev) {
|
||||
int i = queue.BinarySearch(ev);
|
||||
if (i < 0) queue.Insert(~i, ev);
|
||||
}
|
||||
|
||||
public int CompareTo(EventBatch other) {
|
||||
return this.Time.CompareTo(other.Time);
|
||||
}
|
||||
|
||||
public IEnumerator<StampedEvent> GetEnumerator() {
|
||||
return queue.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user