Exemple #1
0
 // Use this for initialization
 void Start()
 {
     if (lapTimer == null)
     {
         lapTimer = transform.parent.GetComponent <LapTimer>();
     }
 }
Exemple #2
0
        void OnEnable()
        {
            // Assign font variables
            m_textStyle.font             = font;
            m_textStyle.fontSize         = fontSize;
            m_textStyle.normal.textColor = fontColor;
            //
            // Subscribe getLapTime method to onLap

            m_lapTimer = FindObjectOfType <LapTimer>();
            if (m_lapTimer != null)
            {
                m_lapTimer.onLap += GetLapTime;
            }

            ///// TEST DATA /////
            //m_laps.Add(new Lap(1, 82.111f, false, 27.750f, 30.610f, 29.938f, true, true, true));
            //m_laps.Add(new Lap(2, 83.298f, true, 27.740f, 29.610f, 28.938f, true, true, true));
            //m_laps.Add(new Lap(3, 82.298f, true, 28.450f, 29.610f, 27.938f, true, true, true));
            //m_laps.Add(new Lap(4, 84.298f, true, 28.950f, 27.500f, 26.938f, false, true, true));
            //m_laps.Add(new Lap(5, 82.598f, true, 27.750f, 27.600f, 27.938f, true, true, false));
            //m_laps.Add(new Lap(6, 83.998f, true, 28.750f, 27.610f, 28.938f, true, true, true));
            //m_laps.Add(new Lap(7, 82.998f, true, 27.450f, 29.610f, 29.938f, true, true, true));
            //m_laps.Add(new Lap(8, 85.498f, false, 27.350f, 28.610f, 26.838f, false, false, true));
            //m_laps.Add(new Lap(9, 82.198f, true, 28.550f, 27.610f, 26.938f, true, true, true));
            //m_laps.Add(new Lap(10, 82.398f, true, 29.750f, 27.499f, 26.938f, true, true, true));
            //m_lapCount += m_laps.Count();

            UpdateLapTable(m_laps);
        }
        public void AddLapResult_OneTimerAndManyResults()
        {
            IPAddress address = IPAddress.Parse("1.1.1.1");

            _lapTimerManager.RegisterLapTimer(address);
            int      days = 0, hours = 0, minutes = 3, seconds = 14, millis = 791;
            TimeSpan time1 = new TimeSpan(days, hours, minutes, seconds, millis);
            TimeSpan time2 = new TimeSpan(days, hours, minutes, seconds, millis + 10);
            TimeSpan time3 = new TimeSpan(days, hours, minutes, seconds + 1, millis);

            _lapTimerManager.AddLapResult(address, time1);
            _lapTimerManager.AddLapResult(address, time2);
            _lapTimerManager.AddLapResult(address, time3);

            LapTimer timer = _lapTimerManager.GetLapTimerByIPAddress(address);

            Assert.NotNull(timer);
            var addedLaps = timer.GetAllLaps();

            Assert.Equal(1, addedLaps[0].Number);
            Assert.Equal(2, addedLaps[1].Number);
            Assert.Equal(3, addedLaps[2].Number);
            Assert.Equal(time1, addedLaps[0].Time);
            Assert.Equal(time2, addedLaps[1].Time);
            Assert.Equal(time3, addedLaps[2].Time);
        }
