Esempio n. 1
0
        private static void FillPlayersGear(PCarsApiStruct data, SimulatorDataSet simData)
        {
            switch (data.MGear)
            {
            case 0:
                simData.PlayerInfo.CarInfo.CurrentGear = "N";
                break;

            case -1:
                simData.PlayerInfo.CarInfo.CurrentGear = "R";
                break;

            case -2:
                simData.PlayerInfo.CarInfo.CurrentGear = string.Empty;
                break;

            default:
                simData.PlayerInfo.CarInfo.CurrentGear = data.MGear.ToString();
                break;
            }
        }
Esempio n. 2
0
        private void AddDriversData(PCarsApiStruct pcarsData, SimulatorDataSet data)
        {
            if (pcarsData.MNumParticipants == -1)
            {
                return;
            }

            data.DriversInfo = new DriverInfo[pcarsData.MNumParticipants];
            DriverInfo playersInfo  = null;
            var        computeSpeed = data.SessionInfo.SessionTime.TotalSeconds > _pcarsConnector.NextSpeedComputation;

            for (int i = 0; i < pcarsData.MNumParticipants; i++)
            {
                PCarsApiParticipantStruct pcarsDriverData = pcarsData.MParticipantData[i];
                DriverInfo driverInfo =
                    new DriverInfo
                {
                    DriverName      = pcarsDriverData.MName,
                    CompletedLaps   = (int)pcarsDriverData.MLapsCompleted,
                    CarName         = "N/A",
                    CarClassName    = pcarsData.MCarClassName,
                    CarClassId      = pcarsData.MCarClassName,
                    InPits          = false,
                    IsPlayer        = i == pcarsData.MViewedParticipantIndex,
                    Position        = (int)pcarsDriverData.MRacePosition,
                    LapDistance     = pcarsDriverData.MCurrentLapDistance,
                    FinishStatus    = DriverFinishStatus.None,
                    CurrentLapValid = true,
                    WorldPosition   = new Point3D(Distance.FromMeters(-pcarsDriverData.MWorldPosition[0]), Distance.FromMeters(pcarsDriverData.MWorldPosition[1]), Distance.FromMeters(pcarsDriverData.MWorldPosition[2]))
                };

                if (_lastPlayer != null)
                {
                    ComputeDistanceToPlayer(_lastPlayer, driverInfo, data);
                }

                if (pcarsData.MLapsInEvent > 0 && driverInfo.CompletedLaps >= pcarsData.MLapsInEvent)
                {
                    driverInfo.FinishStatus = DriverFinishStatus.Finished;
                }

                driverInfo.TotalDistance = driverInfo.CompletedLaps * data.SessionInfo.TrackInfo.LayoutLength.InMeters + driverInfo.LapDistance;

                if (driverInfo.IsPlayer)
                {
                    playersInfo = driverInfo;
                    driverInfo.CurrentLapValid = !pcarsData.MLapInvalidated;
                }
                else
                {
                    driverInfo.CurrentLapValid = true;
                }

                data.DriversInfo[i] = driverInfo;
                if (string.IsNullOrEmpty(driverInfo.DriverName))
                {
                    throw new PCarsConnector.NameNotFilledException("Name not filled for driver with index " + i);
                }

                AddSpeedInfo(data, computeSpeed, driverInfo);
                if (data.SessionInfo.SessionType == SessionType.Race && _lastPlayer != null && _lastPlayer.CompletedLaps != 0)
                {
                    driverInfo.IsBeingLappedByPlayer = driverInfo.TotalDistance < (_lastPlayer.TotalDistance - data.SessionInfo.TrackInfo.LayoutLength.InMeters * 0.5);
                    driverInfo.IsLappingPlayer       = _lastPlayer.TotalDistance < (driverInfo.TotalDistance - data.SessionInfo.TrackInfo.LayoutLength.InMeters * 0.5);
                }

                if (driverInfo.Position == 1)
                {
                    data.LeaderInfo = driverInfo;
                    data.SessionInfo.LeaderCurrentLap = driverInfo.CompletedLaps + 1;
                }
            }

            if (computeSpeed)
            {
                _pcarsConnector.NextSpeedComputation += 0.5;
            }

            if (playersInfo != null)
            {
                data.PlayerInfo = playersInfo;
                _lastPlayer     = playersInfo;
            }

            AddPitsInfo(data);
            if (computeSpeed)
            {
                _lastSpeedComputationSet = data;
            }
        }
