-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logger to write touch events on disk and ability to load this data in…
… the editor.
- Loading branch information
Showing
9 changed files
with
471 additions
and
98 deletions.
There are no files selected for viewing
206 changes: 143 additions & 63 deletions
206
Source/Assets/TouchScript/Editor/Debugging/PointerDebuggerWindow.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
Source/Assets/TouchScript/Scripts/Debugging/Loggers/FileReaderLogger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* @author Valentin Simonov / http://va.lent.in/ | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using TouchScript.Debugging.Filters; | ||
using TouchScript.Pointers; | ||
using UnityEngine; | ||
|
||
#if TOUCHSCRIPT_DEBUG | ||
|
||
namespace TouchScript.Debugging.Loggers | ||
{ | ||
public class FileReaderLogger : IPointerLogger | ||
{ | ||
public const int MIN_POINTER_LIST_SIZE = 1000; | ||
|
||
private int pointerCount = 0; | ||
private BinaryReader reader; | ||
|
||
protected List<PointerData> data = new List<PointerData>(1); | ||
protected List<List<PointerLog>> events = new List<List<PointerLog>>(1); | ||
|
||
/// <inheritdoc /> | ||
public int PointerCount | ||
{ | ||
get { return pointerCount; } | ||
} | ||
|
||
public FileReaderLogger(string path) | ||
{ | ||
try | ||
{ | ||
reader = new BinaryReader(new FileStream(path, FileMode.Open)); | ||
} | ||
catch (IOException e) | ||
{ | ||
Debug.LogFormat("Error opening file at '{0}'. {1}", path, e.Message); | ||
} | ||
|
||
try | ||
{ | ||
while (true) | ||
{ | ||
var type = (Pointer.PointerType) reader.ReadUInt32(); | ||
var log = new PointerLog() | ||
{ | ||
Id = reader.ReadInt32(), | ||
Tick = reader.ReadInt64(), | ||
PointerId = reader.ReadInt32(), | ||
Event = (PointerEvent) reader.ReadUInt32(), | ||
State = new PointerState() | ||
{ | ||
Buttons = (Pointer.PointerButtonState) reader.ReadUInt32(), | ||
Position = new Vector2(reader.ReadSingle(), reader.ReadSingle()), | ||
PreviousPosition = new Vector2(reader.ReadSingle(), reader.ReadSingle()), | ||
Flags = reader.ReadUInt32(), | ||
Target = null, | ||
TargetPath = reader.ReadString(), | ||
} | ||
}; | ||
|
||
checkId(log.PointerId, type); | ||
var list = getPointerList(log.PointerId); | ||
list.Add(log); | ||
} | ||
} | ||
catch (Exception e) {} | ||
finally | ||
{ | ||
reader.Close(); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Log(Pointer pointer, PointerEvent evt) | ||
{ | ||
throw new NotImplementedException("FileReaderLogger doesn't support writing data."); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public List<PointerData> GetFilteredPointerData(IPointerDataFilter filter = null) | ||
{ | ||
//if (filter == null) | ||
return new List<PointerData>(data); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public List<PointerLog> GetFilteredLogsForPointer(int id, IPointerLogFilter filter = null) | ||
{ | ||
if (id < 0 || id >= pointerCount) | ||
return new List<PointerLog>(); | ||
|
||
List<PointerLog> list = events[id]; | ||
if (filter == null) | ||
return new List<PointerLog>(list); | ||
|
||
var count = list.Count; | ||
List<PointerLog> filtered = new List<PointerLog>(count); | ||
for (var i = 0; i < count; i++) | ||
{ | ||
var item = list[i]; | ||
if (filter.Applies(ref item)) filtered.Add(item); | ||
} | ||
return filtered; | ||
} | ||
|
||
public void Dispose() {} | ||
|
||
private IList<PointerLog> getPointerList(int id) | ||
{ | ||
return events[id]; | ||
} | ||
|
||
private void checkId(int id, Pointer.PointerType type) | ||
{ | ||
if (id > pointerCount) throw new InvalidOperationException("Pointer id desync!"); | ||
else if (id == pointerCount) | ||
{ | ||
var list = new List<PointerLog>(MIN_POINTER_LIST_SIZE); | ||
events.Add(list); | ||
data.Add(new PointerData() | ||
{ | ||
Id = id, | ||
Type = type, | ||
}); | ||
pointerCount++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
12 changes: 12 additions & 0 deletions
12
Source/Assets/TouchScript/Scripts/Debugging/Loggers/FileReaderLogger.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
Source/Assets/TouchScript/Scripts/Debugging/Loggers/FileWriterLogger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* @author Valentin Simonov / http://va.lent.in/ | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using TouchScript.Debugging.Filters; | ||
using TouchScript.Pointers; | ||
using TouchScript.Utils; | ||
using UnityEngine; | ||
|
||
#if TOUCHSCRIPT_DEBUG | ||
|
||
namespace TouchScript.Debugging.Loggers | ||
{ | ||
public class FileWriterLogger : IPointerLogger | ||
{ | ||
private int eventCount = 0; | ||
private BinaryWriter writer; | ||
|
||
/// <inheritdoc /> | ||
public int PointerCount | ||
{ | ||
get { throw new NotImplementedException("FileWriterLogger doesn't support reading data."); } | ||
} | ||
|
||
public FileWriterLogger() | ||
{ | ||
var path = Path.Combine(Application.dataPath, "../TouchEvents.bin"); | ||
try | ||
{ | ||
writer = new BinaryWriter(new FileStream(path, FileMode.Create)); | ||
} | ||
catch (IOException e) | ||
{ | ||
Debug.LogFormat("Error creating file at '{0}'. {1}", path, e.Message); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Log(Pointer pointer, PointerEvent evt) | ||
{ | ||
var path = TransformUtils.GetHeirarchyPath(pointer.GetPressData().Target); | ||
|
||
writer.Write((uint) pointer.Type); | ||
writer.Write(eventCount); | ||
writer.Write(DateTime.Now.Ticks); | ||
writer.Write(pointer.Id); | ||
writer.Write((uint) evt); | ||
writer.Write((uint) pointer.Buttons); | ||
writer.Write(pointer.Position.x); | ||
writer.Write(pointer.Position.y); | ||
writer.Write(pointer.PreviousPosition.x); | ||
writer.Write(pointer.PreviousPosition.y); | ||
writer.Write(pointer.Flags); | ||
writer.Write(path ?? ""); | ||
|
||
eventCount++; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public List<PointerData> GetFilteredPointerData(IPointerDataFilter filter = null) | ||
{ | ||
throw new NotImplementedException("FileWriterLogger doesn't support reading data."); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public List<PointerLog> GetFilteredLogsForPointer(int id, IPointerLogFilter filter = null) | ||
{ | ||
throw new NotImplementedException("FileWriterLogger doesn't support reading data."); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (writer != null) writer.Close(); | ||
} | ||
} | ||
} | ||
|
||
#endif |
12 changes: 12 additions & 0 deletions
12
Source/Assets/TouchScript/Scripts/Debugging/Loggers/FileWriterLogger.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.