Exemple #4
0
        void OnEnable()
        {
            // Assign font variables
            m_textStyle.font             = font;
            m_textStyle.fontSize         = fontSize;
            m_textStyle.normal.textColor = fontColor;

            // Subscribe getLapTime method to onLap

            m_lapTimer = FindObjectOfType <LapTimer>();
            if (m_lapTimer != null)
            {
                m_lapTimer.onLap += GetLapTime;
            }

            ///// TEST LAPS /////
            //m_laps.Add(new Lap(1, 11.11f, 9.11f, 66.11f, 93.41231f, true));
            //m_laps.Add(new Lap(2, 26.11f, 1f, 12f, 84.41231f, true));
            //m_laps.Add(new Lap(3, 31.11f, 20f, 999f, 95.41231f, true));
            //m_laps.Add(new Lap(4, 99.11f, 38f, 50f, 86.41231f, true));
            //m_laps.Add(new Lap(5, 20.11f, 89f, 42f, 97.41231f, true));
            //m_laps.Add(new Lap(6, 41.11f, 399f, 34f, 88.41231f, false));
            //m_laps.Add(new Lap(7, 249.11f, 56f, 36f, 99.41231f, false));
            //m_laps.Add(new Lap(8, 55f, 99f, 78f, 90.41231f, false));
            //m_laps.Add(new Lap(9, 22f, 15f, 12f, 91.41231f, false));
            //m_laps.Add(new Lap(101, 40f, 76f, 32f, 92.41231f, false));

            m_lapCount = m_laps.Count();

            UpdateLapTable(m_laps);
        }
    public void RemoveLapTimer(LapTimer t)
    {
        if (raceStatusPanel == null)
        {
            return;
        }

        int count = raceStatusPanel.transform.childCount;

        for (int i = 0; i < count; i++)
        {
            Transform  child = raceStatusPanel.transform.GetChild(i);
            RaceStatus rs    = child.GetComponent <RaceStatus>();
            if (rs.timer == t)
            {
                Destroy(child.gameObject);
                float height = (count - 1) * raceStatusHeight;
                raceStatusPanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
                raceStatusPanel.anchoredPosition = new Vector3(8.0f, -1 * height, 0.0f);
                Debug.Log("removed lap timer");
                return;
            }
        }

        Debug.LogError("failed to remove lap timer");
    }
    public void Init(LapTimer _timer, int _place, int heat, List <string> summary_text)
    {
        timer = _timer;
        string summary = heat.ToString() + "," + _place.ToString() + ",";

        summary += timer.racerName + ",";

        place.text    = _place.ToString() + ".";
        userName.text = timer.racerName;

        if (timer.IsDisqualified())
        {
            dqNot.gameObject.SetActive(true);
            lap_total.gameObject.SetActive(false);
        }

        float best = timer.GetBestLapTime();

        summary += (best / 1000f).ToString("00.00") + ",";

        for (int iLap = 0; iLap < lap_times.Length; iLap++)
        {
            Text  lap_time = lap_times[iLap];
            float t        = timer.GetLapTime(iLap);

            if (t == best)
            {
                lap_time.color = bestLapTimeColor;
            }
            else
            {
                lap_time.color = lapTimeColor;
            }

            if (t != 0.0f)
            {
                lap_time.text = (t / 1000.0f).ToString("00.00");
                summary      += lap_time.text + ",";
            }
            else
            {
                summary += "00.00" + ",";
            }
        }

        float totalTime = timer.GetTotalTime();

        lap_total.text = (totalTime / 1000.0f).ToString("00.00");

        if (timer.IsDisqualified())
        {
            summary += "DQ";
        }
        else
        {
            summary += lap_total.text;
        }

        summary_text.Add(summary);
    }
Exemple #7
0
 void Start()
 {
     spawnPosition       = GameObject.FindWithTag("Spawnpoint").transform.position;
     moveSpeed           = .1f;
     playerTrail         = GameObject.Find("Player").GetComponent <TrailRenderer>();
     playerTrail.enabled = false;
     lapTimer            = GameObject.Find("TimeText").GetComponent <LapTimer>();
 }
Exemple #8
0
 public static void Main(params string[] args)
 {
     using (var lapTimer = new LapTimer(TimeSpan.FromMilliseconds(100), remaining => Console.WriteLine(remaining)))
     {
         lapTimer.StartRace(TimeSpan.FromSeconds(5));
         System.Threading.Thread.Sleep(2000);
         lapTimer.RaceComplete();
     }
     Console.ReadLine();
 }
