Skip to content

feat: bad network conditions warning [MTT-3242] #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
May 24, 2022
Merged
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a12826a
Adding text warning to UI when UTP RTT is over a threshold
LPLafontaineB Apr 27, 2022
64995d4
adding pulsing to warning
LPLafontaineB Apr 28, 2022
d30bf8c
adding comment
LPLafontaineB Apr 28, 2022
4d863e5
Merge branch 'develop' into feature/bad-network-condition-warning
LPLafontaineB Apr 28, 2022
1aabf73
Added coloring of stats text
LPLafontaineB Apr 28, 2022
d62897d
Merge branch 'develop' into feature/bad-network-condition-warning
LPLafontaineB May 5, 2022
82c75d5
reduced increase in fontsize for bad network conditions warning
LPLafontaineB May 10, 2022
1bc8aaf
Merge branch 'develop' into feature/bad-network-condition-warning
LPLafontaineB May 11, 2022
186b9cd
made debug overlay canvas scale with screen resolution
LPLafontaineB May 12, 2022
3a68934
removing font size increase for bad conditions warning text
LPLafontaineB May 12, 2022
6b51417
Apply suggestions from code review
LPLafontaineB May 12, 2022
2311d07
formatting
LPLafontaineB May 12, 2022
4613300
Merge branch 'feature/bad-network-condition-warning' of https://githu…
LPLafontaineB May 12, 2022
00918b4
updating changelog
LPLafontaineB May 13, 2022
86fc33f
resetting scale after parenting UIText to canvas
LPLafontaineB May 17, 2022
51a707d
Merge branch 'develop' into feature/bad-network-condition-warning
LPLafontaineB May 17, 2022
6b5f057
moving the scaling fix to NetworkOverlay
LPLafontaineB May 17, 2022
e3857f2
Using TMP for NetworkLatencyWarning and increasing font size
LPLafontaineB May 17, 2022
1288950
extracted duplicated methods to NetworkOverlay
LPLafontaineB May 17, 2022
1713157
increased width of Vetical Layout Group in Debug Overlay Canvas
LPLafontaineB May 17, 2022
e4b6a2d
further increased width of vertical layout group
LPLafontaineB May 19, 2022
449c9c7
made font smaller
LPLafontaineB May 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Assets/BossRoom/Scripts/Infrastructure/NetworkStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ public ExponentialMovingAverageCalculator(float average)
const float k_PingIntervalSeconds = 0.1f;
const float k_MaxWindowSize = k_MaxWindowSizeSeconds / k_PingIntervalSeconds;

const float k_StrugglingNetworkConditionsRTTThreshold = 130;
const float k_BadNetworkConditionsRTTThreshold = 200;

ExponentialMovingAverageCalculator m_BossRoomRTT = new ExponentialMovingAverageCalculator(0);
ExponentialMovingAverageCalculator m_UtpRTT = new ExponentialMovingAverageCalculator(0);

float m_LastPingTime;
TextMeshProUGUI m_TextStat;
TextMeshProUGUI m_TextHostType;
TextMeshProUGUI m_TextBadNetworkConditions;

// When receiving pong client RPCs, we need to know when the initiating ping sent it so we can calculate its individual RTT
int m_CurrentRTTPingId;
Expand Down Expand Up @@ -88,6 +92,8 @@ void CreateNetworkStatsText()
string hostType = IsHost ? "Host" : IsClient ? "Client" : "Unknown";
InitializeTextLine($"Type: {hostType}", out m_TextHostType);
InitializeTextLine("No Stat", out m_TextStat);
InitializeTextLine("", out m_TextBadNetworkConditions);
m_TextBadNetworkConditions.fontSize *= 1.2f;
}

void InitializeTextLine(string defaultText, out TextMeshProUGUI textComponent)
Expand Down Expand Up @@ -124,6 +130,27 @@ void FixedUpdate()
if (m_TextStat != null)
{
m_TextToDisplay = $"RTT: {(m_BossRoomRTT.Average * 1000).ToString("0")} ms;\nUTP RTT {m_UtpRTT.Average.ToString("0")} ms";
if (m_UtpRTT.Average > k_BadNetworkConditionsRTTThreshold)
{
m_TextStat.color = Color.red;
}
else if (m_UtpRTT.Average > k_StrugglingNetworkConditionsRTTThreshold)
{
m_TextStat.color = Color.yellow;
}
else
{
m_TextStat.color = Color.white;
}
}

if (m_TextBadNetworkConditions != null)
{
// Right now, we only base this warning on UTP's RTT metric, but in the future we could watch for packet loss as well, or other metrics.
m_TextBadNetworkConditions.text = m_UtpRTT.Average > k_BadNetworkConditionsRTTThreshold ? "Bad Network Conditions Detected!": "";
var color = Color.red;
color.a = Mathf.PingPong(Time.time, 1f);
m_TextBadNetworkConditions.color = color;
}
}
else
Expand Down