slightly improved the Emulator

This commit is contained in:
2023-05-22 11:29:44 +02:00
parent e650072213
commit 66906cb54e
2 changed files with 63 additions and 46 deletions
+38 -29
View File
@@ -235,39 +235,48 @@ namespace Test_Merge
switch (mainZoneId)
{
case 0:
//object lockObject = new object();
//Main Zone
//Parallel.For(0, mainZones[mainZoneId].Zones.Count,async i =>
//Parallel.For(0, mainZones[mainZoneId].Zones.Count, async i =>
for (int i = 0; i < mainZones[mainZoneId].Zones.Count; i++)
{
DriverData data = await mainZones[mainZoneId].Zones[i].Decode(new List<string>(drivers));
mainResults.Add(data);
DriverDataLogs[i].Add(data);
if (data.Position != -1 && DriverDataLogs[i].Count > 1)
await Task.Run(async () =>
{
//Tries to fix the tyres
if (data.CurrentTyre.NumberOfLaps > DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 3)
data.CurrentTyre.NumberOfLaps = DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 1;
DriverData data = await mainZones[mainZoneId].Zones[i].Decode(new List<string>(drivers));
//Checking if its a new lap
//If the third sector is filled but it was'nt the last time, then it means that a new Lap has been started
if (
DriverDataLogs[i][DriverDataLogs[i].Count - 1].Sector3 != 0
&& DriverDataLogs[i][DriverDataLogs[i].Count - 2].Sector3 == 0)
{
DriverData stats = DriverDataLogs[i][DriverDataLogs[i].Count - 2];
DriverLaps[i]++;
Storage.AddDriverStat(stats, DriverLaps[i]);
}
//Checking if its a pitstop
//Forget this the best way to know if a tyre has been changed is if the number of laps is zero
if (data.CurrentTyre.Coumpound != Tyre.Type.Undefined && data.CurrentTyre.NumberOfLaps == 0 && DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps != 0)
{
Storage.AddPitstop(data.Name, DriverLaps[i] - 1, data.CurrentTyre.Coumpound.ToString());
//Driver laps -1 because it would take AT LEAST one lap for this program to detect a pitstop
}
}
DriverDataLogs[i].Add(data);
//lock (lockObject)
//{
mainResults.Add(data);
DriverDataLogs[i].Add(data);
if (data.Position != -1 && DriverDataLogs[i].Count > 1)
{
//Tries to fix the tyres
if (data.CurrentTyre.NumberOfLaps > DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 3)
data.CurrentTyre.NumberOfLaps = DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps + 1;
//Checking if its a new lap
//If the third sector is filled but it was'nt the last time, then it means that a new Lap has been started
//Lap detection can be f***ed if the OCR takes so much time that an entire sector can be raced without us knowing.
if (
DriverDataLogs[i][DriverDataLogs[i].Count - 1].Sector3 != 0
&& DriverDataLogs[i][DriverDataLogs[i].Count - 2].Sector3 == 0)
{
DriverData stats = DriverDataLogs[i][DriverDataLogs[i].Count - 2];
DriverLaps[i]++;
Storage.AddDriverStat(stats, DriverLaps[i]);
}
//Checking if its a pitstop
//Forget this the best way to know if a tyre has been changed is if the number of laps is zero
if (data.CurrentTyre.Coumpound != Tyre.Type.Undefined && data.CurrentTyre.NumberOfLaps == 0 && DriverDataLogs[i][DriverDataLogs[i].Count - 2].CurrentTyre.NumberOfLaps != 0)
{
Storage.AddPitstop(data.Name, DriverLaps[i] - 1, data.CurrentTyre.Coumpound.ToString());
//Driver laps -1 because it would take AT LEAST one lap for this program to detect a pitstop
}
}
DriverDataLogs[i].Add(data);
//}
});
}//);
break;
//Next there could be a Title Zone and TrackInfoZone
@@ -285,7 +294,7 @@ namespace Test_Merge
}
//If 75% or more of the drivers cannot be decoded there must be a problem somewhere.
//Some can be because if they are out of the race usually the OCR returns -1 as the driver position
if (nullDrivers >= Convert.ToInt32((float)NUMBER_OF_DRIVERS / 4.0f * 3.0f))
if (nullDrivers >= Convert.ToInt32((float)NUMBER_OF_DRIVERS / 4.0f * 3.0f) || mainResults.Count == 0)
{
return "";
}