Beispiel #1
0
        private void CheckSessionFlagUpdates(SessionFlag prevFlags, SessionFlag curFlags)
        {
            if (prevFlags == null || curFlags == null)
            {
                return;
            }

            var go     = SessionFlags.StartGo;
            var green  = SessionFlags.Green;
            var yellow = SessionFlags.Caution;

            bool isGreen = !prevFlags.Contains(go) && curFlags.Contains(go) ||
                           !prevFlags.Contains(green) && curFlags.Contains(green);

            if (isGreen)
            {
                var e = new GreenFlagRaceEvent();
                e.SessionTime = _telemetry.SessionTime.Value;
                e.Lap         = Leader == null ? 0 : Leader.Live.Lap;
                this.OnRaceEvent(e);
            }

            if (!prevFlags.Contains(yellow) && curFlags.Contains(yellow))
            {
                var e = new YellowFlagRaceEvent();
                e.SessionTime = _telemetry.SessionTime.Value;
                e.Lap         = Leader == null ? 0 : Leader.Live.Lap;
                this.OnRaceEvent(e);
            }
        }
        // Example method that adds some caution flags to the string builder if they are displayed in the sim
        private void BitfieldsExample(StringBuilder sb, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // The value of SessionFlags returns a SessionFlag object which contains information about all currently active flags
            // Use the Contains method to check if it contains a specific flag.

            // EngineWarnings and CameraStates behave similarly.

            SessionFlag flags = e.TelemetryInfo.SessionFlags.Value;

            if (flags.Contains(SessionFlags.Black))
            {
                sb.AppendLine("Black flag!");
            }
            if (flags.Contains(SessionFlags.Disqualify))
            {
                sb.AppendLine("DQ");
            }
            if (flags.Contains(SessionFlags.Repair))
            {
                sb.AppendLine("Repair");
            }
            if (flags.Contains(SessionFlags.Checkered))
            {
                sb.AppendLine("Checkered");
            }
        }
Beispiel #3
0
        public void Tick()
        {
            string sType = "";

            if ((Module.SessionType == SessionType.LapRace || Module.SessionType == SessionType.TimeRace) && Module.SessionState == SessionState.Warmup)
            {
                LapText2.Text = "W";
            }
            else if (SessionTypeToString.TryGetValue(Module.SessionType, out sType))
            {
                LapText2.Text = sType;
            }
            else
            {
                LapText2.Text = "-";
            }

            if (Module.SessionState == SessionState.Racing && Module.SessionType == SessionType.LapRace && Mode == SessionMode.TimeMode)
            {
                SwitchToLap();
            }
            else if (Module.SessionType != SessionType.LapRace && Mode == SessionMode.LapMode)
            {
                SwitchToTime();
            }

            this.UpdateTime(Module.TimeRemaining);
            this.UpdateLaps(Module.LapsDriven, Module.LapsTotal);

            SessionFlag f = Module.SessionFlags;

            if (IsCheckeredFlag(f) || Module.SessionState == SessionState.Checkered || Module.SessionState == SessionState.Cooldown)
            {
                ChequeredFlag();
            }
            else if (IsYellowFlag(f))
            {
                YellowFlag();
            }
            else if (IsSafetyCar(f))
            {
                SafetyCarDeveloped();
            }
            else if (IsRedFlag(f))
            {
                RedFlag();
            }
            else if (IsWhiteFlag(f))
            {
                return;
            }
            else
            {
                Normal();
            }
        }
Beispiel #4
0
 private bool IsWhiteFlag(SessionFlag f)
 {
     return(f.FlagSet(SessionFlag.White));
 }
Beispiel #5
0
 private bool IsCheckeredFlag(SessionFlag f)
 {
     return(f.FlagSet(SessionFlag.Checkered));
 }
Beispiel #6
0
 private bool IsRedFlag(SessionFlag f)
 {
     return(f.FlagSet(SessionFlag.Red));
 }
Beispiel #7
0
 private bool IsSafetyCar(SessionFlag f)
 {
     return(f.FlagSet(SessionFlag.Caution) || f.FlagSet(SessionFlag.CautionWaving) || f.FlagSet(SessionFlag.OneLapToGreen));
 }