Exemple #9
0
        public void GetId()
        {
            LapTimer lapTimerZero = new LapTimer(0);
            LapTimer lapTimerOne  = new LapTimer(1);
            LapTimer lapTimerMax  = new LapTimer(int.MaxValue);

            Assert.Equal(0, lapTimerZero.GetId());
            Assert.Equal(1, lapTimerOne.GetId());
            Assert.Equal(int.MaxValue, lapTimerMax.GetId());
        }
Exemple #10
0
        private async void lapTimer_TimingStarted(LapTimer sender, object args)
        {
            StartTime             = DateTime.Now;
            StartPhoneOrientation = CurrentPhoneOrientation;
            await StartCameraRecording();

            if (TimingStarted != null)
            {
                TimingStarted(this, Laps);
            }
        }
Exemple #11
0
        public void UnloadGps()
        {
            if (lapTimer == null)
            {
                return;
            }

            lapTimer.GeolocatorStatusChanged      -= lapTimer_GeolocatorStatusChanged;
            lapTimer.GeolocatorUnrecoverableError -= lapTimer_GeolocatorUnrecoverableError;
            lapTimer.Dispose();
            lapTimer = null;
        }
Exemple #12
0
 void Start()
 {
     spawnPosition       = GameObject.FindWithTag("Spawnpoint").transform.position;
     moveSpeed           = .1f;
     playerTrail         = GameObject.Find("Player").GetComponent <TrailRenderer>();
     playerTrail.enabled = false;
     lapTimer            = GameObject.Find("TimeText").GetComponent <LapTimer>();
     player = GameObject.Find("Player");
     player.GetComponent <SpriteRenderer>().enabled  = true;
     player.GetComponent <PlayerBehaviour>().enabled = true;
     //playerTrail.GetComponent<Renderer>().sortingLayerName = "Foreground";
 }
Exemple #13
0
        private async void lapTimer_GeolocatorUnrecoverableError(LapTimer sender, GeolocationErrorEventArgs args)
        {
            string errorId = string.Empty;

            if (args.Exception != null)
            {
                var extraCrashData = new CrashExtraData(AppConstants.BUGSENSE_EXTRADATA_DEVICENAME, args.DeviceName);
                errorId = await BugSenseHandler.Instance.LogExceptionWithId(App.MobileService.CurrentUser, args.Exception, extraCrashData);
            }

            StopLapTimer(string.Format(args.DeviceName.Equals(AppConstants.DEFAULT_INTERNALGPS_NAME, StringComparison.OrdinalIgnoreCase)
                                        ? AppResources.Text_Error_UnableToCommunicateWithInternalGpsDevice
                                        : AppResources.Text_Error_UnableToCommunicateWithExternalGpsDevice,
                                       errorId));
        }
        public void AddLapResult_MultipleTimersAndMultipleResults()
        {
            IPAddress timer1Address = IPAddress.Parse("1.1.1.1");
            IPAddress timer2Address = IPAddress.Parse("2.2.2.2");

            _lapTimerManager.RegisterLapTimer(timer1Address);
            _lapTimerManager.RegisterLapTimer(timer2Address);

            int      days = 0, hours = 0, minutes = 3, seconds = 14, millis = 791;
            TimeSpan timer1lap1 = new TimeSpan(days, hours, minutes, seconds, millis);
            TimeSpan timer1lap2 = new TimeSpan(days, hours, minutes, seconds, millis + 10);
            TimeSpan timer1lap3 = new TimeSpan(days, hours, minutes, seconds + 1, millis);

            TimeSpan timer2lap1 = new TimeSpan(days, hours, minutes, seconds, millis + 10);
            TimeSpan timer2lap2 = new TimeSpan(days, hours, minutes, seconds + 1, millis);
            TimeSpan timer2lap3 = new TimeSpan(days, hours, minutes + 1, seconds, millis);

            _lapTimerManager.AddLapResult(timer1Address, timer1lap1);
            _lapTimerManager.AddLapResult(timer2Address, timer2lap1);
            _lapTimerManager.AddLapResult(timer1Address, timer1lap2);
            _lapTimerManager.AddLapResult(timer2Address, timer2lap2);
            _lapTimerManager.AddLapResult(timer1Address, timer1lap3);
            _lapTimerManager.AddLapResult(timer2Address, timer2lap3);

            LapTimer timer1 = _lapTimerManager.GetLapTimerByIPAddress(timer1Address);

            Assert.NotNull(timer1);
            var timer1AddedLaps = timer1.GetAllLaps();

            Assert.Equal(1, timer1AddedLaps[0].Number);
            Assert.Equal(2, timer1AddedLaps[1].Number);
            Assert.Equal(3, timer1AddedLaps[2].Number);
            Assert.Equal(timer1lap1, timer1AddedLaps[0].Time);
            Assert.Equal(timer1lap2, timer1AddedLaps[1].Time);
            Assert.Equal(timer1lap3, timer1AddedLaps[2].Time);

            LapTimer timer2 = _lapTimerManager.GetLapTimerByIPAddress(timer2Address);

            Assert.NotNull(timer2);
            var timer2AddedLaps = timer2.GetAllLaps();

            Assert.Equal(1, timer2AddedLaps[0].Number);
            Assert.Equal(2, timer2AddedLaps[1].Number);
            Assert.Equal(3, timer2AddedLaps[2].Number);
            Assert.Equal(timer2lap1, timer2AddedLaps[0].Time);
            Assert.Equal(timer2lap2, timer2AddedLaps[1].Time);
            Assert.Equal(timer2lap3, timer2AddedLaps[2].Time);
        }
