Esempio n. 1
0
        private static void FillDrsData(R3ESharedData data, CarInfo playerCar)
        {
            DrsSystem drsSystem = playerCar.DrsSystem;

            drsSystem.DrsActivationLeft = data.Drs.NumActivationsLeft < 100 ? data.Drs.NumActivationsLeft : -1;
            if (data.Drs.Equipped == 0)
            {
                drsSystem.DrsStatus = DrsStatus.NotEquipped;
                return;
            }

            if (data.Drs.Engaged == 1)
            {
                drsSystem.DrsStatus = DrsStatus.InUse;
                return;
            }

            if (data.Drs.Available == 1)
            {
                drsSystem.DrsStatus = DrsStatus.Available;
                return;
            }

            drsSystem.DrsStatus = DrsStatus.Equipped;
        }
Esempio n. 2
0
        internal SimulatorDataSet FromR3EData(R3ESharedData data)
        {
            SimulatorDataSet simData = new SimulatorDataSet("R3E");

            simData.SimulatorSourceInfo.HasLapTimeInformation = true;
            simData.SimulatorSourceInfo.SectorTimingSupport   = DataInputSupport.FULL;
            simData.SimulatorSourceInfo.AIInstantFinish       = true;

            // SimulatorDataSet simData = new SimulatorDataSet("R3R");
            FillSessionInfo(data, simData);
            AddDriversData(simData, data);

            FillPlayersGear(data, simData);

            // PEDAL INFO
            AddPedalInfo(data, simData);

            // WaterSystemInfo
            AddWaterSystemInfo(data, simData);

            // OilSystemInfo
            AddOilSystemInfo(data, simData);

            // Brakes Info
            AddBrakesInfo(data, simData);

            // Tyre Pressure Info
            AddTyresInfo(data, simData);

            // Acceleration
            AddAcceleration(data, simData);

            return(simData);
        }
Esempio n. 3
0
        private void AddPlayerCarInfo(R3ESharedData data, SimulatorDataSet simData)
        {
            CarInfo playerCar = simData.PlayerInfo.CarInfo;

            playerCar.CarDamageInformation.Bodywork.MediumDamageThreshold     = 0.01;
            playerCar.CarDamageInformation.Engine.MediumDamageThreshold       = 0.01;
            playerCar.CarDamageInformation.Transmission.MediumDamageThreshold = 0.01;
            playerCar.CarDamageInformation.Suspension.Damage   = data.CarDamage.Suspension >= 0 ? 1 - data.CarDamage.Suspension : 0;
            playerCar.CarDamageInformation.Bodywork.Damage     = data.CarDamage.Aerodynamics >= 0 ? 1 - data.CarDamage.Aerodynamics : 0;
            playerCar.CarDamageInformation.Engine.Damage       = data.CarDamage.Engine >= 0 ? 1 - data.CarDamage.Engine : 0;
            playerCar.CarDamageInformation.Transmission.Damage = data.CarDamage.Transmission >= 0 ? 1 - data.CarDamage.Transmission : 0;
            playerCar.TurboPressure    = Math.Abs(data.TurboPressure) < 0.1 ? Pressure.Zero : Pressure.FromBar(data.TurboPressure);
            playerCar.OverallDownForce = Force.GetFromNewtons(data.Player.CurrentDownforce);

            playerCar.FrontRollAngle = Angle.GetFromRadians(data.Player.FrontRollAngle);
            playerCar.RearRollAngle  = Angle.GetFromRadians(data.Player.RearRollAngle);

            playerCar.SpeedLimiterEngaged = data.PitLimiter == 1;

            playerCar.WorldOrientation = new Orientation()
            {
                Roll  = Angle.GetFromRadians(data.CarOrientation.Roll),
                Pitch = Angle.GetFromRadians(data.CarOrientation.Pitch),
                Yaw   = Angle.GetFromRadians(-data.CarOrientation.Yaw),
            };

            FillDrsData(data, playerCar);
            FillBoostData(data.PushToPass, playerCar);

            playerCar.EngineTorque = Torque.FromNm(data.Player.EngineTorque);
            playerCar.EnginePower  = Power.FromKw(data.Player.EngineTorque * playerCar.EngineRpm / 9549);
        }
Esempio n. 4
0
        private bool CheckSessionStarted(R3ESharedData r3RData)
        {
            if (r3RData.SessionType != _lastSessionType)
            {
                _lastSessionType     = r3RData.SessionType;
                _sessionStartR3RTime = r3RData.Player.GameSimulationTime;
                _startSessionTime    = DateTime.Now;
                return(true);
            }

            if (r3RData.SessionPhase != -1 && !_inSession)
            {
                _inSession           = true;
                _sessionStartR3RTime = r3RData.Player.GameSimulationTime;
                _startSessionTime    = DateTime.Now;
                return(true);
            }

            if (_inSession && r3RData.SessionPhase == -1)
            {
                _inSession = false;
            }

            if (_lastSessionPhase >= 5 && r3RData.SessionPhase < 5)
            {
                _lastSessionPhase = r3RData.SessionPhase;
                return(true);
            }

            _lastSessionPhase = r3RData.SessionPhase;
            return(false);
        }