Esempio n. 3
0
        private void FillSessionInfo(PCarsApiStruct pCarsData, SimulatorDataSet simData, TimeSpan lastTickDuration)
        {
            if (pCarsData.MGameState == 2)
            {
                _pcarsConnector.SessionTime = _pcarsConnector.SessionTime.Add(lastTickDuration);
            }

            if (pCarsData.MSessionState == (int)ESessionState.SessionInvalid ||
                (pCarsData.MSessionState == (int)ESessionState.SessionRace && pCarsData.MRaceState == 1))
            {
                _pcarsConnector.SessionTime = TimeSpan.Zero;
            }

            simData.SessionInfo.SessionTime = _pcarsConnector.SessionTime;

            simData.SessionInfo.WeatherInfo.AirTemperature   = Temperature.FromCelsius(pCarsData.MAmbientTemperature);
            simData.SessionInfo.WeatherInfo.TrackTemperature = Temperature.FromCelsius(pCarsData.MTrackTemperature);
            simData.SessionInfo.WeatherInfo.RainIntensity    = (int)(pCarsData.MRainDensity * 100);
            simData.SessionInfo.TrackInfo.LayoutLength       = Distance.FromMeters(pCarsData.MTrackLength);
            simData.SessionInfo.IsActive = true; // (eRaceState)pcarsData.mRaceState == eRaceState.RACESTATE_RACING

            // || (eRaceState)pcarsData.mRaceState == eRaceState.RACESTATE_FINISHED;
            switch ((ESessionState)pCarsData.MSessionState)
            {
            case ESessionState.SessionPractice:
            case ESessionState.SessionTest:
            case ESessionState.SessionTimeAttack:
                simData.SessionInfo.SessionType = SessionType.Practice;
                break;

            case ESessionState.SessionQualify:
                simData.SessionInfo.SessionType = SessionType.Qualification;
                break;

            case ESessionState.SessionRace:
                simData.SessionInfo.SessionType = SessionType.Race;
                break;

            case ESessionState.SessionInvalid:
                simData.SessionInfo.SessionType = SessionType.Na;
                break;
            }

            switch ((ERaceState)pCarsData.MRaceState)
            {
            case ERaceState.RacestateNotStarted:
                simData.SessionInfo.SessionPhase = SessionPhase.Countdown;
                break;

            case ERaceState.RacestateRacing:
                simData.SessionInfo.SessionPhase = SessionPhase.Green;
                break;

            case ERaceState.RacestateRetired:
            case ERaceState.RacestateDnf:
            case ERaceState.RacestateDisqualified:
            case ERaceState.RacestateFinished:
                simData.SessionInfo.SessionPhase = SessionPhase.Checkered;
                break;

            case ERaceState.RacestateInvalid:
                break;

            case ERaceState.RacestateMax:
                break;

            default:
                simData.SessionInfo.SessionPhase = SessionPhase.Green;
                break;
            }
            if (simData.SessionInfo.SessionPhase == SessionPhase.Countdown &&
                simData.SessionInfo.SessionType != SessionType.Race)
            {
                simData.SessionInfo.SessionPhase = SessionPhase.Green;
            }

            simData.SessionInfo.TrackInfo.TrackName       = pCarsData.MTrackLocation;
            simData.SessionInfo.TrackInfo.TrackLayoutName = pCarsData.MTrackVariation;

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (pCarsData.MEventTimeRemaining != -1)
            {
                simData.SessionInfo.SessionLengthType    = SessionLengthType.Time;
                simData.SessionInfo.SessionTimeRemaining = pCarsData.MEventTimeRemaining;
            }
            else if (pCarsData.MLapsInEvent != 0)
            {
                simData.SessionInfo.SessionLengthType = SessionLengthType.Laps;
                simData.SessionInfo.TotalNumberOfLaps = (int)pCarsData.MLapsInEvent;
            }
        }
