public void ProgressTime(TimeSpan timespan, IScheduler scheduler) { foreach (KeyValuePair <Guid, LinkedList <SchedulerEventItem> > schedulable in _delayedEvents) { TimeSpan span = timespan; LinkedList <SchedulerEventItem> timeline = schedulable.Value; while (timeline.First != null && span >= TimeSpan.Zero) { SchedulerEventItem item = timeline.First.Value; item.TimeSpan -= span; span = -item.TimeSpan; if (item.TimeSpan <= TimeSpan.Zero) { scheduler.ScheduleDeltaEvent(item.Subject, item.Value); timeline.RemoveFirst(); } } } }
/// <returns> /// The simulated time. /// TimeSpan.Zero if no time progress was achieved due to delta events. /// TimeSpan.MinValue if no events were available. /// </returns> private TimeSpan RunSignalAssignmentPhase(bool progressTime) { _phase = SchedulerPhase.SignalAssignment; TimeSpan simulatedTime = TimeSpan.Zero; while (progressTime && _deltaEvents.Count == 0) { TimeSpan timespan; if (_timeline.TryNextEventTime(out timespan)) { _schedule.ProgressTime(timespan, this); OnSimulationTimeProgress(timespan); simulatedTime += timespan; } else { _phase = SchedulerPhase.Idle; return(TimeSpan.MinValue); // TODO: check, why MinValue? } } while (_deltaEvents.Count > 0) { SchedulerEventItem item = _deltaEvents.Pop(); ISchedulable subject = item.Subject; if (subject.CurrentValue == null || !subject.CurrentValue.Equals(item.Value)) { item.Subject.CurrentValue = item.Value; _schedulablesWithEvent.Add(item.Subject); } } _phase = SchedulerPhase.Idle; return(simulatedTime); }