Skip to content
Permalink
Browse files

Optimized a few small things, added profiling samplers.

  • Loading branch information...
valyard committed Jul 29, 2017
1 parent 04aa00e commit 8f02827f102bb5e8bdd4011f613e7ec8e3b2b240
@@ -517,13 +517,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7a878a6ff128243dfb1d89ca0273f059, type: 3}
m_Name:
m_EditorClassIdentifier:
debugMode: 0
OnStateChange:
m_PersistentCalls:
m_Calls: []
m_TypeName: TouchScript.Gestures.Gesture+GestureEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
basicEditor: 1
basicEditor: 0
generalProps: 0
limitsProps: 0
advancedProps: 0
@@ -542,7 +541,7 @@ MonoBehaviour:
m_TypeName: TouchScript.Gestures.Gesture+GestureEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
numberOfTapsRequired: 2
timeLimit: Infinity
timeLimit: 1
distanceLimit: Infinity
combinePointers: 0
combinePointersInterval: 0.3
@@ -1768,6 +1767,10 @@ Prefab:
propertyPath: useDPI
value: 1
objectReference: {fileID: 0}
- target: {fileID: 100000, guid: c0dc5781cae4a6348b42ea6b818a3f9c, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: c0dc5781cae4a6348b42ea6b818a3f9c, type: 2}
m_IsPrefabParent: 0
@@ -93,7 +93,7 @@ public InputType SupportedInputs
private ObjectProcessor objectProcessor;
private BlobProcessor blobProcessor;

private Dictionary<TuioCursor, TouchPointer> cursorToInternalId = new Dictionary<TuioCursor, TouchPointer>();
private Dictionary<TuioCursor, TouchPointer> cursorToInternalId = new Dictionary<TuioCursor, TouchPointer>(10);
private Dictionary<TuioBlob, ObjectPointer> blobToInternalId = new Dictionary<TuioBlob, ObjectPointer>();
private Dictionary<TuioObject, ObjectPointer> objectToInternalId = new Dictionary<TuioObject, ObjectPointer>();
private int screenWidth;
@@ -7,6 +7,7 @@
using TouchScript.Pointers;
using TouchScript.Utils.Attributes;
using UnityEngine;
using UnityEngine.Profiling;

namespace TouchScript.Behaviors.Cursors
{
@@ -132,12 +133,18 @@ public uint CursorPixelSize
private ObjectPool<PointerCursor> objectPool;
private Dictionary<int, PointerCursor> cursors = new Dictionary<int, PointerCursor>(10);

private CustomSampler cursorSampler;

#endregion

#region Unity methods

private void Awake()
{
cursorSampler = CustomSampler.Create("[TouchScript] Update Cursors");

cursorSampler.Begin();

mousePool = new ObjectPool<PointerCursor>(2, instantiateMouseProxy, null, clearProxy);
touchPool = new ObjectPool<PointerCursor>(10, instantiateTouchProxy, null, clearProxy);
penPool = new ObjectPool<PointerCursor>(2, instantiatePenProxy, null, clearProxy);
@@ -151,6 +158,8 @@ private void Awake()
Debug.LogError("CursorManager must be on an UI element!");
enabled = false;
}

cursorSampler.End();
}

private void OnEnable()
@@ -219,6 +228,8 @@ private void updateCursorSize()

private void pointersAddedHandler(object sender, PointerEventArgs e)
{
cursorSampler.Begin();

updateCursorSize();

var count = e.Pointers.Count;
@@ -251,10 +262,14 @@ private void pointersAddedHandler(object sender, PointerEventArgs e)
cursor.Init(rect, pointer);
cursors.Add(pointer.Id, cursor);
}

cursorSampler.End();
}

private void pointersRemovedHandler(object sender, PointerEventArgs e)
{
cursorSampler.Begin();

var count = e.Pointers.Count;
for (var i = 0; i < count; i++)
{
@@ -279,10 +294,14 @@ private void pointersRemovedHandler(object sender, PointerEventArgs e)
break;
}
}

cursorSampler.End();
}

private void pointersPressedHandler(object sender, PointerEventArgs e)
{
cursorSampler.Begin();

var count = e.Pointers.Count;
for (var i = 0; i < count; i++)
{
@@ -291,10 +310,14 @@ private void pointersPressedHandler(object sender, PointerEventArgs e)
if (!cursors.TryGetValue(pointer.Id, out cursor)) continue;
cursor.SetState(pointer, PointerCursor.CursorState.Pressed);
}

cursorSampler.End();
}

private void PointersUpdatedHandler(object sender, PointerEventArgs e)
{
cursorSampler.Begin();

var count = e.Pointers.Count;
for (var i = 0; i < count; i++)
{
@@ -303,10 +326,14 @@ private void PointersUpdatedHandler(object sender, PointerEventArgs e)
if (!cursors.TryGetValue(pointer.Id, out cursor)) continue;
cursor.UpdatePointer(pointer);
}

cursorSampler.End();
}