Esempio n. 5
0
 private static void AddBrakesInfo(R3ESharedData data, SimulatorDataSet simData)
 {
     simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.BrakeTemperature  = Temperature.FromCelsius(data.BrakeTemp.FrontLeft);
     simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.BrakeTemperature = Temperature.FromCelsius(data.BrakeTemp.FrontRight);
     simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.BrakeTemperature   = Temperature.FromCelsius(data.BrakeTemp.RearLeft);
     simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.BrakeTemperature  = Temperature.FromCelsius(data.BrakeTemp.RearRight);
 }
Esempio n. 6
0
 private static void AddPedalInfo(R3ESharedData data, SimulatorDataSet simData)
 {
     simData.InputInfo.ThrottlePedalPosition = data.ThrottleRaw;
     simData.InputInfo.BrakePedalPosition    = data.BrakeRaw;
     simData.InputInfo.ClutchPedalPosition   = data.ClutchRaw;
     simData.InputInfo.SteeringInput         = data.SteerInputRaw;
     simData.InputInfo.WheelAngle            = data.SteerWheelRangeDegrees * data.SteerInputRaw;
 }
Esempio n. 7
0
        internal void AddDriversData(SimulatorDataSet data, R3ESharedData r3RData)
        {
            if (r3RData.NumCars == -1)
            {
                return;
            }

            data.DriversInfo = new DriverInfo[r3RData.NumCars];
            string     playerName  = FromByteArray(r3RData.PlayerName);
            DriverInfo playersInfo = null;

            for (int i = 0; i < r3RData.NumCars; i++)
            {
                DriverData r3RDriverData = r3RData.DriverData[i];
                DriverInfo driverInfo    = CreateDriverInfo(r3RData, r3RDriverData, playerName);

                /*if (string.IsNullOrWhiteSpace(driverInfo.DriverName))
                 * {
                 *  continue;
                 * }*/

                if (driverInfo.IsPlayer)
                {
                    playersInfo = driverInfo;
                    driverInfo.CurrentLapValid = r3RData.CurrentLapValid == 1;
                    _lastPlayer = driverInfo;
                }
                else
                {
                    AddWheelInfo(driverInfo, r3RDriverData);
                    driverInfo.CurrentLapValid = r3RDriverData.CurrentLapValid == 1;
                }

                AddWheelInfo(driverInfo, r3RDriverData);
                data.DriversInfo[i] = driverInfo;
                if (driverInfo.Position == 1)
                {
                    data.SessionInfo.LeaderCurrentLap = driverInfo.CompletedLaps + 1;
                    data.LeaderInfo = driverInfo;
                }

                AddLappingInformation(data, r3RData, driverInfo);
                FillTimingInfo(driverInfo, r3RDriverData, r3RData);

                if (driverInfo.FinishStatus == DriverFinishStatus.Finished && !driverInfo.IsPlayer && driverInfo.Position > _lastPlayer?.Position)
                {
                    driverInfo.CompletedLaps--;
                    driverInfo.FinishStatus = DriverFinishStatus.None;
                }

                _connector.StoreLastTickInfo(driverInfo);
            }

            if (playersInfo != null)
            {
                data.PlayerInfo = playersInfo;
            }
        }
Esempio n. 8
0
 private void AddLappingInformation(SimulatorDataSet data, R3ESharedData r3RData, DriverInfo driverInfo)
 {
     if (data.SessionInfo.SessionType == SessionType.Race && _lastPlayer != null &&
         _lastPlayer.CompletedLaps != 0)
     {
         driverInfo.IsBeingLappedByPlayer =
             driverInfo.TotalDistance < (_lastPlayer.TotalDistance - r3RData.LayoutLength * 0.5);
         driverInfo.IsLappingPlayer =
             _lastPlayer.TotalDistance < (driverInfo.TotalDistance - r3RData.LayoutLength * 0.5);
     }
 }
Esempio n. 9
0
        private void AddFlags(R3ESharedData data, SimulatorDataSet simData)
        {
            if (data.Flags.SectorYellow.Sector1 == 1)
            {
                simData.SessionInfo.ActiveFlags.Add(FlagKind.YellowSector1);
            }

            if (data.Flags.SectorYellow.Sector2 == 1)
            {
                simData.SessionInfo.ActiveFlags.Add(FlagKind.YellowSector2);
            }

            if (data.Flags.SectorYellow.Sector3 == 1)
            {
                simData.SessionInfo.ActiveFlags.Add(FlagKind.YellowSector3);
            }
        }