Exemple #15
0
        // Update is called once per frame
        void Update()
        {
            if (bExitScene)
            {
                bExitScene = false;
                ExitScene();
            }

            if (state == State.SendTelemetry)
            {
                if (bResetCar)
                {
                    car.RestorePosRot();
                    pm.path.ResetActiveSpan();

                    if (carObj != null)
                    {
                        LapTimer t = carObj.transform.GetComponentInChildren <LapTimer>();

                        //reset last controls
                        car.RequestSteering(0.0f);
                        car.RequestThrottle(0.0f);
                        car.RequestFootBrake(10.0f);

                        if (t != null)
                        {
                            t.ResetRace();
                        }
                    }

                    bResetCar = false;
                }


                timeSinceLastCapture += Time.deltaTime;

                if (timeSinceLastCapture > 1.0f / limitFPS)
                {
                    timeSinceLastCapture -= (1.0f / limitFPS);
                    SendTelemetry();
                }

                if (ai_text != null)
                {
                    ai_text.text = string.Format("NN: {0} : {1}", ai_steering, ai_throttle);
                }
            }
        }
Exemple #16
0
 private void Start()
 {
     myCamera.m_Lens.OrthographicSize = startZoomOut;
     lapDisplayCanvas.SetActive(false);
     lastLapCanvas.SetActive(false);
     timerCanvas.SetActive(false);
     bestTimeCanvas.SetActive(false);
     quitCanvas.SetActive(false);
     lapText.text       = currentLap + " Laps";
     lapTextShadow.text = currentLap + " Laps";
     storyManager       = FindObjectOfType <StoryManager>();
     //storyIndex = FindObjectOfType<StoryIndex>();
     playerKart = FindObjectOfType <Kart>();
     darker     = FindObjectsOfType <Darker>();
     lapTimer   = FindObjectOfType <LapTimer>();
     kartHeadlights.SetActive(false);
 }
