private ApexInfo GetNearestApex(int distance) { var nearest = CircuitLayoutData.apexInfo.Where(a => Math.Abs(distance - a.fastAverage) < 50).FirstOrDefault(); if (nearest == null) { nearest = new ApexInfo(); nearest.AddMeasurement(distance); CircuitLayoutData.apexInfo.Add(nearest); } return nearest; }
/// <summary> /// Check if apex narration is needed and speak! /// Already in 'locked' state. Prevent deadlocks! /// </summary> public void CheckMyApex() { if (CircuitLayoutData?.apexInfo == null) return; // Check if data is consistent if (lastMotionFrame == lastLapFrame && lastMotionFrame == lastTelemetryFrame && lastCarMotionData != null && lastLapData != null && lastCarTelemetryData != null) { // Are we alre if (myNextApex == null) { // Next apex (first apex in upcoming 200 m) myNextApex = CircuitLayoutData.apexInfo.Where(a => a.numMeasurements > 3 && a.fastAverage > lastLapData.Value.lapDistance && a.fastAverage - lastLapData.Value.lapDistance < 200) .FirstOrDefault(); if (myNextApex != null) { myNextApex.LaptimeBeforeApex = 0; myNextApex.Breaking = 0; } } if (myNextApex != null) { // Store lap time at 70m before apex if (myNextApex.fastAverage - lastLapData.Value.lapDistance < 70 && myNextApex.LaptimeBeforeApex == 0) { myNextApex.LaptimeBeforeApex = lastLapData.Value.currentLapTimeInMS; } if (myNextApex.Breaking == 0 && lastCarTelemetryData.Value.brake>0) { // Hitting the brakes! myNextApex.Breaking = lastLapData.Value.lapDistance; if (Config.UserConfig.AnnounceDinstance2Apex) { SpeachSynthesizer.QueueText((myNextApex.fastAverage - lastLapData.Value.lapDistance).ToString()); } } if (lastLapData.Value.lapDistance > myNextApex.fastAverage) { // just after apex myLastApex = myNextApex; if (Config.UserConfig.AnnounceApexSpeed) { SpeachSynthesizer.QueueText(lastCarTelemetryData.Value.speed.ToString()); } myNextApex = null; } } if (myLastApex != null && lastLapData.Value.lapDistance > myLastApex.fastAverage + 70) { // X m after apex if (myLastApex.LaptimeBeforeApex > 0) { string s = (lastLapData.Value.currentLapTimeInMS - myLastApex.LaptimeBeforeApex).ToString(); // Call out ms from 150m before apex to now if (Config.UserConfig.AnnounceCornerTime) { SpeachSynthesizer.QueueNumber(s); } myLastApex = null; } } } }