/// <summary>
/// Inserts in the circulare buffer to keep it ordered
/// by timestamp.
/// </summary>
/// <returns>the index where the data was inserted timestamp.</returns>
private int InsertByTimestamp(TrackingData data)
{
System.Type entryType = data.GetType();
System.Type exitType;
trackingDataBuffer.PushFront(data);
int index = 0;
for (int i = 1; i < trackingDataBuffer.Size; i++)
{
index = i - 1;
if (trackingDataBuffer[i - 1].timestamp < trackingDataBuffer[i].timestamp)
{
// Invert
TrackingData tempData = trackingDataBuffer[i];
trackingDataBuffer[i] = trackingDataBuffer[i - 1];
trackingDataBuffer[i - 1] = tempData;
}
else
{
exitType = trackingDataBuffer[i - 1].GetType();
if (entryType != exitType)
{
Debug.LogWarning("A. Entrype: " + entryType.ToString() + " ExitType: " + exitType.ToString());
}
return(index);
}
}
exitType = trackingDataBuffer[index].GetType();
if (entryType != exitType)
{
Debug.LogWarning("B. Entrype: " + entryType.ToString() + " ExitType: " + exitType.ToString() + " Index: " + index.ToString());
}
return(index);
}