public float[] getTimeAndSectorsForBestOpponentLapInWindow(int lapsToCheck, CarData.CarClassEnum carClassToCheck) { float[] bestLapWithSectors = new float[] { -1, -1, -1, -1 }; foreach (KeyValuePair <Object, OpponentData> entry in OpponentData) { if (entry.Value.CarClass.carClassEnum == carClassToCheck) { float[] thisOpponentsBest = entry.Value.getTimeAndSectorsForBestLapInWindow(lapsToCheck); if (bestLapWithSectors[0] == -1 || (thisOpponentsBest[0] > 0 && thisOpponentsBest[0] < bestLapWithSectors[0])) { bestLapWithSectors = thisOpponentsBest; } } } // special case for practice and qual - if we're looking for all the laps in the session, we might want to use the data sent by the game // because the play may have joined mid-session. In these cases there might be an historical lap (before the player joined) that's actually faster. if (lapsToCheck == -1 && SessionData.SessionFastestLapTimeFromGamePlayerClass > 0 && (SessionData.PlayerLapTimeSessionBest == -1 || SessionData.PlayerLapTimeSessionBest > SessionData.SessionFastestLapTimeFromGamePlayerClass)) { // the player isn't the fastest in his class. This means that the game-sent best lap data will be an opponent lap if (bestLapWithSectors[0] == -1 || bestLapWithSectors[0] > SessionData.SessionFastestLapTimeFromGamePlayerClass) { // there's an historical lap which is quicker than all the data we currently hold. Due to limitations in the shared memory blocks, // we never have sector times for this historical lap, so we have to remove them and disable sector deltas until a better lap is recorded bestLapWithSectors[0] = SessionData.SessionFastestLapTimeFromGamePlayerClass; bestLapWithSectors[1] = -1; bestLapWithSectors[2] = -1; bestLapWithSectors[3] = -1; } } return(bestLapWithSectors); }
private static string GetCarClassMappingHint(CarData.CarClassEnum cce) { if (cce == CarData.CarClassEnum.UNKNOWN_RACE) { return("(unmapped)"); } else if (cce == CarData.CarClassEnum.USER_CREATED) { return("(user defined)"); } return("(built-in)"); }
public static void startRecordingPaceNotes(GameEnum gameEnum, String trackName, CarData.CarClassEnum carClass) { if (!isPlayingPaceNotes && !isRecordingPaceNotes) { Console.WriteLine("Recording a pace notes session for circuit " + trackName + " with car class " + carClass.ToString()); DriverTrainingService.gameEnum = gameEnum; DriverTrainingService.trackName = trackName; DriverTrainingService.carClass = carClass; if (carClass == CarData.CarClassEnum.UNKNOWN_RACE || carClass == CarData.CarClassEnum.USER_CREATED) { Console.WriteLine("Recording pace notes for any car class"); DriverTrainingService.folderPathForPaceNotes = getAnyCarFolderPath(gameEnum, trackName); } else { Console.WriteLine("Recording pace notes for car class " + carClass.ToString()); DriverTrainingService.folderPathForPaceNotes = getCarSpecificFolderPath(gameEnum, trackName, carClass); } Boolean createFolder = true; Boolean createNewMetaData = true; if (System.IO.Directory.Exists(folderPathForPaceNotes)) { createFolder = false; String fileName = System.IO.Path.Combine(folderPathForPaceNotes, "metadata.json"); if (File.Exists(fileName)) { try { DriverTrainingService.recordingMetaData = JsonConvert.DeserializeObject <MetaData>(File.ReadAllText(fileName)); Console.WriteLine("Pace notes for this game / track / car combination already exists. This will be extended"); createNewMetaData = false; } catch (Exception e) { Console.WriteLine("Unable to load existing metadata - renaming to 'broken_" + fileName + "', " + e.Message); File.Move(fileName, "broken_" + fileName); } } } if (createFolder) { System.IO.Directory.CreateDirectory(folderPathForPaceNotes); } if (createNewMetaData) { DriverTrainingService.recordingMetaData = new MetaData(gameEnum.ToString(), carClass.ToString(), trackName); } isRecordingPaceNotes = true; } }
public static Boolean loadPaceNotes(GameEnum gameEnum, String trackName, CarData.CarClassEnum carClass) { if (!isRecordingPaceNotes && !isPlayingPaceNotes) { Console.WriteLine("Playing pace notes for circuit " + trackName + " with car class " + carClass.ToString()); isRecordingPaceNotes = false; isRecordingSound = false; if (carClass != CarData.CarClassEnum.USER_CREATED && carClass != CarData.CarClassEnum.UNKNOWN_RACE) { DriverTrainingService.folderPathForPaceNotes = getCarSpecificFolderPath(gameEnum, trackName, carClass); if (!Directory.Exists(DriverTrainingService.folderPathForPaceNotes)) { Console.WriteLine("No pace notes folder exists for car class " + carClass + ", game " + gameEnum + ", track " + trackName + ". Checking for pace notes folder applicable to any car"); DriverTrainingService.folderPathForPaceNotes = getAnyCarFolderPath(gameEnum, trackName); if (!Directory.Exists(DriverTrainingService.folderPathForPaceNotes)) { Console.WriteLine("Unable to find any pace notes set for game " + gameEnum + ", track " + trackName); return(false); } } } else { DriverTrainingService.folderPathForPaceNotes = getAnyCarFolderPath(gameEnum, trackName); if (!Directory.Exists(DriverTrainingService.folderPathForPaceNotes)) { Console.WriteLine("Unable to find any pace notes set for game " + gameEnum + ", track " + trackName); return(false); } } String fileName = System.IO.Path.Combine(folderPathForPaceNotes, "metadata.json"); if (File.Exists(fileName)) { try { DriverTrainingService.recordingMetaData = JsonConvert.DeserializeObject <MetaData>(File.ReadAllText(fileName)); if (DriverTrainingService.recordingMetaData.description != null && !DriverTrainingService.recordingMetaData.description.Equals("")) { Console.WriteLine("Playing pace notes with description " + DriverTrainingService.recordingMetaData.description); } } catch (Exception e) { Console.WriteLine("Unable to parse pace notes metadata file: " + e.Message); return(false); } foreach (MetaDataEntry entry in DriverTrainingService.recordingMetaData.entries) { for (int i = 0; i < entry.recordingNames.Count; i++) { try { SoundCache.loadSingleSound(entry.recordingNames[i], System.IO.Path.Combine(DriverTrainingService.folderPathForPaceNotes, entry.fileNames[i])); } catch (Exception e) { Console.WriteLine("Unable to load a sound from pace notes set " + DriverTrainingService.folderPathForPaceNotes + " : " + e.Message); return(false); } } } isPlayingPaceNotes = true; } else { Console.WriteLine("No metadata.json file exists in the pace notes folder " + DriverTrainingService.folderPathForPaceNotes); } return(true); } else { if (isRecordingPaceNotes) { Console.WriteLine("A recording is already in progress, complete this first"); } else { Console.WriteLine("Already playing a session"); } return(false); } }
private static String getCarSpecificFolderPath(GameEnum gameEnum, String trackName, CarData.CarClassEnum carClass) { return(System.IO.Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments), "CrewChiefV4", "pace_notes", makeValidForPathName(gameEnum.ToString()), makeValidForPathName(carClass.ToString()), makeValidForPathName(trackName))); }