/// <summary>
 /// Read the data at current cursor on the ring buffer then move forward by 1.
 ///
 /// If too many touches had passed that it loops over the ring buffer and overwritten your current cursor position,
 /// this read automatically change the cursor to be the earliest touch and start from there.
 /// </summary>
 /// <param name="ntd">When returning `false`, this is a `default` value and should not be used.</param>
 /// <returns>`true` when there is a remaining touch to get. This is to be used with `while` loop.</returns>
 /// <exception cref="InvalidOperationException">Thrown when you use this while in <see cref="NativeTouch.StartOption.fullMode">.</exception>
 public bool TryGetAndMoveNext(out NativeTouchData ntd)
 {
     if (NativeTouch.IsFullMode)
     {
         throw new InvalidOperationException("You cannot TryGetAndMoveNext() while Native Touch is in full mode. Use TryGetAndMoveNextFull() instead.");
     }
     EnterCriticalSection();
     CatchUpIfRequired();
     //Debug.Log($"{currentCursor} vs {NativeTouch.finalCursor}");
     if (currentCursor < NativeTouch.finalCursor)
     {
         int getIndex = currentCursor % NativeTouch.activeRingBufferSize;
         ntd = NativeTouch.ntdRingBuffer[getIndex];
         //Debug.Log($"Dequeued {ntd} at {getIndex}");
         ExitCriticalSection();
         currentCursor++;
         return(true);
     }
     else
     {
         ExitCriticalSection();
         ntd = default(NativeTouchData);
         return(false);
     }
 }
Beispiel #2
0
        internal static void NativeTouchMinimalCallback(NativeTouchData ntd)
        {
            switch (ntd.CallbackType)
            {
            case TouchPhase.Began: minimalCallbacksBegan.Invoke(ntd); break;

            case TouchPhase.Ended: minimalCallbacksEnded.Invoke(ntd); break;

            case TouchPhase.Canceled: minimalCallbacksCancelled.Invoke(ntd); break;

            case TouchPhase.Moved: minimalCallbacksMoved.Invoke(ntd); break;
            }
        }
Beispiel #3
0
        internal static void NativeTouchMinimalCallbackRingBuffer(int start, int count)
        {
            int currentIndex = start;

            do
            {
                //No mutex is required for this read, since this continues immediately after the native side itself writes. No one else could be writing at this moment.
                NativeTouchData ntd = NativeTouch.ntdRingBuffer[currentIndex];

                switch (ntd.CallbackType)
                {
                case TouchPhase.Began: minimalCallbacksBegan.Invoke(ntd); break;

                case TouchPhase.Ended: minimalCallbacksEnded.Invoke(ntd); break;

                case TouchPhase.Canceled: minimalCallbacksCancelled.Invoke(ntd); break;

                case TouchPhase.Moved: minimalCallbacksMoved.Invoke(ntd); break;
                }

                currentIndex = (currentIndex + 1) % NativeTouch.activeRingBufferSize;
                count--;
            }while (count > 0);
        }