Exemple #17
0
 public TimerViewModel(LiveClient liveClient, LapViewModel bestLap, IEnumerable <TrackSectorViewModel> trackSectors, GeolocatorFactory geolocatorFactory, ICamera camera, Dispatcher dispatcher)
 {
     Dispatcher        = dispatcher;
     LapCount          = 1;
     CurrentLapTime    = TimeSpan.Zero;
     CurrentLapStatus  = TimeSpan.Zero;
     GpsStatusText     = AppResources.Text_Unit_InternalGps;
     Laps              = new ObservableCollection <LapViewModel>();
     this.trackSectors = trackSectors;
     bestLapSectors    = new Dictionary <int, TimeSpan?>();
     SetBestLapSectorsFromLap(bestLap);
     this.geolocatorFactory = geolocatorFactory;
     this.camera            = camera;
     lapTimer = new LapTimer(geolocatorFactory, App.ViewModel.Settings.IsMetricUnits);
     lapTimer.GeolocatorStatusChanged      += lapTimer_GeolocatorStatusChanged;
     lapTimer.GeolocatorUnrecoverableError += lapTimer_GeolocatorUnrecoverableError;
 }
        public void AddLapResult_OneTimerAndOneResult()
        {
            IPAddress address = IPAddress.Parse("1.1.1.1");

            _lapTimerManager.RegisterLapTimer(address);
            var time = new TimeSpan(0, 1, 20);

            _lapTimerManager.AddLapResult(address, time);

            LapTimer timer = _lapTimerManager.GetLapTimerByIPAddress(address);

            Assert.NotNull(timer);
            var addedLaps = timer.GetAllLaps();

            Assert.Single(addedLaps);
            Assert.Equal(time, addedLaps[0].Time);
        }
    public void AddLapTimer(LapTimer t, tk.JsonTcpClient client)
    {
        if (raceStatusPrefab == null)
        {
            return;
        }

        Debug.Log("Adding lap timer.");
        GameObject go = Instantiate(raceStatusPrefab) as GameObject;
        RaceStatus rs = go.GetComponent <RaceStatus>();

        rs.Init(t, client);
        go.transform.SetParent(raceStatusPanel.transform);

        float height = raceStatusPanel.transform.childCount * raceStatusHeight;

        raceStatusPanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
        raceStatusPanel.anchoredPosition = new Vector3(8.0f, -1 * height, 0.0f);
    }
Exemple #20
0
 private void lapTimer_SectorComplete(LapTimer sender, LapEventArgs args)
 {
     Dispatcher.BeginInvoke(() =>
     {
         var sectorSplit       = args.Lap.EndElapsedTime - lapStartElapsed;
         var bestLapSectorTime = bestLapSectors.Any()
                                     ? bestLapSectors[args.Lap.SectorNumber]
                                     : (TimeSpan?)null;
         if (bestLapSectorTime.HasValue)
         {
             var sectorTimeDifference = sectorSplit - bestLapSectorTime.Value;
             CurrentLapStatus         = sectorTimeDifference;
         }
         else
         {
             CurrentLapStatus = TimeSpan.Zero;
         }
     });
 }
Exemple #21
0
        private void lapTimer_LapComplete(LapTimer sender, LapEventArgs args)
        {
            Dispatcher.BeginInvoke(() =>
            {
                lapStartElapsed = args.Lap.EndElapsedTime;
                Laps.Insert(0, args.Lap);
                LapCount = args.Lap.LapNumber + 1;
                if ((bestLapSectors == null || !bestLapSectors.Any()) && lapTimer.GenerateSectors && lapTimer.SectorCoordinates != null && lapTimer.SectorCoordinates.Any())
                {
                    trackSectors = lapTimer.SectorCoordinates;
                    SetBestLapSectorsFromLap(args.Lap);
                    CurrentLapStatus = TimeSpan.Zero;
                    return;
                }

                if (bestLapSectors == null || !bestLapSectors.Any())
                {
                    SetBestLapSectorsFromLap(args.Lap);
                }

                var bestLapSectorTime = bestLapSectors.Any()
                                                ? bestLapSectors[args.Lap.SectorNumber]
                                                : (TimeSpan?)null;
                if (bestLapSectorTime.HasValue)
                {
                    var sectorTimeDifference = args.Lap.LapTime - bestLapSectorTime.Value;
                    CurrentLapStatus         = sectorTimeDifference;
                    if (sectorTimeDifference < TimeSpan.Zero)
                    {
                        SetBestLapSectorsFromLap(args.Lap);
                    }
                }
                else
                {
                    SetBestLapSectorsFromLap(args.Lap);
                    CurrentLapStatus = TimeSpan.Zero;
                }
            });
        }
