private void update(IList <TouchPoint> touches, Action <Transform> process, Action <Gesture, IList <TouchPoint> > dispatch) { // WARNING! Arcane magic ahead! // gestures which got any touch points // needed because there's no order in dictionary activeGestures.Clear(); var targets = transformListPool.Get(); // arrange touch points by target var count = touches.Count; for (var i = 0; i < count; i++) { var touch = touches[i]; if (touch.Target != null) { List <TouchPoint> list; if (!targetTouches.TryGetValue(touch.Target, out list)) { list = touchListPool.Get(); targetTouches.Add(touch.Target, list); targets.Add(touch.Target); } list.Add(touch); } } // process all targets - get and sort all gestures on targets in hierarchy count = targets.Count; for (var i = 0; i < count; i++) { var target = targets[i]; process(target); touchListPool.Release(targetTouches[target]); } transformListPool.Release(targets); // dispatch gesture events with touches assigned to them count = activeGestures.Count; for (var i = 0; i < count; i++) { var gesture = activeGestures[i]; var list = gestureTouches[gesture]; if (gestureIsActive(gesture)) { dispatch(gesture, list); } touchListPool.Release(list); } targetTouches.Clear(); gestureTouches.Clear(); }
internal TouchPoint INTERNAL_BeginTouch(Vector2 position, IInputSource input, Tags tags) { TouchPoint touch; lock (touchLock) { touch = touchPointPool.Get(); touch.INTERNAL_Init(nextTouchId++, position, input, tags); touchesBegan.Add(touch); } return(touch); }
private void updateBegan(List <TouchPoint> points) { var count = points.Count; var list = touchPointListPool.Get(); for (var i = 0; i < count; i++) { var touch = points[i]; list.Add(touch); touches.Add(touch); idToTouch.Add(touch.Id, touch); for (var j = 0; j < layerCount; j++) { var touchLayer = layers[j]; if (touchLayer == null || !touchLayer.enabled) { continue; } if (touchLayer.INTERNAL_BeginTouch(touch)) { break; } } #if TOUCHSCRIPT_DEBUG addDebugFigureForTouch(touch); #endif } if (touchesBeganInvoker != null) { touchesBeganInvoker.InvokeHandleExceptions(this, TouchEventArgs.GetCachedEventArgs(list)); } touchPointListPool.Release(list); }
private void processTarget(Transform target) { var targetList = targetTouches[target]; var touchCount = targetList.Count; // gestures on objects in the hierarchy from "root" to target var list = gestureListPool.Get(); getHierarchyEndingWith(target, list); var count = list.Count; for (var i = 0; i < count; i++) { var gesture = list[i]; if (!gestureIsActive(gesture)) { continue; } var touchList = touchListPool.Get(); for (var j = 0; j < touchCount; j++) { var touch = targetList[j]; if (gesture.HasTouch(touch)) { touchList.Add(touch); } } if (touchList.Count > 0) { if (gestureTouches.ContainsKey(gesture)) { gestureTouches[gesture].AddRange(touchList); touchListPool.Release(touchList); } else { activeGestures.Add(gesture); gestureTouches.Add(gesture, touchList); } } else { touchListPool.Release(touchList); } } gestureListPool.Release(list); }
private void touchesBeganHandler(object sender, TouchEventArgs e) { if (touchProxy == null) { return; } var count = e.Touches.Count; for (var i = 0; i < count; i++) { var touch = e.Touches[i]; var proxy = pool.Get(); proxy.Size = getTouchSize(); proxy.ShowTouchId = showTouchId; proxy.ShowTags = showTags; proxy.Init(rect, touch); proxies.Add(touch.Id, proxy); } }
private void updateTouches() { if (frameStartedInvoker != null) { frameStartedInvoker.InvokeHandleExceptions(this, EventArgs.Empty); } // need to copy buffers since they might get updated during execution List <TouchPoint> beganList = null; List <int> updatedList = null; List <int> endedList = null; List <int> cancelledList = null; lock (touchLock) { if (touchesBegan.Count > 0) { beganList = touchPointListPool.Get(); beganList.AddRange(touchesBegan); touchesBegan.Clear(); } if (touchesUpdated.Count > 0) { updatedList = intListPool.Get(); updatedList.AddRange(touchesUpdated); touchesUpdated.Clear(); } if (touchesEnded.Count > 0) { endedList = intListPool.Get(); endedList.AddRange(touchesEnded); touchesEnded.Clear(); } if (touchesCancelled.Count > 0) { cancelledList = intListPool.Get(); cancelledList.AddRange(touchesCancelled); touchesCancelled.Clear(); } } if (beganList != null) { updateBegan(beganList); touchPointListPool.Release(beganList); } if (updatedList != null) { updateUpdated(updatedList); intListPool.Release(updatedList); } if (endedList != null) { updateEnded(endedList); intListPool.Release(endedList); } if (cancelledList != null) { updateCancelled(cancelledList); intListPool.Release(cancelledList); } if (frameFinishedInvoker != null) { frameFinishedInvoker.InvokeHandleExceptions(this, EventArgs.Empty); } }