< Summary

Class:DCL.FPSDisplay.FPSDisplay
Assembly:FPSDisplay
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/FPSDisplay/FPSDisplay.cs
Covered lines:0
Uncovered lines:33
Coverable lines:33
Total lines:79
Line coverage:0% (0 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%12300%
OnOtherPlayersModified(...)0%2100%
OnDisable()0%2100%
UpdateLabelLoop()0%12300%
UpdateLabel()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/FPSDisplay/FPSDisplay.cs

#LineLine coverage
 1using System.Collections;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5namespace DCL.FPSDisplay
 6{
 7
 8    public class FPSDisplay : MonoBehaviour
 9    {
 10        private const float REFRESH_SECONDS = 0.1f;
 11
 12        [SerializeField] private Text label;
 13        [SerializeField] private PerformanceMetricsDataVariable performanceData;
 14
 015        private BaseDictionary<string, Player> otherPlayers => DataStore.i.player.otherPlayers;
 16        private int lastPlayerCount = 0;
 17
 18        private void OnEnable()
 19        {
 020            if (label == null || performanceData == null)
 021                return;
 22
 023            lastPlayerCount = otherPlayers.Count();
 024            otherPlayers.OnAdded += OnOtherPlayersModified;
 025            otherPlayers.OnRemoved += OnOtherPlayersModified;
 26
 027            StartCoroutine(UpdateLabelLoop());
 028        }
 29
 30        private void OnOtherPlayersModified(string playerName, Player player)
 31        {
 032            lastPlayerCount = otherPlayers.Count();
 033        }
 34
 35        private void OnDisable()
 36        {
 037            otherPlayers.OnAdded -= OnOtherPlayersModified;
 038            otherPlayers.OnRemoved -= OnOtherPlayersModified;
 039            StopAllCoroutines();
 040        }
 41
 42        private IEnumerator UpdateLabelLoop()
 43        {
 044            while (true)
 45            {
 046                UpdateLabel();
 47
 048                yield return new WaitForSeconds(REFRESH_SECONDS);
 49            }
 50        }
 51
 52        private void UpdateLabel()
 53        {
 054            float dt = Time.unscaledDeltaTime;
 55
 056            float fps = performanceData.Get().fpsCount;
 57
 058            string fpsFormatted = fps.ToString("##");
 059            string msFormatted = (dt * 1000).ToString("##");
 60
 061            string targetText = string.Empty;
 62
 063            string NO_DECIMALS = "##";
 064            string TWO_DECIMALS = "##.00";
 065            targetText += $"Nearby players: {lastPlayerCount}\n";
 066            targetText += $"Hiccups in the last 1000 frames: {performanceData.Get().hiccupCount}\n";
 067            targetText += $"Hiccup loss: {(100.0f * performanceData.Get().hiccupSum / performanceData.Get().totalSeconds
 068            targetText += $"Bad Frames Percentile: {((performanceData.Get().hiccupCount) / 10.0f).ToString(NO_DECIMALS)}
 069            targetText += $"Current {msFormatted} ms (fps: {fpsFormatted})";
 70
 071            if (label.text != targetText)
 72            {
 073                label.text = targetText;
 74            }
 75
 076            FPSColoring.DisplayColor(label, fps);
 077        }
 78    }
 79}