Пример #1
0
        public ClockState Tick(TimeSpan time)
        {
            ClockState state = clock.Tick(time - offset);

            TimeSpan previousTick = state.PreviousTick == Granular.Compatibility.TimeSpan.MinValue ? Granular.Compatibility.TimeSpan.MinValue : offset + state.PreviousTick;
            TimeSpan nextTick     = state.NextTick == Granular.Compatibility.TimeSpan.MaxValue ? Granular.Compatibility.TimeSpan.MaxValue : offset + state.NextTick;

            return(new ClockState(state.ProgressState, state.Progress, state.Iteration, previousTick, nextTick));
        }
Пример #2
0
        public ClockState Tick(TimeSpan time)
        {
            ClockState state = clock.Tick(time - beginTime);

            TimeSpan previousTick = state.PreviousTick == Granular.Compatibility.TimeSpan.MinValue ? Granular.Compatibility.TimeSpan.MinValue : beginTime + state.PreviousTick;
            TimeSpan nextTick     = state.NextTick == Granular.Compatibility.TimeSpan.MaxValue ? Granular.Compatibility.TimeSpan.MaxValue : beginTime + state.NextTick;

            this.CurrentState = new ClockState(state.ProgressState, state.Progress, state.Iteration, previousTick, nextTick);

            Invalidated.Raise(this);

            return(CurrentState);
        }
Пример #3
0
        public ClockState Tick(TimeSpan time)
        {
            if (time < FirstTick)
            {
                CurrentState = new ClockState(ClockProgressState.BeforeStarted, 0, 0, Granular.Compatibility.TimeSpan.MinValue, FirstTick);
            }
            else if (time < LastTick)
            {
                CurrentState = new ClockState(ClockProgressState.Active, (time - FirstTick).Divide(LastTick - FirstTick), 0, time, time);
            }
            else
            {
                CurrentState = new ClockState(ClockProgressState.AfterEnded, 1, 0, LastTick, Granular.Compatibility.TimeSpan.MaxValue);
            }

            return CurrentState;
        }
Пример #4
0
        public ClockState Tick(TimeSpan time)
        {
            ClockProgressState progressState;

            if (time < FirstTick)
            {
                progressState = ClockProgressState.BeforeStarted;
            }
            else if (time < LastTick)
            {
                progressState = ClockProgressState.Active;
            }
            else
            {
                progressState = ClockProgressState.AfterEnded;
            }

            TimeSpan previousTick  = Granular.Compatibility.TimeSpan.MinValue;
            TimeSpan nextTick      = Granular.Compatibility.TimeSpan.MaxValue;
            TimeSpan totalDuration = TimeSpan.Zero;

            foreach (IClock clock in clocks)
            {
                ClockState state = clock.Tick(time - totalDuration);

                if (state.PreviousTick != Granular.Compatibility.TimeSpan.MinValue)
                {
                    previousTick = previousTick.Max(state.PreviousTick + totalDuration);
                }

                if (state.NextTick != Granular.Compatibility.TimeSpan.MaxValue)
                {
                    nextTick = nextTick.Min(state.NextTick + totalDuration);
                }

                totalDuration += clock.Duration;
            }

            return(new ClockState(progressState, 0, 0, previousTick, nextTick));
        }
Пример #5
0
        public ClockState Tick(TimeSpan time)
        {
            if (time < TimeSpan.Zero)
            {
                ClockState state = clock.Tick(TimeSpan.Zero);

                TimeSpan previousTick = Granular.Compatibility.TimeSpan.MinValue;
                TimeSpan nextTick     = TimeSpan.Zero;

                return(new ClockState(ClockProgressState.BeforeStarted, state.Progress, state.Iteration, previousTick, nextTick));
            }

            if (time >= Duration)
            {
                ClockState state = clock.Tick(Duration);

                TimeSpan previousTick = Duration;
                TimeSpan nextTick     = Granular.Compatibility.TimeSpan.MaxValue;

                return(new ClockState(ClockProgressState.AfterEnded, state.Progress, state.Iteration, previousTick, nextTick));
            }

            return(clock.Tick(time));
        }
Пример #6
0
            public void Tick(TimeSpan time)
            {
                ClockState state = Clock.Tick(time);

                NextTick = state.NextTick;
            }
Пример #7
0
        public ClockState Tick(TimeSpan time)
        {
            double iteration = time.Divide(iterationDuration);

            ClockProgressState progressState = time < FirstTick ? ClockProgressState.BeforeStarted : (time >= LastTick ? ClockProgressState.AfterEnded : ClockProgressState.Active);

            iteration = Math.Min(Math.Max(iteration, 0), iterationsCount);

            double iterationRemainder = iteration - Math.Floor(iteration);

            TimeSpan currentIterationStart;
            TimeSpan currentIterationTime;

            if (progressState == ClockProgressState.AfterEnded && iterationRemainder == 0)
            {
                currentIterationStart = iterationDuration.Scale(iteration - 1);
                currentIterationTime  = iterationDuration;
            }
            else
            {
                currentIterationStart = iterationDuration.Scale(iteration - iterationRemainder);
                currentIterationTime  = iterationDuration.Scale(iterationRemainder);
            }

            ClockState state = clock.Tick(currentIterationTime);

            TimeSpan previousTick;
            TimeSpan nextTick;

            if (time < FirstTick)
            {
                previousTick = Granular.Compatibility.TimeSpan.MinValue;
                nextTick     = FirstTick;
            }
            else if (time >= LastTick)
            {
                previousTick = LastTick;
                nextTick     = Granular.Compatibility.TimeSpan.MaxValue;
            }
            else
            {
                if (currentIterationTime > clock.FirstTick || Math.Floor(iteration) == 0)
                {
                    previousTick = (currentIterationStart + state.PreviousTick).Max(FirstTick);
                }
                else
                {
                    previousTick = (currentIterationStart - iterationDuration + clock.LastTick).Max(FirstTick);
                }

                if (currentIterationTime < clock.LastTick || Math.Floor(iteration) == Math.Floor(iterationsCount))
                {
                    nextTick = (currentIterationStart + state.NextTick).Min(LastTick);
                }
                else
                {
                    nextTick = (currentIterationStart + iterationDuration + clock.FirstTick).Min(LastTick);
                }
            }

            if (progressState == ClockProgressState.Active)
            {
                progressState = state.ProgressState;
            }

            return(new ClockState(progressState, state.Progress, iteration, previousTick, nextTick));
        }
Пример #8
0
 internal void StepTime(int milliseconds)
 {
     if (myClockState != ClockState.Active)
         return;
     myCurrentGlobalTime += milliseconds;
     OnClockChanged();
     if (myCurrentGlobalTime >= myTotalTime)
     {
         myClockState = ClockState.Stopped;
         mySystem.RemoveClock(this);
     }
 }