Esempio n. 10
0
        private R3ESharedData Load()
        {
            if (!IsConnected)
            {
                throw new InvalidOperationException("Not connected");
            }

            MemoryMappedViewStream view   = _sharedMemory.CreateViewStream();
            BinaryReader           stream = new BinaryReader(view);

            byte[]        buffer = stream.ReadBytes(Marshal.SizeOf(typeof(R3ESharedData)));
            GCHandle      handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            R3ESharedData data   = (R3ESharedData)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(R3ESharedData));

            handle.Free();
            return(data);
        }
Esempio n. 11
0
        internal SimulatorDataSet FromR3EData(R3ESharedData data)
        {
            SimulatorDataSet simData = new SimulatorDataSet("R3E");

            simData.SimulatorSourceInfo.HasLapTimeInformation  = true;
            simData.SimulatorSourceInfo.SectorTimingSupport    = DataInputSupport.Full;
            simData.SimulatorSourceInfo.AIInstantFinish        = true;
            simData.SimulatorSourceInfo.GapInformationProvided = GapInformationKind.TimeToSurroundingDrivers;
            simData.SimulatorSourceInfo.TelemetryInfo.ContainsSuspensionVelocity  = true;
            simData.SimulatorSourceInfo.TelemetryInfo.ContainsOptimalTemperatures = true;

            // SimulatorDataSet simData = new SimulatorDataSet("R3R");
            FillSessionInfo(data, simData);
            AddDriversData(simData, data);

            FillPlayerCarInfo(data, simData);

            // PEDAL INFO
            AddPedalInfo(data, simData);

            // WaterSystemInfo
            AddWaterSystemInfo(data, simData);

            // OilSystemInfo
            AddOilSystemInfo(data, simData);

            // Brakes Info
            AddBrakesInfo(data, simData);

            // Tyre Pressure Info
            AddTyresInfo(data, simData);

            // Acceleration
            AddAcceleration(data, simData);

            //Add Additional Player Car Info
            AddPlayerCarInfo(data, simData);

            //Add Flags Info
            AddFlags(data, simData);

            simData.SessionInfo.IsMultiClass = simData.DriversInfo != null && simData.DriversInfo.Any(x => x != null && x.Position != x.PositionInClass);

            return(simData);
        }
Esempio n. 12
0
        private static void AddBrakesInfo(R3ESharedData data, SimulatorDataSet simData)
        {
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.BrakeTemperature.ActualQuantity      = Temperature.FromCelsius(data.BrakeTemp.FrontLeft.CurrentTemp);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.BrakeTemperature.IdealQuantityWindow = Temperature.FromCelsius((data.BrakeTemp.FrontLeft.HotTemp - data.BrakeTemp.FrontLeft.OptimalTemp) / 2);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.BrakeTemperature.IdealQuantity       = Temperature.FromCelsius(data.BrakeTemp.FrontLeft.OptimalTemp);

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.BrakeTemperature.ActualQuantity      = Temperature.FromCelsius(data.BrakeTemp.FrontRight.CurrentTemp);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.BrakeTemperature.IdealQuantityWindow = Temperature.FromCelsius((data.BrakeTemp.FrontRight.HotTemp - data.BrakeTemp.FrontRight.OptimalTemp) / 2);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.BrakeTemperature.IdealQuantity       = Temperature.FromCelsius(data.BrakeTemp.FrontRight.OptimalTemp);

            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.BrakeTemperature.ActualQuantity      = Temperature.FromCelsius(data.BrakeTemp.RearLeft.CurrentTemp);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.BrakeTemperature.IdealQuantityWindow = Temperature.FromCelsius((data.BrakeTemp.RearLeft.HotTemp - data.BrakeTemp.RearLeft.OptimalTemp) / 2);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.BrakeTemperature.IdealQuantity       = Temperature.FromCelsius(data.BrakeTemp.RearLeft.OptimalTemp);

            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.BrakeTemperature.ActualQuantity      = Temperature.FromCelsius(data.BrakeTemp.RearRight.CurrentTemp);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.BrakeTemperature.IdealQuantityWindow = Temperature.FromCelsius((data.BrakeTemp.RearRight.HotTemp - data.BrakeTemp.RearRight.OptimalTemp) / 2);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.BrakeTemperature.IdealQuantity       = Temperature.FromCelsius(data.BrakeTemp.RearRight.OptimalTemp);
        }