Esempio n. 4
0
        // NEED EXTRACT WHEN SUPPORT FOR OTHER SIMS IS ADDED
        public SimulatorDataSet FromPcarsData(PCarsApiStruct data, TimeSpan lastTickDuration)
        {
            SimulatorDataSet simData = new SimulatorDataSet("PCars");

            // PEDAL INFO
            simData.InputInfo.ThrottlePedalPosition = data.MThrottle;
            simData.InputInfo.BrakePedalPosition    = data.MBrake;
            simData.InputInfo.ClutchPedalPosition   = data.MClutch;

            FillSessionInfo(data, simData, lastTickDuration);
            AddDriversData(data, simData);

            FillPlayerCarInfo(data, simData);

            // WaterSystemInfo
            simData.PlayerInfo.CarInfo.WaterSystemInfo.OptimalWaterTemperature.ActualQuantity =
                Temperature.FromCelsius(data.MWaterTempCelsius);

            // OilSystemInfo
            simData.PlayerInfo.CarInfo.OilSystemInfo.OilPressure = Pressure.FromKiloPascals(data.MOilPressureKPa);
            simData.PlayerInfo.CarInfo.OilSystemInfo.OptimalOilTemperature.ActualQuantity = Temperature.FromCelsius(data.MOilTempCelsius);

            // Brakes Info
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.BrakeTemperature.ActualQuantity =
                Temperature.FromCelsius(data.MBrakeTempCelsius[0]);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.BrakeTemperature.ActualQuantity =
                Temperature.FromCelsius(data.MBrakeTempCelsius[1]);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.BrakeTemperature.ActualQuantity =
                Temperature.FromCelsius(data.MBrakeTempCelsius[2]);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.BrakeTemperature.ActualQuantity =
                Temperature.FromCelsius(data.MBrakeTempCelsius[3]);

            // Tyre Pressure Info

            /*simData.PlayerCarInfo.WheelsInfo.FrontLeft.TyrePressure = Pressure.FromKiloPascals(data.ty TirePressure.FrontLeft);
             * simData.PlayerCarInfo.WheelsInfo.FrontRight.TyrePressure = Pressure.FromKiloPascals(data.TirePressure.FrontRight);
             * simData.PlayerCarInfo.WheelsInfo.RearLeft.TyrePressure = Pressure.FromKiloPascals(data.TirePressure.RearLeft);
             * simData.PlayerCarInfo.WheelsInfo.RearRight.TyrePressure = Pressure.FromKiloPascals(data.TirePressure.RearRight);*/

            // Front Left Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.LeftTyreTemp.ActualQuantity   = Temperature.FromCelsius(data.MTyreTemp[0]);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.RightTyreTemp.ActualQuantity  = Temperature.FromCelsius(data.MTyreTemp[0]);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.CenterTyreTemp.ActualQuantity = Temperature.FromCelsius(data.MTyreTemp[0]);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.TyreWear.ActualWear           = data.MTyreWear[0];

            // Front Right Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.LeftTyreTemp.ActualQuantity   = Temperature.FromCelsius(data.MTyreTemp[1]);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.RightTyreTemp.ActualQuantity  = Temperature.FromCelsius(data.MTyreTemp[1]);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.CenterTyreTemp.ActualQuantity = Temperature.FromCelsius(data.MTyreTemp[1]);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.TyreWear.ActualWear           = data.MTyreWear[1];

            // Rear Left Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.LeftTyreTemp.ActualQuantity   = Temperature.FromCelsius(data.MTyreTemp[2]);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.RightTyreTemp.ActualQuantity  = Temperature.FromCelsius(data.MTyreTemp[2]);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.CenterTyreTemp.ActualQuantity = Temperature.FromCelsius(data.MTyreTemp[2]);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.TyreWear.ActualWear           = data.MTyreWear[2];

            // Rear Right Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.LeftTyreTemp.ActualQuantity   = Temperature.FromCelsius(data.MTyreTemp[3]);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.RightTyreTemp.ActualQuantity  = Temperature.FromCelsius(data.MTyreTemp[3]);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.CenterTyreTemp.ActualQuantity = Temperature.FromCelsius(data.MTyreTemp[3]);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.TyreWear.ActualWear           = data.MTyreWear[3];

            // Fuel
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelCapacity  = Volume.FromLiters(data.MFuelCapacity);
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelRemaining =
                Volume.FromLiters(data.MFuelCapacity * data.MFuelLevel);
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelPressure = Pressure.FromKiloPascals(data.MFuelPressureKPa);

            // Acceleration
            simData.PlayerInfo.CarInfo.Acceleration.XinMs = data.MLocalAcceleration[0];
            simData.PlayerInfo.CarInfo.Acceleration.YinMs = data.MLocalAcceleration[1];
            simData.PlayerInfo.CarInfo.Acceleration.ZinMs = data.MLocalAcceleration[2];


            PopulateClassPositions(simData);
            return(simData);
        }