コード例 #1
0
ファイル: ActivePath.cs プロジェクト: Jeffersah/FP1
        /// <summary>
        /// Create an active path from a path
        /// </summary>
        /// <param name="p">The path</param>
        /// <returns>The active path</returns>
        public static ActivePath MakeActive(Path p)
        {
            ActivePath np = new ActivePath();

            np.path             = p.GetPath();
            np.currentlyReached = null;
            np.isPathDone       = false;
            return(np);
        }
コード例 #2
0
 private void ElapsedInt(ulong millSinceBeginning = 0)
 {
     while (true)
     {
         lock (_tempPaths)
         {
             if (_tempPaths != null && ActivePath == null && _tempPaths.Count > 0)
             {
                 while (ActivePath == null)
                 {
                     if (_tempReverseRepeat)
                     {
                         ActivePath = _tempPaths.LastOrDefault();
                         _tempPaths.RemoveAt(_tempPaths.Count - 1);
                     }
                     else
                     {
                         ActivePath = _tempPaths.FirstOrDefault();
                         _tempPaths.RemoveAt(0);
                     }
                     _timer.ResetClock();
                     millSinceBeginning = 0;
                 }
             }
             var ended = ActivePath == null;
             if (ActivePath != null)
             {
                 if (!_tempReverseRepeat && millSinceBeginning < ActivePath.Delay)
                 {
                     CurrentStatus = AnimatorStatus.OnHold;
                     return;
                 }
                 if (millSinceBeginning - (!_tempReverseRepeat ? ActivePath.Delay : 0) <= ActivePath.Duration)
                 {
                     if (CurrentStatus != AnimatorStatus.Playing)
                     {
                         CurrentStatus = AnimatorStatus.Playing;
                     }
                     var value = ActivePath.Function(_tempReverseRepeat ? ActivePath.Duration - millSinceBeginning : millSinceBeginning - ActivePath.Delay, ActivePath.Start, ActivePath.Change, ActivePath.Duration);
                     FrameCallbackInt.Invoke((int)value);
                     return;
                 }
                 if (CurrentStatus == AnimatorStatus.Playing)
                 {
                     if (_tempPaths.Count == 0)
                     {
                         // For the last path, we make sure that control is in end point
                         FrameCallbackInt.Invoke(_tempReverseRepeat ? (int)ActivePath.Start : (int)ActivePath.End);
                         ended = true;
                     }
                     else
                     {
                         if ((_tempReverseRepeat && ActivePath.Delay > 0) || !_tempReverseRepeat && _tempPaths.FirstOrDefault()?.Delay > 0)
                         {
                             // Or if the next path or this one in revese order has a delay
                             FrameCallbackInt.Invoke(_tempReverseRepeat ? (int)ActivePath.Start : (int)ActivePath.End);
                         }
                     }
                 }
                 if (_tempReverseRepeat && (millSinceBeginning - ActivePath.Duration) < ActivePath.Delay)
                 {
                     CurrentStatus = AnimatorStatus.OnHold;
                     return;
                 }
                 ActivePath = null;
             }
             if (!ended)
             {
                 return;
             }
         }
         if (Repeat)
         {
             lock (_tempPaths)
             {
                 _tempPaths.AddRange(_paths);
                 _tempReverseRepeat = ReverseRepeat && !_tempReverseRepeat;
             }
             millSinceBeginning = 0;
             continue;
         }
         Stop();
         EndCallback?.Invoke();
         break;
     }
 }
コード例 #3
0
 private void Elapsed(ulong millSinceBeginning)
 {
     lock (_tempPaths)
     {
         if (_tempPaths != null && ActivePath == null && _tempPaths.Count > 0)
         {
             while (ActivePath == null)
             {
                 if (_tempReverseRepeat)
                 {
                     ActivePath = _tempPaths.LastOrDefault();
                     _tempPaths.RemoveAt(_tempPaths.Count - 1);
                 }
                 else
                 {
                     ActivePath = _tempPaths.FirstOrDefault();
                     _tempPaths.RemoveAt(0);
                 }
                 _timer.ResetClock();
                 millSinceBeginning = 0;
             }
         }
         if (ActivePath != null)
         {
             if (!_tempReverseRepeat && millSinceBeginning < ActivePath.Delay)
             {
                 CurrentStatus = AnimatorStatus.OnHold;
                 return;
             }
             if (millSinceBeginning - (!_tempReverseRepeat ? ActivePath.Delay : 0) <= ActivePath.Duration)
             {
                 if (CurrentStatus != AnimatorStatus.Playing)
                 {
                     FrameCallback.Invoke(_tempReverseRepeat ? ActivePath.End : ActivePath.Start);
                     CurrentStatus = AnimatorStatus.Playing;
                 }
                 var value = ActivePath.Function(
                     _tempReverseRepeat
                         ? ActivePath.Duration - millSinceBeginning
                         : millSinceBeginning - ActivePath.Delay,
                     ActivePath.Start,
                     ActivePath.Change,
                     ActivePath.Duration);
                 FrameCallback.Invoke(value);
                 return;
             }
             if (CurrentStatus == AnimatorStatus.Playing)
             {
                 FrameCallback.Invoke(_tempReverseRepeat ? ActivePath.Start : ActivePath.End);
             }
             if (_tempReverseRepeat && (millSinceBeginning - ActivePath.Duration) < ActivePath.Delay)
             {
                 CurrentStatus = AnimatorStatus.OnHold;
                 return;
             }
             ActivePath = null;
         }
         else if (Repeat)
         {
             lock (_tempPaths)
             {
                 _tempPaths.AddRange(_paths);
                 _tempReverseRepeat = ReverseRepeat && !_tempReverseRepeat;
             }
         }
         else
         {
             Stop();
             EndCallback?.Invoke();
         }
     }
 }