Example #1
0
        public Runner()
        {
            var memMap = MemoryMappedFile.CreateFromFile(Path.Combine("data", "session.ibt"));

            sdk = new IRacingSDK(memMap.CreateViewAccessor());

            _dataModel = sdk.GetSerializedData();
            _data      = sdk.GetData();
        }
Example #2
0
 public static List <CarModel> GetPositions(this IRacingSDK racingSDK, out double sessionTime)
 {
     if (racingSDK.IsConnected())
     {
         var fileView = IRacingSDK.GetFileMapView(racingSDK);
         var headers  = IRacingSDK.GetVarHeaders(racingSDK);
         var data     = new byte[racingSDK.Header.BufferLength];
         fileView.ReadArray(racingSDK.Header.Offset, data, 0, racingSDK.Header.BufferLength);
         sessionTime = (double)racingSDK.GetData("SessionTime");
         return(IRacingDataModel.SerializeCars(data, headers));
     }
     sessionTime = 0;
     return(null);
 }
Example #3
0
 public Data Data() => sdk.GetData();
Example #4
0
        private static void Loop()
        {
            int lastUpdate = -1;

            while (true)
            {
                var currentlyConnected = sdk.IsConnected();

                // Check if we can find the sim
                if (currentlyConnected)
                {
                    int       attempts    = 0;
                    const int maxAttempts = 99;

                    object sessionnum = TryGetSessionNum();
                    while (sessionnum == null && attempts <= maxAttempts)
                    {
                        attempts++;
                        sessionnum = TryGetSessionNum();
                    }
                    if (attempts >= maxAttempts)
                    {
                        System.Console.WriteLine("Session num too many attempts");
                        continue;
                    }

                    // Parse out your own driver Id
                    if (DriverId == -1)
                    {
                        _DriverId = (int)sdk.GetData("PlayerCarIdx");
                    }

                    var data = sdk.GetSerializedData();

                    // Raise the TelemetryUpdated event and pass along the lap info and session time
                    //var telArgs = new TelemetryUpdatedEventArgs(new TelemetryInfo(sdk), time);
                    // this.RaiseEvent(OnTelemetryUpdated, telArgs);

                    // Is the session info updated?
                    int newUpdate = sdk.Header.SessionInfoUpdate;
                    if (newUpdate != lastUpdate)
                    {
                        lastUpdate = newUpdate;
                        _session   = sdk.GetSerializedSessionInfo();
                    }

                    if (data != null && _session != null)
                    {
                        Console.SetCursorPosition(0, 0);


                        foreach (var car in data.Data.Cars.OrderByDescending(x => x.CarIdxLap).ThenByDescending(x => x.CarIdxLapDistPct))
                        {
                            var currentData = _session.DriverInfo.Drivers.Where(y => y.CarIdx == car.CarIdx).FirstOrDefault();
                            if (currentData != null && car.CarIdxEstTime != 0)
                            {
                                Console.WriteLine($"{currentData.CarNumber}\t{string.Format("{0:0.00}", car.CarIdxEstTime)}\t{string.Format("{0:0.00}", car.CarIdxLapDistPct * 100)}");
                            }
                        }
                    }

                    Thread.Sleep(15);
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
        }