Modify priority logic for normal/temporary events.

This commit is contained in:
2023-02-09 18:22:39 +08:00
parent 314cdb9935
commit c04e50e959

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace Cryville.Crtr.Event {
public class EventBus : StateBase<EventBatch>, IDisposable {
@@ -120,6 +121,7 @@ namespace Cryville.Crtr.Event {
var batch = Events[EventId];
for (var i = 0; i < batch.Count; i++) {
var ev = batch[i];
HandleTempEvents(time0, ev.Priority);
if (ev is StampedEvent.ClipBehind) {
var cevs = ev.Origin.Coevents;
if (cevs != null) foreach (var cev in cevs) {
@@ -137,16 +139,7 @@ namespace Cryville.Crtr.Event {
}
EventId++;
}
if (time2 == time0) {
while (tempEvents.Count > 0) {
var ev = tempEvents[0];
if (ev.Time != time0) break;
if (ev.Container != null) {
states[ev.Container].Handle(ev);
}
tempEvents.RemoveAt(0);
}
}
HandleTempEvents(time0);
}
else {
Time = toTime;
@@ -154,6 +147,17 @@ namespace Cryville.Crtr.Event {
}
ValidateStates();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void HandleTempEvents(double time, int maxPriority = int.MaxValue) {
while (tempEvents.Count > 0) {
var ev2 = tempEvents[0];
if (ev2.Time != time || ev2.Priority >= maxPriority) break;
if (ev2.Container != null) {
states[ev2.Container].Handle(ev2);
}
tempEvents.RemoveAt(0);
}
}
private void ValidateStates() {
foreach (var s in invalidatedStates)