Example #1
0
        /// <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 (_timeQueue.TryNextEventTime(out timespan))
                {
                    OnSimulationTimeProgress(timespan);
                    simulatedTime += timespan;
                }
                else
                {
                    _phase = SchedulerPhase.Idle;
                    return(TimeSpan.MinValue);
                }
            }

            while (_deltaEvents.Count > 0)
            {
                SignalEventItem item = _deltaEvents.Pop();
                if (item.SetValue(item.NewValue))
                {
                    _eventSignals.Add(item);
                }
            }

            _phase = SchedulerPhase.Idle;
            return(simulatedTime);
        }
Example #2
0
        public void handleDrawFrame()
        {
            D.assert(this._schedulerPhase == SchedulerPhase.midFrameMicrotasks);

            try {
                this._schedulerPhase = SchedulerPhase.persistentCallbacks;
                foreach (FrameCallback callback in this._persistentCallbacks)
                {
                    this._invokeFrameCallback(callback, this._currentFrameTimeStamp.Value);
                }

                this._schedulerPhase = SchedulerPhase.postFrameCallbacks;
                var localPostFrameCallbacks = new List <FrameCallback>(this._postFrameCallbacks);
                this._postFrameCallbacks.Clear();
                foreach (FrameCallback callback in localPostFrameCallbacks)
                {
                    this._invokeFrameCallback(callback, this._currentFrameTimeStamp.Value);
                }
            }
            finally {
                this._schedulerPhase = SchedulerPhase.idle;
                D.assert(() => {
                    if (D.debugPrintEndFrameBanner)
                    {
                        Debug.Log(new string('▀', this._debugBanner.Length));
                    }

                    this._debugBanner = null;
                    return(true);
                });
                this._currentFrameTimeStamp = null;
            }
        }
Example #3
0
 private void RunProcessExecutionPhase()
 {
     _phase = SchedulerPhase.ProcessExecution;
     foreach (SignalEventItem item in _eventSignals)
     {
         item.SetEventFlag(true);
     }
     foreach (SignalEventItem item in _eventSignals)
     {
         item.NotifyNewValue();
     }
     foreach (SignalEventItem item in _eventSignals)
     {
         item.SetEventFlag(false);
     }
     _eventSignals.Clear();
     _phase = SchedulerPhase.Idle;
 }
Example #4
0
 private void RunProcessExecutionPhase()
 {
     _phase = SchedulerPhase.ProcessExecution;
     foreach (ISchedulable item in _schedulablesWithEvent)
     {
         item.HasEvent = true;
     }
     foreach (ISchedulable item in _schedulablesWithEvent)
     {
         item.NotifyOutputsNewValue();
     }
     foreach (ISchedulable item in _schedulablesWithEvent)
     {
         item.HasEvent = false;
     }
     _schedulablesWithEvent.Clear();
     _phase = SchedulerPhase.Idle;
 }
        /// <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?
                }
            }

            if (_deltaEvents.Count > 0)
            {
                int index = _random.Next(_deltaEvents.Count);
                SchedulerEventItem item = _deltaEvents[index];
                _deltaEvents.RemoveAt(index);

                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);
        }
Example #6
0
        public void handleBeginFrame(TimeSpan?rawTimeStamp)
        {
            this._firstRawTimeStampInEpoch = this._firstRawTimeStampInEpoch ?? rawTimeStamp;
            this._currentFrameTimeStamp    = this._adjustForEpoch(rawTimeStamp ?? this._lastRawTimeStamp);

            if (rawTimeStamp != null)
            {
                this._lastRawTimeStamp = rawTimeStamp.Value;
            }

            D.assert(() => {
                this._profileFrameNumber += 1;
                return(true);
            });

            D.assert(() => {
                if (D.debugPrintBeginFrameBanner || D.debugPrintEndFrameBanner)
                {
                    var frameTimeStampDescription = new StringBuilder();
                    if (rawTimeStamp != null)
                    {
                        _debugDescribeTimeStamp(
                            this._currentFrameTimeStamp.Value, frameTimeStampDescription);
                    }
                    else
                    {
                        frameTimeStampDescription.Append("(warm-up frame)");
                    }

                    this._debugBanner =
                        $"▄▄▄▄▄▄▄▄ Frame {this._profileFrameNumber.ToString().PadRight(7)}   {frameTimeStampDescription.ToString().PadLeft(18)} ▄▄▄▄▄▄▄▄";
                    if (D.debugPrintBeginFrameBanner)
                    {
                        Debug.Log(this._debugBanner);
                    }
                }

                return(true);
            });

            D.assert(this._schedulerPhase == SchedulerPhase.idle);
            this._hasScheduledFrame = false;

            try {
                this._schedulerPhase = SchedulerPhase.transientCallbacks;
                var callbacks = this._transientCallbacks;
                this._transientCallbacks = new Dictionary <int, _FrameCallbackEntry>();
                foreach (var entry in callbacks)
                {
                    if (!this._removedIds.Contains(entry.Key))
                    {
                        this._invokeFrameCallback(
                            entry.Value.callback, this._currentFrameTimeStamp.Value, entry.Value.debugStack);
                    }
                }

                this._removedIds.Clear();
            }
            finally {
                this._schedulerPhase = SchedulerPhase.midFrameMicrotasks;
            }
        }
        /// <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;
        }
 private void RunProcessExecutionPhase()
 {
     _phase = SchedulerPhase.ProcessExecution;
     foreach(ISchedulable item in _schedulablesWithEvent)
         item.HasEvent = true;
     foreach(ISchedulable item in _schedulablesWithEvent)
         item.NotifyOutputsNewValue();
     foreach(ISchedulable item in _schedulablesWithEvent)
         item.HasEvent = false;
     _schedulablesWithEvent.Clear();
     _phase = SchedulerPhase.Idle;
 }
Example #9
0
        /// <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(_timeQueue.TryNextEventTime(out timespan))
                {
                    OnSimulationTimeProgress(timespan);
                    simulatedTime += timespan;
                }
                else
                {
                    _phase = SchedulerPhase.Idle;
                    return TimeSpan.MinValue;
                }
            }

            while(_deltaEvents.Count > 0)
            {
                SignalEventItem item = _deltaEvents.Pop();
                if(item.SetValue(item.NewValue))
                    _eventSignals.Add(item);
            }

            _phase = SchedulerPhase.Idle;
            return simulatedTime;
        }
Example #10
0
 private void RunProcessExecutionPhase()
 {
     _phase = SchedulerPhase.ProcessExecution;
     foreach(SignalEventItem item in _eventSignals)
         item.SetEventFlag(true);
     foreach(SignalEventItem item in _eventSignals)
         item.NotifyNewValue();
     foreach(SignalEventItem item in _eventSignals)
         item.SetEventFlag(false);
     _eventSignals.Clear();
     _phase = SchedulerPhase.Idle;
 }