Beispiel #1
0
        protected override void OnCollision(MsgClientEvent msg)
        {
            // Contact handling is now done by the backend completely - that is we just report any
            // collision with another car
            if (msg.Subtype == (byte)ACSProtocol.MessageType.ACSP_CE_COLLISION_WITH_CAR)
            {
                DriverInfo driver = null;
                if (!PluginManager.TryGetDriverInfo(Convert.ToByte(msg.CarId), out driver))
                {
                    throw new Exception("Driver not found: " + msg.CarId);
                }

                DriverInfo otherDriver = null;
                if (!PluginManager.TryGetDriverInfo(Convert.ToByte(msg.OtherCarId), out otherDriver))
                {
                    throw new Exception("(Other) Driver not found: " + msg.OtherCarId);
                }

                var driversCache      = GetDriversCache(driver, 980);
                var otherDriversCache = GetDriversCache(otherDriver, 980);

                var driversDistance = _distancesToReport[driver];
                _distancesToReport[driver] = new MRDistanceHelper();

                TrySendDistance(driver, true);
                MRBackend.CollisionAsyncV22(msg.CreationDate, msg.CarId, msg.OtherCarId, msg.RelativeVelocity, driver.LastSplinePosition, msg.RelativePosition.X, msg.RelativePosition.Z, msg.WorldPosition.X, msg.WorldPosition.Z, driversCache.ToArray(), otherDriversCache.ToArray(), driversDistance);
            }
        }
Beispiel #2
0
        private void TrySendDistance(DriverInfo di, bool forced = false)
        {
            if (!_distancesToReport.ContainsKey(di))
            {
                _distancesToReport.Add(di, new MRDistanceHelper());
            }

            // New approach: We'll send the distance set as soon as a driver crosses a TrackDefinition.Split
            #region legacy approach: fixed distance
            if (CurrentTrackDefinition == null || CurrentTrackDefinition.Splits == null)
            {
                var distanceCached = _distancesToReport[di];
                // Then we'll do it in different resolutions; the first meters are more important than the later ones
                if (di.Distance > REGULAR_DISTANCE && distanceCached.MetersDriven > 2000 || forced) // After 2km, we'll just report in big chunks - or if forced
                {
                    MRBackend.DistanceDrivenAsync(di.CarId, distanceCached);
                    _distancesToReport[di] = new MRDistanceHelper();
                }
                else if (di.Distance < REGULAR_DISTANCE && distanceCached.MetersDriven > 200) // 200m is about "left pits", so we'll report this until
                {
                    MRBackend.DistanceDrivenAsync(di.CarId, distanceCached);
                    _distancesToReport[di] = new MRDistanceHelper();
                }
            }
            #endregion
            else
            {
                try
                {
                    if (di.LastCarUpdate != null && di.LastCarUpdate.List.Count > 1)
                    {
                        var lastPos = di.LastCarUpdate.Previous.Value;
                        var thisPos = di.LastCarUpdate.Value;

                        foreach (var split in CurrentTrackDefinition.Splits)
                        {
                            if (lastPos.NormalizedSplinePosition < split && thisPos.NormalizedSplinePosition > split)
                            {
                                // Gotcha!
                                var distanceCached = _distancesToReport[di];
                                _distancesToReport[di] = new MRDistanceHelper();

                                distanceCached.SplinePosCurrent     = thisPos.NormalizedSplinePosition;
                                distanceCached.SplinePosTimeCurrent = Convert.ToInt32(thisPos.CreationDate.Subtract(di.CurrentLapStart).TotalMilliseconds);
                                distanceCached.SplinePosLast        = lastPos.NormalizedSplinePosition;
                                distanceCached.SplinePosTimeLast    = Convert.ToInt32(lastPos.CreationDate.Subtract(di.CurrentLapStart).TotalMilliseconds);
                                MRBackend.DistanceDrivenAsync(di.CarId, distanceCached);
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    PluginManager.Log(ex);
                }
            }
        }
Beispiel #3
0
 public void CollisionAsyncV22(DateTime creationDate, byte carId, byte otherCarId, float relativeVelocity, float lastSplinePosition, float relativeX, float relativeZ, float worldX, float worldZ, CarUpdateHistory[] historyCar, CarUpdateHistory[] historyOtherCar, MRDistanceHelper distanceCar)
 {
     EnqueueBackendMessage(() => { return(_mrserver.CollisionV24(CurrentSessionGuid, creationDate, carId, otherCarId, relativeVelocity, lastSplinePosition, relativeX, relativeZ, worldX, worldZ, historyCar, historyOtherCar, distanceCar)); });
 }
Beispiel #4
0
 public void DistanceDrivenAsync(byte carId, MRDistanceHelper distanceDriven)
 {
     EnqueueBackendMessage(() => { return(_mrserver.DistanceDriven(CurrentSessionGuid, carId, distanceDriven)); });
 }
Beispiel #5
0
        private void SendDistance(DriverInfo di, bool forced = false)
        {
            if (!_distancesToReport.ContainsKey(di))
                _distancesToReport.Add(di, new MRDistanceHelper());

            var distanceCached = _distancesToReport[di];
            // Then we'll do it in different resolutions; the first meters are more important than the later ones
            if (di.Distance > REGULAR_DISTANCE && distanceCached.MetersDriven > 2000 || forced) // After 2km, we'll just report in big chunks - or if forced
            {
                PluginManager.Log(DateTime.Now.TimeOfDay.ToString() + "- Send DistanceDriven: " + di.CarId + ": " + distanceCached.MetersDriven);
                HandleClientActions(LiveDataServer.DistanceDriven(CurrentSessionGuid, di.CarId, distanceCached));
                _distancesToReport[di] = new MRDistanceHelper();
            }
            else if (di.Distance < REGULAR_DISTANCE && distanceCached.MetersDriven > 200) // 200m is about "left pits", so we'll report this until
            {
                PluginManager.Log(DateTime.Now.TimeOfDay.ToString() + "- Send DistanceDriven: " + di.CarId + ": " + distanceCached.MetersDriven);
                HandleClientActions(LiveDataServer.DistanceDriven(CurrentSessionGuid, di.CarId, distanceCached));
                _distancesToReport[di] = new MRDistanceHelper();
            }
        }