private void pointersReleasedHandler(object sender, PointerEventArgs e)
{
cursorSampler.Begin();

var count = e.Pointers.Count;
for (var i = 0; i < count; i++)
{
@@ -315,6 +342,8 @@ private void pointersReleasedHandler(object sender, PointerEventArgs e)
if (!cursors.TryGetValue(pointer.Id, out cursor)) continue;
cursor.SetState(pointer, PointerCursor.CursorState.Released);
}

cursorSampler.End();
}

private void pointersCancelledHandler(object sender, PointerEventArgs e)
@@ -8,6 +8,7 @@
using TouchScript.Utils;
using TouchScript.Pointers;
using UnityEngine;
using UnityEngine.Profiling;

namespace TouchScript.Core
{
@@ -56,7 +57,9 @@ public static IGestureManager Instance

// Upcoming changes
private List<Gesture> gesturesToReset = new List<Gesture>(20);
private Dictionary<int, List<Gesture>> pointerToGestures = new Dictionary<int, List<Gesture>>();
private Dictionary<int, List<Gesture>> pointerToGestures = new Dictionary<int, List<Gesture>>(10);

private CustomSampler gestureSampler;

#endregion

@@ -69,8 +72,8 @@ public static IGestureManager Instance
private Dictionary<Gesture, List<Pointer>> pointersToDispatchForGesture = new Dictionary<Gesture, List<Pointer>>(10);
private List<Gesture> activeGesturesThisUpdate = new List<Gesture>(20);

private Dictionary<Transform, List<Gesture>> hierarchyEndingWithCache = new Dictionary<Transform, List<Gesture>>();
private Dictionary<Transform, List<Gesture>> hierarchyBeginningWithCache = new Dictionary<Transform, List<Gesture>>();
private Dictionary<Transform, List<Gesture>> hierarchyEndingWithCache = new Dictionary<Transform, List<Gesture>>(4);
private Dictionary<Transform, List<Gesture>> hierarchyBeginningWithCache = new Dictionary<Transform, List<Gesture>>(4);

#endregion

@@ -107,6 +110,8 @@ private void Awake()
gestureListPool.WarmUp(20);
pointerListPool.WarmUp(20);
transformListPool.WarmUp(1);

gestureSampler = CustomSampler.Create("[TouchScript] Update Gestures");
}

private void OnEnable()
@@ -219,6 +224,8 @@ internal Gesture.GestureState INTERNAL_GestureChangeState(Gesture gesture, Gestu

private void updatePressed(IList<Pointer> pointers)
{
gestureSampler.Begin();

var activeTargets = transformListPool.Get();
var gesturesInHierarchy = gestureListPool.Get();
var startedGestures = gestureListPool.Get();
@@ -368,10 +375,14 @@ private void updatePressed(IList<Pointer> pointers)
pointersOnTarget.Clear();
activeGesturesThisUpdate.Clear();
pointersToDispatchForGesture.Clear();

gestureSampler.End();
}

private void updateUpdated(IList<Pointer> pointers)
{
gestureSampler.Begin();

sortPointersForActiveGestures(pointers);

var count = activeGesturesThisUpdate.Count;
@@ -388,10 +399,14 @@ private void updateUpdated(IList<Pointer> pointers)

activeGesturesThisUpdate.Clear();
pointersToDispatchForGesture.Clear();

gestureSampler.End();
}

private void updateReleased(IList<Pointer> pointers)
{
gestureSampler.Begin();

sortPointersForActiveGestures(pointers);

var count = activeGesturesThisUpdate.Count;
@@ -409,10 +424,14 @@ private void updateReleased(IList<Pointer> pointers)
removePointers(pointers);
activeGesturesThisUpdate.Clear();
pointersToDispatchForGesture.Clear();

gestureSampler.End();
}

private void updateCancelled(IList<Pointer> pointers)
{
gestureSampler.Begin();

sortPointersForActiveGestures(pointers);

var count = activeGesturesThisUpdate.Count;
@@ -430,6 +449,8 @@ private void updateCancelled(IList<Pointer> pointers)
removePointers(pointers);
activeGesturesThisUpdate.Clear();
pointersToDispatchForGesture.Clear();

gestureSampler.End();
}

private void sortPointersForActiveGestures(IList<Pointer> pointers)
@@ -499,8 +520,8 @@ private void resetGestures()

private void clearFrameCaches()
{
foreach (var list in hierarchyEndingWithCache.Values) gestureListPool.Release(list);
foreach (var list in hierarchyBeginningWithCache.Values) gestureListPool.Release(list);
foreach (var kv in hierarchyEndingWithCache) gestureListPool.Release(kv.Value);
foreach (var kv in hierarchyBeginningWithCache) gestureListPool.Release(kv.Value);
hierarchyEndingWithCache.Clear();
hierarchyBeginningWithCache.Clear();
}
Oops, something went wrong.

0 comments on commit 8f02827

Please sign in to comment.
You can’t perform that action at this time.