Esempio n. 13
0
        private static void AddTyresInfo(R3ESharedData data, SimulatorDataSet simData)
        {
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.TyrePressure  = Pressure.FromKiloPascals(data.TirePressure.FrontLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.TyrePressure = Pressure.FromKiloPascals(data.TirePressure.FrontRight);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.TyrePressure   = Pressure.FromKiloPascals(data.TirePressure.RearLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.TyrePressure  = Pressure.FromKiloPascals(data.TirePressure.RearRight);



            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.TyreWear  = 1 - data.TireWear.FrontLeft;
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.TyreWear = 1 - data.TireWear.FrontRight;
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.TyreWear   = 1 - data.TireWear.RearLeft;
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.TyreWear  = 1 - data.TireWear.RearRight;

            // Front Left Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.LeftTyreTemp   = Temperature.FromCelsius(data.TireTemp.FrontLeft_Left);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.RightTyreTemp  = Temperature.FromCelsius(data.TireTemp.FrontLeft_Right);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.CenterTyreTemp = Temperature.FromCelsius(data.TireTemp.FrontLeft_Center);


            // Front Right Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.LeftTyreTemp   = Temperature.FromCelsius(data.TireTemp.FrontRight_Left);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.RightTyreTemp  = Temperature.FromCelsius(data.TireTemp.FrontRight_Right);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.CenterTyreTemp = Temperature.FromCelsius(data.TireTemp.FrontRight_Center);


            // Rear Left Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.LeftTyreTemp   = Temperature.FromCelsius(data.TireTemp.RearLeft_Left);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.RightTyreTemp  = Temperature.FromCelsius(data.TireTemp.RearLeft_Right);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.CenterTyreTemp = Temperature.FromCelsius(data.TireTemp.RearLeft_Center);

            // Rear Right Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.LeftTyreTemp   = Temperature.FromCelsius(data.TireTemp.RearRight_Left);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.RightTyreTemp  = Temperature.FromCelsius(data.TireTemp.RearRight_Right);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.CenterTyreTemp = Temperature.FromCelsius(data.TireTemp.RearRight_Center);

            // Fuel System
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelCapacity  = Volume.FromLiters(data.FuelCapacity);
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelRemaining = Volume.FromLiters(data.FuelLeft);
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelPressure  = Pressure.FromKiloPascals(data.FuelPressure);
        }
Esempio n. 14
0
        protected override async Task DaemonMethod(CancellationToken cancellationToken)
        {
            while (!ShouldDisconnect)
            {
                await Task.Delay(TickTime, cancellationToken).ConfigureAwait(false);

                R3ESharedData    r3RData = Load();
                SimulatorDataSet data    = DataConvertor.FromR3EData(r3RData);
                if (CheckSessionStarted(r3RData, data))
                {
                    _lastTickInformation.Clear();
                    _sessionTime     = TimeSpan.Zero;
                    _lastSessionTime = _sessionTime;
                    RaiseSessionStartedEvent(data);
                }

                if (r3RData.GamePaused != 1 && r3RData.ControlType != (int)Constant.Control.Replay)
                {
                    if (r3RData.Player.GameSimulationTime != 0)
                    {
                        _sessionTime = TimeSpan.FromSeconds(r3RData.Player.GameSimulationTime - _sessionStartR3RTime);
                    }
                    else
                    {
                        _sessionTime = DateTime.UtcNow - _startSessionTime;
                    }
                }

                _lastSessionTime = data.SessionInfo.SessionTime;
                RaiseDataLoadedEvent(data);

                if (r3RData.ControlType == -1 && !IsProcessRunning())
                {
                    ShouldDisconnect = true;
                }
            }

            _sharedMemory = null;
            _sessionTime  = TimeSpan.Zero;
            RaiseDisconnectedEvent();
        }
Esempio n. 15
0
        private DriverInfo CreateDriverInfo(R3ESharedData r3RData, DriverData r3RDriverData, string playerName)
        {
            DriverInfo driverInfo = new DriverInfo
            {
                DriverName    = FromByteArray(r3RDriverData.DriverInfo.Name),
                CompletedLaps = r3RDriverData.CompletedLaps,
                CarName       = string.Empty,
                InPits        = r3RDriverData.InPitlane == 1
            };

            driverInfo.IsPlayer      = driverInfo.DriverName == playerName;
            driverInfo.Position      = r3RDriverData.Place;
            driverInfo.Speed         = Velocity.FromMs(r3RDriverData.CarSpeed);
            driverInfo.LapDistance   = r3RDriverData.LapDistance;
            driverInfo.TotalDistance = r3RDriverData.CompletedLaps * r3RData.LayoutLength + r3RDriverData.LapDistance;
            driverInfo.CarName       = _database.GetCarName(r3RDriverData.DriverInfo.ModelId);
            driverInfo.FinishStatus  = FromR3RStatus(r3RDriverData.FinishStatus);
            driverInfo.WorldPosition = new Point3D(Distance.FromMeters(r3RDriverData.Position.X), Distance.FromMeters(r3RDriverData.Position.Y), Distance.FromMeters(r3RDriverData.Position.Z));
            ComputeDistanceToPlayer(_lastPlayer, driverInfo, r3RData);
            return(driverInfo);
        }
Esempio n. 16
0
        private static void FillPlayersGear(R3ESharedData data, SimulatorDataSet simData)
        {
            switch (data.Gear)
            {
            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.Gear.ToString();
                break;
            }
        }
Esempio n. 17
0
        private static void FillPlayerCarInfo(R3ESharedData data, SimulatorDataSet simData)
        {
            simData.PlayerInfo.CarInfo.EngineRpm = (int)(data.EngineRps / 0.104719755);
            switch (data.Gear)
            {
            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.Gear.ToString();
                break;
            }
        }
Esempio n. 18
0
        private void AddPlayerCarInfo(R3ESharedData data, SimulatorDataSet simData)
        {
            CarInfo playerCar = simData.PlayerInfo.CarInfo;

            playerCar.CarDamageInformation.Bodywork.MediumDamageThreshold     = 0.01;
            playerCar.CarDamageInformation.Engine.MediumDamageThreshold       = 0.01;
            playerCar.CarDamageInformation.Transmission.MediumDamageThreshold = 0.01;
            playerCar.CarDamageInformation.Suspension.Damage   = 1 - data.CarDamage.Suspension;
            playerCar.CarDamageInformation.Bodywork.Damage     = 1 - data.CarDamage.Aerodynamics;
            playerCar.CarDamageInformation.Engine.Damage       = 1 - data.CarDamage.Engine;
            playerCar.CarDamageInformation.Transmission.Damage = 1 - data.CarDamage.Transmission;
            playerCar.TurboPressure    = Math.Abs(data.TurboPressure) < 0.1 ? Pressure.Zero : Pressure.FromBar(data.TurboPressure);
            playerCar.OverallDownForce = Force.GetFromNewtons(data.Player.CurrentDownforce);

            playerCar.FrontRollAngle = Angle.GetFromRadians(data.Player.FrontRollAngle);
            playerCar.RearRollAngle  = Angle.GetFromRadians(data.Player.RearRollAngle);

            playerCar.SpeedLimiterEngaged = data.PitLimiter == 1;

            FillDrsData(data, playerCar);
            FillBoostData(data.PushToPass, playerCar);
        }
Esempio n. 19
0
        protected override void DaemonMethod()
        {
            while (!ShouldDisconnect)
            {
                Thread.Sleep(TickTime);
                R3ESharedData    r3RData = Load();
                SimulatorDataSet data    = DataConvertor.FromR3EData(r3RData);
                if (CheckSessionStarted(r3RData))
                {
                    _lastTickInformation.Clear();
                    _sessionTime = new TimeSpan(0, 0, 1);
                    RaiseSessionStartedEvent(data);
                }

                if (r3RData.GamePaused != 1 && r3RData.ControlType != (int)Constant.Control.Replay)
                {
                    if (r3RData.Player.GameSimulationTime != 0)
                    {
                        _sessionTime = TimeSpan.FromSeconds(r3RData.Player.GameSimulationTime - _sessionStartR3RTime);
                    }
                    else
                    {
                        _sessionTime = DateTime.Now - _startSessionTime;
                    }
                }

                AddToQueue(data);

                if (r3RData.ControlType == -1 && !IsProcessRunning())
                {
                    ShouldDisconnect = true;
                }
            }

            _sharedMemory = null;
            _sessionTime  = new TimeSpan(0, 0, 1);
            RaiseDisconnectedEvent();
        }
Esempio n. 20
0
 private static void AddPedalInfo(R3ESharedData data, SimulatorDataSet simData)
 {
     simData.PedalInfo.ThrottlePedalPosition = data.ThrottlePedal;
     simData.PedalInfo.BrakePedalPosition    = data.BrakePedal;
     simData.PedalInfo.ClutchPedalPosition   = data.ClutchPedal;
 }
Esempio n. 21
0
        private static void AddTyresInfo(R3ESharedData data, SimulatorDataSet simData)
        {
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.TyrePressure.ActualQuantity  = Pressure.FromKiloPascals(data.TirePressure.FrontLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.TyrePressure.ActualQuantity = Pressure.FromKiloPascals(data.TirePressure.FrontRight);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.TyrePressure.ActualQuantity   = Pressure.FromKiloPascals(data.TirePressure.RearLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.TyrePressure.ActualQuantity  = Pressure.FromKiloPascals(data.TirePressure.RearRight);

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.TyreWear.ActualWear  = 1 - data.TireWear.FrontLeft;
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.TyreWear.ActualWear = 1 - data.TireWear.FrontRight;
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.TyreWear.ActualWear   = 1 - data.TireWear.RearLeft;
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.TyreWear.ActualWear  = 1 - data.TireWear.RearRight;

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.Rps  = -data.TireRps.FrontLeft;
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.Rps = -data.TireRps.FrontRight;
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.Rps   = -data.TireRps.RearLeft;
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.Rps  = -data.TireRps.RearRight;

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.DirtLevel  = data.TireDirt.FrontLeft;
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.DirtLevel = data.TireDirt.FrontRight;
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.DirtLevel   = data.TireDirt.RearLeft;
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.DirtLevel  = data.TireDirt.RearRight;

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.SuspensionTravel  = Distance.FromMeters(data.Player.SuspensionDeflection.FrontLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.SuspensionTravel = Distance.FromMeters(data.Player.SuspensionDeflection.FrontRight);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.SuspensionTravel   = Distance.FromMeters(data.Player.SuspensionDeflection.RearLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.SuspensionTravel  = Distance.FromMeters(data.Player.SuspensionDeflection.RearRight);

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.SuspensionVelocity  = Velocity.FromMs(data.Player.SuspensionVelocity.FrontLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.SuspensionVelocity = Velocity.FromMs(data.Player.SuspensionVelocity.FrontRight);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.SuspensionVelocity   = Velocity.FromMs(data.Player.SuspensionVelocity.RearLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.SuspensionVelocity  = Velocity.FromMs(data.Player.SuspensionVelocity.RearRight);

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.Camber  = Angle.GetFromRadians(data.Player.Camber.FrontLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.Camber = Angle.GetFromRadians(data.Player.Camber.FrontRight);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.Camber   = Angle.GetFromRadians(data.Player.Camber.RearLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.Camber  = Angle.GetFromRadians(data.Player.Camber.RearRight);

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.RideHeight  = Distance.FromMeters(data.Player.RideHeight.FrontLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.RideHeight = Distance.FromMeters(data.Player.RideHeight.FrontRight);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.RideHeight   = Distance.FromMeters(data.Player.RideHeight.RearLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.RideHeight  = Distance.FromMeters(data.Player.RideHeight.RearRight);

            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.TyreLoad  = Force.GetFromNewtons(data.TyreLoad.FrontLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.TyreLoad = Force.GetFromNewtons(data.TyreLoad.FrontRight);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.TyreLoad   = Force.GetFromNewtons(data.TyreLoad.RearLeft);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.TyreLoad  = Force.GetFromNewtons(data.TyreLoad.RearRight);

            // Front Left Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.CenterTyreTemp.IdealQuantity       = Temperature.FromCelsius(data.TireTemp.FrontLeft.OptimalTemp);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.CenterTyreTemp.IdealQuantityWindow = Temperature.FromCelsius((data.TireTemp.FrontLeft.HotTemp - data.TireTemp.FrontLeft.OptimalTemp) * 0.5);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.LeftTyreTemp.ActualQuantity        = Temperature.FromCelsius(data.TireTemp.FrontLeft.CurrentTemp.Left);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.RightTyreTemp.ActualQuantity       = Temperature.FromCelsius(data.TireTemp.FrontLeft.CurrentTemp.Right);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.CenterTyreTemp.ActualQuantity      = Temperature.FromCelsius(data.TireTemp.FrontLeft.CurrentTemp.Center);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontLeft.TyreCoreTemperature.ActualQuantity = Temperature.FromCelsius((data.TireTemp.FrontLeft.CurrentTemp.Left + data.TireTemp.FrontLeft.CurrentTemp.Center + data.TireTemp.FrontLeft.CurrentTemp.Right) / 3);


            // Front Right Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.CenterTyreTemp.IdealQuantity       = Temperature.FromCelsius(data.TireTemp.FrontLeft.OptimalTemp);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.CenterTyreTemp.IdealQuantityWindow = Temperature.FromCelsius((data.TireTemp.FrontLeft.HotTemp - data.TireTemp.FrontLeft.OptimalTemp) * 0.5);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.LeftTyreTemp.ActualQuantity        = Temperature.FromCelsius(data.TireTemp.FrontRight.CurrentTemp.Left);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.RightTyreTemp.ActualQuantity       = Temperature.FromCelsius(data.TireTemp.FrontRight.CurrentTemp.Right);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.CenterTyreTemp.ActualQuantity      = Temperature.FromCelsius(data.TireTemp.FrontRight.CurrentTemp.Center);
            simData.PlayerInfo.CarInfo.WheelsInfo.FrontRight.TyreCoreTemperature.ActualQuantity = Temperature.FromCelsius((data.TireTemp.FrontRight.CurrentTemp.Left + data.TireTemp.FrontRight.CurrentTemp.Center + data.TireTemp.FrontRight.CurrentTemp.Right) / 3);


            // Rear Left Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.CenterTyreTemp.IdealQuantity       = Temperature.FromCelsius(data.TireTemp.FrontLeft.OptimalTemp);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.CenterTyreTemp.IdealQuantityWindow = Temperature.FromCelsius((data.TireTemp.FrontLeft.HotTemp - data.TireTemp.FrontLeft.OptimalTemp) * 0.5);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.LeftTyreTemp.ActualQuantity        = Temperature.FromCelsius(data.TireTemp.RearLeft.CurrentTemp.Left);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.RightTyreTemp.ActualQuantity       = Temperature.FromCelsius(data.TireTemp.RearLeft.CurrentTemp.Right);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.CenterTyreTemp.ActualQuantity      = Temperature.FromCelsius(data.TireTemp.RearLeft.CurrentTemp.Center);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearLeft.TyreCoreTemperature.ActualQuantity = Temperature.FromCelsius((data.TireTemp.RearLeft.CurrentTemp.Left + data.TireTemp.RearLeft.CurrentTemp.Center + data.TireTemp.RearLeft.CurrentTemp.Right) / 3);

            // Rear Right Tyre Temps
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.CenterTyreTemp.IdealQuantity       = Temperature.FromCelsius(data.TireTemp.FrontLeft.OptimalTemp);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.CenterTyreTemp.IdealQuantityWindow = Temperature.FromCelsius((data.TireTemp.FrontLeft.HotTemp - data.TireTemp.FrontLeft.OptimalTemp) * 0.5);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.LeftTyreTemp.ActualQuantity        = Temperature.FromCelsius(data.TireTemp.RearRight.CurrentTemp.Left);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.RightTyreTemp.ActualQuantity       = Temperature.FromCelsius(data.TireTemp.RearRight.CurrentTemp.Right);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.CenterTyreTemp.ActualQuantity      = Temperature.FromCelsius(data.TireTemp.RearRight.CurrentTemp.Center);
            simData.PlayerInfo.CarInfo.WheelsInfo.RearRight.TyreCoreTemperature.ActualQuantity = Temperature.FromCelsius((data.TireTemp.RearRight.CurrentTemp.Left + data.TireTemp.RearRight.CurrentTemp.Center + data.TireTemp.RearRight.CurrentTemp.Right) / 3);

            // Fuel System
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelCapacity  = Volume.FromLiters(data.FuelCapacity);
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelRemaining = Volume.FromLiters(data.FuelLeft);
            simData.PlayerInfo.CarInfo.FuelSystemInfo.FuelPressure  = Pressure.FromKiloPascals(data.FuelPressure);
        }
Esempio n. 22
0
 private static void AddAcceleration(R3ESharedData data, SimulatorDataSet simData)
 {
     simData.PlayerInfo.CarInfo.Acceleration.XinMs = data.LocalAcceleration.X;
     simData.PlayerInfo.CarInfo.Acceleration.YinMs = data.LocalAcceleration.Y;
     simData.PlayerInfo.CarInfo.Acceleration.ZinMs = data.LocalAcceleration.Z;
 }
Esempio n. 23
0
        internal void FillSessionInfo(R3ESharedData data, SimulatorDataSet simData)
        {
            // Timing
            simData.SessionInfo.SessionTime            = _connector.SessionTime; // TimeSpan.FromSeconds(data.Player.GameSimulationTime);
            simData.SessionInfo.TrackInfo.LayoutLength = data.LayoutLength;
            simData.SessionInfo.IsActive = (Constant.SessionPhase)data.SessionPhase == Constant.SessionPhase.Green ||
                                           (Constant.SessionPhase)data.SessionPhase == Constant.SessionPhase.Checkered;
            switch ((Constant.Session)data.SessionType)
            {
            case Constant.Session.Practice:
                simData.SessionInfo.SessionType = SessionType.Practice;
                break;

            case Constant.Session.Qualify:
                simData.SessionInfo.SessionType = SessionType.Qualification;
                break;

            case Constant.Session.Race:
                simData.SessionInfo.SessionType = SessionType.Race;
                break;

            case Constant.Session.Unavailable:
                simData.SessionInfo.SessionType = SessionType.Na;
                break;

            case Constant.Session.Warmup:
                simData.SessionInfo.SessionType = SessionType.WarmUp;
                break;

            default:
                simData.SessionInfo.SessionType = SessionType.Na;
                break;
            }

            switch ((Constant.SessionPhase)data.SessionPhase)
            {
            case Constant.SessionPhase.Countdown:
            case Constant.SessionPhase.Formation:
            case Constant.SessionPhase.Gridwalk:
            case Constant.SessionPhase.Garage:
                simData.SessionInfo.SessionPhase = SessionPhase.Countdown;
                break;

            case Constant.SessionPhase.Green:
                simData.SessionInfo.SessionPhase = SessionPhase.Green;
                break;

            case Constant.SessionPhase.Checkered:
                simData.SessionInfo.SessionPhase = SessionPhase.Checkered;
                break;

            default:
                simData.SessionInfo.SessionPhase = SessionPhase.Green;
                break;
            }

            simData.SessionInfo.TrackInfo.TrackName       = FromByteArray(data.TrackName);
            simData.SessionInfo.TrackInfo.TrackLayoutName = FromByteArray(data.LayoutName);

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (data.SessionTimeRemaining != -1)
            {
                simData.SessionInfo.SessionLengthType    = SessionLengthType.Time;
                simData.SessionInfo.SessionTimeRemaining = data.SessionTimeRemaining;
            }
            else if (data.NumberOfLaps != -1)
            {
                simData.SessionInfo.SessionLengthType = SessionLengthType.Laps;
                simData.SessionInfo.TotalNumberOfLaps = data.NumberOfLaps;
            }
        }
Esempio n. 24
0
        internal void FillTimingInfo(DriverInfo driverInfo, DriverData r3EDriverData, R3ESharedData r3RData)
        {
            if (driverInfo.IsPlayer)
            {
                driverInfo.Timing.LastLapTime = r3RData.LapTimePreviousSelf != -1 ? TimeSpan.FromSeconds(r3RData.LapTimePreviousSelf) : TimeSpan.Zero;
                if (r3RData.SectorTimesCurrentSelf.Sector1 != -1 || r3RData.SectorTimesCurrentSelf.Sector2 != -1 ||
                    r3RData.SectorTimesPreviousSelf.Sector3 != -1)
                {
                    driverInfo.Timing.LastSector1Time = TimeSpan.FromSeconds(r3RData.SectorTimesCurrentSelf.Sector1);
                    driverInfo.Timing.LastSector2Time = TimeSpan.FromSeconds(r3RData.SectorTimesCurrentSelf.Sector2 - r3RData.SectorTimesCurrentSelf.Sector1);
                    driverInfo.Timing.LastSector3Time = TimeSpan.FromSeconds(r3RData.SectorTimesPreviousSelf.Sector3 - r3RData.SectorTimesPreviousSelf.Sector2);
                }
                driverInfo.Timing.CurrentSector  = r3EDriverData.TrackSector;
                driverInfo.Timing.CurrentLapTime = TimeSpan.FromSeconds(r3RData.LapTimeCurrentSelf);
                return;
            }

            if (r3EDriverData.SectorTimesCurrentSelf.Sector1 != -1 || r3EDriverData.SectorTimesCurrentSelf.Sector2 != -1 ||
                r3EDriverData.SectorTimesPreviousSelf.Sector3 != -1)
            {
                driverInfo.Timing.LastSector1Time = TimeSpan.FromSeconds(r3EDriverData.SectorTimesCurrentSelf.Sector1);
                driverInfo.Timing.LastSector2Time = TimeSpan.FromSeconds(r3EDriverData.SectorTimesCurrentSelf.Sector2 - r3EDriverData.SectorTimesCurrentSelf.Sector1);
                driverInfo.Timing.LastSector3Time = TimeSpan.FromSeconds(r3EDriverData.SectorTimesPreviousSelf.Sector3 - r3EDriverData.SectorTimesPreviousSelf.Sector2);
            }

            driverInfo.Timing.CurrentLapTime = TimeSpan.FromSeconds(r3EDriverData.LapTimeCurrentSelf);
            driverInfo.Timing.LastLapTime    = r3EDriverData.SectorTimesPreviousSelf.Sector3 != -1 ? TimeSpan.FromSeconds(r3EDriverData.SectorTimesPreviousSelf.Sector3) : TimeSpan.Zero;
            driverInfo.Timing.CurrentSector  = r3EDriverData.TrackSector;
        }
Esempio n. 25
0
        internal static void ComputeDistanceToPlayer(DriverInfo player, DriverInfo driverInfo, R3ESharedData r3RData)
        {
            if (player == null)
            {
                return;
            }

            if (driverInfo.FinishStatus == DriverInfo.DriverFinishStatus.Dq || driverInfo.FinishStatus == DriverInfo.DriverFinishStatus.Dnf ||
                driverInfo.FinishStatus == DriverInfo.DriverFinishStatus.Dnq || driverInfo.FinishStatus == DriverInfo.DriverFinishStatus.Dns)
            {
                driverInfo.DistanceToPlayer = double.MaxValue;
                return;
            }

            double trackLength       = r3RData.LayoutLength;
            double playerLapDistance = player.LapDistance;

            double distanceToPlayer = playerLapDistance - driverInfo.LapDistance;

            if (distanceToPlayer < -(trackLength / 2))
            {
                distanceToPlayer = distanceToPlayer + trackLength;
            }

            if (distanceToPlayer > (trackLength / 2))
            {
                distanceToPlayer = distanceToPlayer - trackLength;
            }

            driverInfo.DistanceToPlayer = distanceToPlayer;
        }
Esempio n. 26
0
 private static void AddWaterSystemInfo(R3ESharedData data, SimulatorDataSet simData)
 {
     simData.PlayerInfo.CarInfo.WaterSystemInfo.WaterTemperature = Temperature.FromCelsius(data.EngineWaterTemp);
 }
Esempio n. 27
0
 private static void AddOilSystemInfo(R3ESharedData data, SimulatorDataSet simData)
 {
     simData.PlayerInfo.CarInfo.OilSystemInfo.OilPressure    = Pressure.FromKiloPascals(data.EngineOilPressure);
     simData.PlayerInfo.CarInfo.OilSystemInfo.OilTemperature = Temperature.FromCelsius(data.EngineOilTemp);
 }