Restructure event/container system.
This commit is contained in:
@@ -11,31 +11,27 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
Dictionary<EventContainer, ContainerState> states
|
||||
= new Dictionary<EventContainer, ContainerState>();
|
||||
HashSet<EventContainer> activeContainers
|
||||
= new HashSet<EventContainer>();
|
||||
HashSet<ContainerState> workingStates
|
||||
HashSet<ContainerState> activeStates
|
||||
= new HashSet<ContainerState>();
|
||||
HashSet<ContainerState> invalidatedStates
|
||||
= new HashSet<ContainerState>();
|
||||
public int ActiveStateCount { get { return activeStates.Count; } }
|
||||
|
||||
public EventBus(ContainerState root, List<EventBatch> b) : base(b) {
|
||||
RootState = root;
|
||||
Expand();
|
||||
AttachBus();
|
||||
RootState.Working = true;
|
||||
}
|
||||
|
||||
public EventBus Clone(byte ct, float offsetTime = 0) {
|
||||
var r = (EventBus)MemberwiseClone();
|
||||
r.prototype = this;
|
||||
r.states = new Dictionary<EventContainer, ContainerState>();
|
||||
r.activeContainers = new HashSet<EventContainer>();
|
||||
r.workingStates = new HashSet<ContainerState>();
|
||||
r.activeStates = new HashSet<ContainerState>();
|
||||
r.invalidatedStates = new HashSet<ContainerState>();
|
||||
r.tempEvents = new List<StampedEvent>();
|
||||
r.tempEvents = new List<StampedEvent.Temporary>();
|
||||
r.Time += offsetTime;
|
||||
r.RootState = RootState.Clone(ct);
|
||||
r.RootState.StartUpdate();
|
||||
r.Expand();
|
||||
r.AttachBus();
|
||||
foreach (var s in r.states) r.invalidatedStates.Add(s.Value);
|
||||
@@ -45,18 +41,9 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
public void CopyTo(byte ct, EventBus dest) {
|
||||
base.CopyTo(dest);
|
||||
dest.workingStates.Clear();
|
||||
dest.activeStates.Clear();
|
||||
dest.invalidatedStates.Clear();
|
||||
RootState.CopyTo(ct, dest.RootState);
|
||||
if (ct >= 2) {
|
||||
dest.activeContainers.Clear();
|
||||
foreach (var c in activeContainers) {
|
||||
if (states[c].Working) {
|
||||
states[c].CopyTo(ct, dest.states[c]);
|
||||
dest.activeContainers.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
dest.ValidateStates();
|
||||
}
|
||||
|
||||
@@ -67,7 +54,7 @@ namespace Cryville.Crtr.Event {
|
||||
RootState.DisposeAll();
|
||||
}
|
||||
|
||||
public void NotifyWorkingChanged(ContainerState state) {
|
||||
public void NotifyActiveChanged(ContainerState state) {
|
||||
if (!invalidatedStates.Contains(state)) invalidatedStates.Add(state);
|
||||
}
|
||||
|
||||
@@ -86,22 +73,6 @@ namespace Cryville.Crtr.Event {
|
||||
s.Bus = this;
|
||||
}
|
||||
|
||||
void EnsureActivity(EventContainer c) {
|
||||
if (activeContainers.Contains(c)) return;
|
||||
var state = states[c];
|
||||
if (state.Parent != null) EnsureActivity(state.Parent.Container);
|
||||
if (RootState.CloneType >= 2) prototype.states[c].CopyTo(RootState.CloneType, state);
|
||||
state.Active = true;
|
||||
activeContainers.Add(c);
|
||||
|
||||
if (state.StampedContainer.Coevents == null) return;
|
||||
foreach (var cev in state.StampedContainer.Coevents) {
|
||||
if (cev.Container == null) continue;
|
||||
EnsureActivity(cev.Container);
|
||||
states[cev.Container].Handle(cev);
|
||||
}
|
||||
}
|
||||
|
||||
void AttachBus() {
|
||||
foreach (var s in states.Values)
|
||||
s.Bus = this;
|
||||
@@ -145,18 +116,26 @@ namespace Cryville.Crtr.Event {
|
||||
double time0 = Math.Min(time1, time2);
|
||||
if (time0 <= toTime && time0 != double.PositiveInfinity) {
|
||||
Time = time0;
|
||||
foreach (var s in workingStates) s.Handle(null);
|
||||
foreach (var s in activeStates) s.Handle(null);
|
||||
ValidateStates();
|
||||
if (time1 == time0) {
|
||||
var batch = Events[EventId];
|
||||
for (var i = 0; i < batch.Count; i++) {
|
||||
var ev = batch[i];
|
||||
if (ev.Container != null) {
|
||||
if (ev.Unstamped is EventContainer) EnsureActivity((EventContainer)ev.Unstamped);
|
||||
else EnsureActivity(ev.Container);
|
||||
if (ev is StampedEvent.ClipBehind) {
|
||||
var cevs = ev.Origin.Coevents;
|
||||
if (cevs != null) foreach (var cev in cevs) {
|
||||
if (cev.Container == null) continue;
|
||||
states[cev.Container].Handle(cev);
|
||||
}
|
||||
states[(EventContainer)ev.Origin.Unstamped].PhysicalActive = true;
|
||||
}
|
||||
else if (ev is StampedEvent.ClipAhead) {
|
||||
states[(EventContainer)ev.Origin.Unstamped].PhysicalActive = false;
|
||||
}
|
||||
else if (ev.Container != null) {
|
||||
states[ev.Container].Handle(ev);
|
||||
}
|
||||
else if (ev.Coevents != null) EnsureActivity((EventContainer)ev.Unstamped);
|
||||
}
|
||||
EventId++;
|
||||
}
|
||||
@@ -165,25 +144,23 @@ namespace Cryville.Crtr.Event {
|
||||
var ev = tempEvents[0];
|
||||
if (ev.Time != time0) break;
|
||||
if (ev.Container != null) {
|
||||
EnsureActivity(ev.Container);
|
||||
states[ev.Container].Handle(ev);
|
||||
}
|
||||
tempEvents.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
ValidateStates();
|
||||
}
|
||||
else {
|
||||
Time = toTime;
|
||||
foreach (var s in workingStates) s.Handle(null);
|
||||
ValidateStates();
|
||||
foreach (var s in activeStates) s.Handle(null);
|
||||
}
|
||||
ValidateStates();
|
||||
}
|
||||
|
||||
private void ValidateStates() {
|
||||
foreach (var s in invalidatedStates)
|
||||
if (s.Working && !workingStates.Contains(s)) workingStates.Add(s);
|
||||
else if (!s.Working && workingStates.Contains(s)) workingStates.Remove(s);
|
||||
if (s.Active && !activeStates.Contains(s)) activeStates.Add(s);
|
||||
else if (!s.Active && activeStates.Contains(s)) activeStates.Remove(s);
|
||||
invalidatedStates.Clear();
|
||||
}
|
||||
|
||||
@@ -194,8 +171,11 @@ namespace Cryville.Crtr.Event {
|
||||
RootState.BroadcastPostInit();
|
||||
}
|
||||
|
||||
public void BroadcastEndUpdate() {
|
||||
RootState.BroadcastEndUpdate();
|
||||
public void EndPreGraphicalUpdate() {
|
||||
RootState.EndPreGraphicalUpdate();
|
||||
}
|
||||
public void EndGraphicalUpdate() {
|
||||
RootState.EndGraphicalUpdate();
|
||||
foreach (var ev in tempEvents) {
|
||||
if (ev.Container != null) {
|
||||
states[ev.Container].Discard(ev);
|
||||
|
Reference in New Issue
Block a user