internal void Update()
{
Updating = true;
if (GlobalProcessOrder != null)
{
foreach (var name in GlobalProcessOrder)
{
if (!ActiveMultiforms.ContainsKey(name))
continue;
ActiveMultiforms[name].Update();
}
}
else
{
foreach (var kvp in ActiveMultiforms)
{
kvp.Value.Update();
}
}
Updating = false;
// Apply PostUpdateEvents.
ApplyingPostUpdateEvents = true;
foreach (var evt in PostUpdateEvents)
{
evt.Perform(RegisteredMultiforms, ActiveMultiforms);
}
PostUpdateEvents.Clear();
ApplyingPostUpdateEvents = false;
// Add the queued PostUpdate events to the list of PostUpdateEvents to be performed
// next time Update is called. The reason we need this is because there are certain
// post update events that can alter the PostUpdateEvents list whilst iterating. For
// example, a PostUpdateEvent can Activate a multiform, which can in turn call something
// that adds a PostUpdateEvent to the list.
//
// Potential problem: this might cause a sort of "waterfall" effect of queued events, causing
// a number of events which were intended to happen simultaneously to happen sequentially instead.
// For example, consider a multiform, which constructs another multiform, which constructs another
// multiform in it's constructor, which does the same, and so on. Each consecutive multiform would
// be constructed the next frame.
foreach (var queuedEvt in PostUpdateEventQueue)
{
PostUpdateEvents.Add(queuedEvt);
}
PostUpdateEventQueue.Clear();
}