Exemple #22
0
        private void lapTimer_GeolocatorStatusChanged(LapTimer sender, StatusChangedEventArgs args)
        {
            Dispatcher.BeginInvoke(() =>
            {
                if (lapTimer == null)
                {
                    return;
                }

                switch (args.Status)
                {
                case PositionStatus.Initializing:
                    IsDataLoading     = true;
                    LoadingStatusText = AppResources.Text_LoadingStatus_StartingGps;
                    GpsStatusText     = lapTimer.UsingInternalGps ? AppResources.Text_Unit_InternalGps : AppResources.Text_Unit_ExternalGps;
                    GpsStatusIsOk     = false;
                    break;

                case PositionStatus.Ready:
                    LoadingStatusText = string.Empty;
                    IsDataLoading     = false;
                    GpsStatusText     = lapTimer.UsingInternalGps ? AppResources.Text_Unit_InternalGps : AppResources.Text_Unit_ExternalGps;
                    GpsStatusIsOk     = true;
                    break;

                case PositionStatus.NoData:
                case PositionStatus.NotAvailable:
                case PositionStatus.Disabled:
                case PositionStatus.NotInitialized:
                default:
                    LoadingStatusText = string.Empty;
                    IsDataLoading     = false;
                    GpsStatusText     = lapTimer.UsingInternalGps ? AppResources.Text_Unit_InternalGps : AppResources.Text_Unit_ExternalGps;
                    GpsStatusIsOk     = false;
                    break;
                }
            });
        }
Exemple #23
0
 public void Init(LapTimer _timer, Competitor c)
 {
     timer = _timer;
     dqNot.gameObject.SetActive(false);
     comp = c;
 }
Exemple #24
0
 void Start()
 {
     lapTimer      = FindObjectOfType <LapTimer>();
     lapController = FindObjectOfType <LapController>();
     StartLap();
 }
Exemple #25
0
 void Start()
 {
     lapTimer = FindObjectOfType <LapTimer>();
     gc       = FindObjectOfType <GameController>();
 }
Exemple #26
0
        // Update is called once per frame
        void Update()
        {
            if (bExitScene)
            {
                bExitScene = false;
                ExitScene();
            }

            if (state == State.SendTelemetry)
            {
                if (bResetCar)
                {
                    car.RestorePosRot();
                    pm.path.ResetActiveSpan();

                    if (carObj != null)
                    {
                        LapTimer t = carObj.transform.GetComponentInChildren <LapTimer>();

                        //reset last controls
                        car.RequestSteering(0.0f);
                        car.RequestThrottle(0.0f);
                        car.RequestFootBrake(10.0f);

                        if (t != null)
                        {
                            t.ResetRace();
                        }

                        GameObject body = CarSpawner.getChildGameObject(carObj, "body");
                        if (body != null)
                        {
                            RaceCheckPoint[] checkPoints = GameObject.FindObjectsOfType <RaceCheckPoint>();
                            foreach (RaceCheckPoint cp in checkPoints)
                            {
                                if (cp.RemoveBody(body))
                                {
                                    Debug.Log("resetting checkpoint.");
                                }
                                else
                                {
                                    Debug.LogWarning("failed to reset checkpoint.");
                                }
                            }
                        }
                        else
                        {
                            Debug.LogWarning("failed to find car body.");
                        }
                    }

                    bResetCar = false;
                }


                timeSinceLastCapture += Time.deltaTime;

                if (timeSinceLastCapture > 1.0f / limitFPS)
                {
                    timeSinceLastCapture -= (1.0f / limitFPS);
                    SendTelemetry();
                }

                if (ai_text != null)
                {
                    ai_text.text = string.Format("NN: {0} : {1}", ai_steering, ai_throttle);
                }
            }
        }
 public void Init(LapTimer _timer, tk.JsonTcpClient _client)
 {
     timer = _timer;
     dqNot.gameObject.SetActive(false);
     client = _client;
 }