/// <summary> /// implementation of the ICarCoordinates interface /// </summary> /// <param name="coords">car coordinate data</param> public void ProcessRaceData(JCarCoords coords) { if (currentTimeData == null) { // set up the first timestamp object currentTimeData = new TimestampData(coords.Timestamp, this); } else if (currentTimeData.Timestamp != coords.Timestamp) { // data has arrived with a new timestamp, work out the positions // of the cars for the previous timestamp RecalculatePositions(currentTimeData); } HandleCarDataEvent(coords); }
/// <summary> /// recalculate the race positions of the cars at a single time /// </summary> /// <param name="timestampData">the data for a timestamp</param> private void RecalculatePositions(TimestampData timestampData) { // collect the latest angles of all cars Car car; double[] angles = new double[Cars.Count]; int[] carIndexes = new int[Cars.Count]; int index = 0; foreach (var key in Cars.Keys) { car = Cars[key]; angles[index] = car.LapAngle; carIndexes[index] = car.Index; index++; } // ensure that all entries are in race order Array.Sort(angles, carIndexes); timestampData.GenerateEnhancedRaceEvents(carIndexes); }