public void Update(double deltaTime)
{
lock (_lock)
{
_epochTime += deltaTime;
ScheduledAction lastExecutedSurvivor = null;
for (var action = _first; action != null; action = action.NextAction)
{
if (_epochTime < action.NextExecutionEpoch)
break;
action.Execute();
if (!action.IsCanceled)
{
lastExecutedSurvivor = action;
}
}
for (var action = lastExecutedSurvivor; action != null; )
{
// note: unfortunately this is a bit fragile: Move will change the
// predecessor of the moved node so back iteration in the above loop
// breaks when we dont store the prev action here
var prevAction = action.PrevAction;
var nextAction = action.NextAction;
if (nextAction != null)
{
var predecessor = TryFindPredecessor(action, startWith: nextAction);
if (predecessor != null)
{
Remove(action);
MoveBehind(action, predecessor);
}
}
action = prevAction;
}
}
}