Implement temporary event injection.
This commit is contained in:
@@ -542,8 +542,6 @@ namespace Cryville.Crtr {
|
||||
using (var pbus = cbus.Clone(16)) {
|
||||
pbus.Forward();
|
||||
}
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Patching events");
|
||||
cbus.DoPatch();
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)");
|
||||
bbus = cbus.Clone(1, -clippingDist);
|
||||
|
@@ -99,39 +99,46 @@ namespace Cryville.Crtr.Event {
|
||||
s.AttachSystems(skin, judge);
|
||||
}
|
||||
|
||||
readonly List<StampedEvent> patch = new List<StampedEvent>();
|
||||
public void IssuePatch(IEnumerable<StampedEvent> l) {
|
||||
patch.AddRange(l);
|
||||
}
|
||||
public void DoPatch() {
|
||||
foreach (var ev in patch) {
|
||||
var batch = new EventBatch(ev.Time);
|
||||
var batchIndex = events.BinarySearch(batch);
|
||||
if (batchIndex >= 0) batch = events[batchIndex];
|
||||
else events.Insert(~batchIndex, batch);
|
||||
batch.Add(ev);
|
||||
}
|
||||
patch.Clear();
|
||||
readonly List<StampedEvent> tempEvents = new List<StampedEvent>();
|
||||
public void PushTempEvent(StampedEvent ev) {
|
||||
var index = tempEvents.BinarySearch(ev);
|
||||
if (index < 0) index = ~index;
|
||||
tempEvents.Insert(index, ev);
|
||||
}
|
||||
|
||||
public override void ForwardOnceToTime(double toTime, Action<EventBatch> callback = null) {
|
||||
if (EventId < events.Count && events[EventId].Time <= toTime) {
|
||||
Time = events[EventId].Time;
|
||||
var batch = events[EventId];
|
||||
double time1 = EventId < events.Count ? events[EventId].Time : double.PositiveInfinity;
|
||||
double time2 = tempEvents.Count > 0 ? tempEvents[0].Time : double.PositiveInfinity;
|
||||
double time0 = Math.Min(time1, time2);
|
||||
if (time0 <= toTime && time0 != double.PositiveInfinity) {
|
||||
Time = time0;
|
||||
foreach (var s in workingStates) s.Handle(null);
|
||||
ValidateStates();
|
||||
for (var i = 0; i < batch.Count; i++) {
|
||||
var ev = batch[i];
|
||||
if (ev.Container != null) {
|
||||
EnsureActivity(ev.Container);
|
||||
states[ev.Container].Handle(ev);
|
||||
if (time1 == time0) {
|
||||
var batch = events[EventId];
|
||||
for (var i = 0; i < batch.Count; i++) {
|
||||
var ev = batch[i];
|
||||
if (ev.Container != null) {
|
||||
EnsureActivity(ev.Container);
|
||||
states[ev.Container].Handle(ev);
|
||||
}
|
||||
if (ev.Unstamped is EventContainer) {
|
||||
if (ev.Container != null) EnsureActivity((EventContainer)ev.Unstamped);
|
||||
}
|
||||
}
|
||||
if (ev.Unstamped is EventContainer) {
|
||||
if (ev.Container != null) EnsureActivity((EventContainer)ev.Unstamped);
|
||||
EventId++;
|
||||
}
|
||||
if (time2 == time0) {
|
||||
while (tempEvents.Count > 0) {
|
||||
var ev = tempEvents[0];
|
||||
if (ev.Container != null) {
|
||||
EnsureActivity(ev.Container);
|
||||
states[ev.Container].Handle(ev);
|
||||
}
|
||||
tempEvents.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
ValidateStates();
|
||||
EventId++;
|
||||
}
|
||||
else {
|
||||
Time = toTime;
|
||||
@@ -156,6 +163,7 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
public void BroadcastEndUpdate() {
|
||||
RootState.BroadcastEndUpdate();
|
||||
tempEvents.Clear();
|
||||
}
|
||||
|
||||
public void Anchor() {
|
||||
|
Reference in New Issue
Block a user