private void SdkOnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e) { Debug.WriteLine($"SdkOnSessionInfoUpdated: {e.UpdateTime}"); // Cache info _sessionInfo = e.SessionInfo; // Stop if we don't have a session number yet if (_currentSessionNumber == null) { return; } if (_mustUpdateSessionData) { _sessionData.Update(e.SessionInfo); _timeDelta = new TimeDelta((float)_sessionData.Track.Length * 1000f, 20, 64); _mustUpdateSessionData = false; this.OnStaticInfoChanged(); } // Update drivers this.UpdateDriverList(e.SessionInfo); this.OnSessionInfoUpdated(e); }
private void UpdateTimeDelta() { if (_timeDelta == null) { return; } // Update the positions of all cars _timeDelta.Update(_telemetry.SessionTime.Value, _telemetry.CarIdxLapDistPct.Value); // Order drivers by live position var drivers = _drivers.OrderBy(d => d.Live.Position).ToList(); if (drivers.Count > 0) { // Get leader //var leader = drivers[0]; this.Leader.Live.DeltaToLeader = "-"; this.Leader.Live.DeltaToNext = "-"; // Loop through drivers for (int i = 1; i < drivers.Count; i++) { var behind = drivers[i]; var ahead = drivers[i - 1]; // Lapped? var leaderLapDiff = Math.Abs(this.Leader.Live.TotalLapDistance - behind.Live.TotalLapDistance); var nextLapDiff = Math.Abs(ahead.Live.TotalLapDistance - behind.Live.TotalLapDistance); if (leaderLapDiff < 1) { var leaderDelta = _timeDelta.GetDelta(behind.Id, this.Leader.Id); behind.Live.DeltaToLeader = TimeDelta.DeltaToString(leaderDelta); } else { behind.Live.DeltaToLeader = Math.Floor(leaderLapDiff) + " L"; } if (nextLapDiff < 1) { var nextDelta = _timeDelta.GetDelta(behind.Id, ahead.Id); behind.Live.DeltaToNext = TimeDelta.DeltaToString(nextDelta); } else { behind.Live.DeltaToNext = Math.Floor(nextLapDiff) + " L"; } } } }
private void Reset() { _mustUpdateSessionData = true; _mustReloadDrivers = true; _currentSessionNumber = null; _driver = null; _leader = null; _drivers.Clear(); _timeDelta = null; _telemetry = null; _sessionInfo = null; _isUpdatingDrivers = false; }
private void SdkOnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e) { // Cache previous and current info _previousSessionInfo = _sessionInfo; _sessionInfo = e.SessionInfo; // Stop if we don't have a session number yet if (_currentSessionNumber == null) return; if (_mustUpdateSessionData) { _sessionData.Update(e.SessionInfo); _timeDelta = new TimeDelta((float)_sessionData.Track.Length * 1000f, 20, 64); _mustUpdateSessionData = false; this.OnStaticInfoChanged(); } // Update drivers this.UpdateDriverList(e.SessionInfo); this.OnSessionInfoUpdated(e); }