Beispiel #8
0
 private bool IsYellowFlag(SessionFlag f)
 {
     return(f.FlagSet(SessionFlag.Yellow) || f.FlagSet(SessionFlag.YellowWaving));
 }
Beispiel #9
0
 public static bool FlagSet(this SessionFlag value, SessionFlag flag)
 {
     return((value & flag) == flag);
 }
Beispiel #10
0
        private void CheckSessionFlagUpdates(SessionFlag prevFlags, SessionFlag curFlags)
        {
            if (prevFlags == null || curFlags == null) return;

            var go = SessionFlags.StartGo;
            var green = SessionFlags.Green;
            var yellow = SessionFlags.Caution;

            bool isGreen = !prevFlags.Contains(go) && curFlags.Contains(go)
                || !prevFlags.Contains(green) && curFlags.Contains(green);

            if (isGreen)
            {
                var e=  new GreenFlagRaceEvent();
                e.SessionTime = _telemetry.SessionTime.Value;
                e.Lap = Leader == null ? 0 : Leader.Live.Lap;
                this.OnRaceEvent(e);
            }

            if (!prevFlags.Contains(yellow) && curFlags.Contains(yellow))
            {
                var e = new YellowFlagRaceEvent();
                e.SessionTime = _telemetry.SessionTime.Value;
                e.Lap = Leader == null ? 0 : Leader.Live.Lap;
                this.OnRaceEvent(e);
            }
        }
Beispiel #11
0
        public override void Update(ConfigurationSection rootNode, API api)
        {
            SessionState = (SessionState)api.GetData("SessionState");

            List <Dictionary <string, object> > sessions = rootNode.GetMapList("SessionInfo.Sessions");
            Dictionary <string, object>         session  = sessions[sessions.Count - 1];

            object sessionLaps;

            if (session.TryGetValue("SessionLaps", out sessionLaps) && sessionLaps is string)
            {
                string laps = (string)sessionLaps;
                if (laps.StartsWith("unlimited"))
                {
                    LapsTotal = int.MaxValue;
                }
                else
                {
                    LapsTotal = int.Parse(laps);
                }
            }

            object sessionType;

            if (session.TryGetValue("SessionType", out sessionType) && sessionType is string)
            {
                string type = (string)sessionType;
                switch (type)
                {
                case "Offline Testing":
                    SessionType = Data.SessionType.OfflineTesting;
                    break;

                case "Practice":
                    SessionType = Data.SessionType.Practice;
                    break;

                case "Qualifying":
                    SessionType = Data.SessionType.Qualifying;
                    break;

                case "Race":
                    if (LapsTotal == int.MaxValue)
                    {
                        SessionType = Data.SessionType.TimeRace;
                    }
                    else
                    {
                        SessionType = Data.SessionType.LapRace;
                    }
                    break;

                case "Time Trial":
                    SessionType = Data.SessionType.TimeTrial;
                    break;

                default:
                    SessionType = Data.SessionType.None;
                    break;
                }
            }

            SessionFlag newFlag = (SessionFlag)Enum.Parse(typeof(SessionFlag), ((int)api.GetData("SessionFlags")).ToString(), true);

            if (newFlag.FlagSet(SessionFlag.White))
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    //Controller.TMTVO.Instance.Window.LapsRemainingFadeIn(1);
                }));
            }

            SessionFlags = newFlag;

            this.TimeRemaining = (int)(double)api.GetData("SessionTimeRemain");
            int lapsRemain = (int)api.GetData("SessionLapsRemain");

            if (lapsRemain + 1 <= 5 && lapsRemain + 1 > 0)
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    //Controller.TMTVO.Instance.Window.LapsRemainingFadeIn(lapsRemain + 1);
                }));
            }

            this.LapsDriven = LapsTotal - lapsRemain;
            object sessionTime;

            if (session.TryGetValue("SessionTime", out sessionTime) && sessionTime is string)
            {
                string time = ((string)sessionTime).Substring(0, ((string)sessionTime).Length - 4).Replace('.', ',');
                if (time.StartsWith("unlim"))
                {
                    TimeTotal = int.MaxValue;
                }
                else
                {
                    TimeTotal = (int)float.Parse(time);
                }
            }
        }