Skip to content

Commit

Permalink
Adjusted when we return LapCompleted event
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis committed Dec 22, 2020
1 parent c75b8ff commit b5b83b8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Backend/Plugins/IRacingPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void ClearState() // This is invoked at start of session, so we set Obser
{ iRacingSDK.SessionState.Warmup, "Warmup" },
};

private double SessionJoinedAt = 0;
private IRacingCurrentSession? LastSessionInfo;
private IRacingSessionState? LastSessionState;
private IRacingRaceFlags? LastRaceFlags;
Expand Down Expand Up @@ -252,15 +251,18 @@ private void HandleLapsCompleted(DataSample data)
if(lapsCompleted == 0) // This is initial lap, so we can use times from next lap
carState.ObservedCrossFinishingLine += 1;

bool localUser = i == data.SessionData.DriverInfo.DriverCarIdx;

// 1st time is when leaving the pits / or whatever lap it is on when we join
// 2nd time is start of first real lap (that we see in full)
// 3rd+ is lap times (we can begin timing laps)
if (carState.ObservedCrossFinishingLine >= 3)
// if "we" are doing laps, then we know we joined with the car,
// so we can track laps from the 1st one.
// for everybody else, we need to see them crossing the line 3 or more times as describe above
if (carState.ObservedCrossFinishingLine >= 3 || (localUser && lapsCompleted > 0))
{
var lapTime = now - carState.LastLapTime;

bool localUser = i == data.SessionData.DriverInfo.DriverCarIdx;

var fuelLeft = data.Telemetry.FuelLevel;

float? usedFuel = fuelLeft - carState.FuelLevelLastLap;
Expand Down Expand Up @@ -440,7 +442,6 @@ private void HandleConnect(DataSample data)
LastWeatherInfo = null;
LastSessionInfo = null;
Connected = true;
SessionJoinedAt = data.Telemetry.SessionTime;

EventBus.PublishEvent(new IRacingConnected());
EventBus.PublishEvent(new IRacingTrackInfo
Expand Down

0 comments on commit b5b83b8

Please sign in to comment.