Skip to content

Commit 69fa623

Browse files
committed
formatting fixes
1 parent e5589e1 commit 69fa623

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

Assets/BossRoom/Scripts/Shared/Net/NetworkStats.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private class MovingWindowAverage
2121
public float LastRTT { get; private set; }
2222
Queue<float> m_MovingWindow = new Queue<float>();
2323
const int k_MaxWindowSizeSeconds = 3; // it should take x seconds for the value to react to change
24-
float m_MaxWindowSize => k_MaxWindowSizeSeconds / m_PingIntervalSeconds;
24+
const float k_MaxWindowSize = k_MaxWindowSizeSeconds / k_PingIntervalSeconds;
2525

2626
public void Add(float value)
2727
{
@@ -31,7 +31,7 @@ public void Add(float value)
3131

3232
void UpdateRTTSlidingWindowAverage()
3333
{
34-
if (m_MovingWindow.Count > m_MaxWindowSize)
34+
if (m_MovingWindow.Count > k_MaxWindowSize)
3535
{
3636
m_MovingWindow.Dequeue();
3737
}
@@ -42,7 +42,7 @@ void UpdateRTTSlidingWindowAverage()
4242
rttSum += singleRTT;
4343
}
4444

45-
LastRTT = rttSum / m_MaxWindowSize;
45+
LastRTT = rttSum / k_MaxWindowSize;
4646
}
4747
}
4848
// RTT
@@ -54,10 +54,11 @@ void UpdateRTTSlidingWindowAverage()
5454
// Note: when adding more stats, it might be worth it to abstract these in their own classes instead of having a bunch
5555
// of attributes floating around.
5656

57-
MovingWindowAverage BossRoomRTT = new MovingWindowAverage();
58-
MovingWindowAverage UTP_RTT = new MovingWindowAverage();
57+
const float k_PingIntervalSeconds = 0.1f;
58+
59+
MovingWindowAverage m_BossRoomRTT = new MovingWindowAverage();
60+
MovingWindowAverage m_UtpRTT = new MovingWindowAverage();
5961

60-
const float m_PingIntervalSeconds = 0.1f;
6162
float m_LastPingTime;
6263
Text m_TextStat;
6364
Text m_TextHostType;
@@ -69,7 +70,6 @@ void UpdateRTTSlidingWindowAverage()
6970

7071
ClientRpcParams m_PongClientParams;
7172

72-
7373
public override void OnNetworkSpawn()
7474
{
7575
bool isClientOnly = IsClient && !IsServer;
@@ -78,10 +78,12 @@ public override void OnNetworkSpawn()
7878
Destroy(this);
7979
return;
8080
}
81+
8182
if (IsOwner)
8283
{
8384
CreateNetworkStatsText();
8485
}
86+
8587
m_PongClientParams = new ClientRpcParams() { Send = new ClientRpcSendParams() { TargetClientIds = new[] { OwnerClientId } } };
8688
}
8789

@@ -96,7 +98,7 @@ void CreateNetworkStatsText()
9698
InitializeTextLine("No Stat", out m_TextStat);
9799
}
98100

99-
private void InitializeTextLine(string defaultText, out Text textComponent)
101+
void InitializeTextLine(string defaultText, out Text textComponent)
100102
{
101103
GameObject rootGO = new GameObject("UI Stat Text");
102104
textComponent = rootGO.AddComponent<Text>();
@@ -116,7 +118,7 @@ void FixedUpdate()
116118
var textToDisplay = string.Empty;
117119
if (!IsServer)
118120
{
119-
if (Time.realtimeSinceStartup - m_LastPingTime > m_PingIntervalSeconds)
121+
if (Time.realtimeSinceStartup - m_LastPingTime > k_PingIntervalSeconds)
120122
{
121123
// We could have had a ping/pong where the ping sends the pong and the pong sends the ping. Issue with this
122124
// is the higher the latency, the lower the sampling would be. We need pings to be sent at a regular interval
@@ -125,13 +127,12 @@ void FixedUpdate()
125127
m_CurrentRTTPingId++;
126128
m_LastPingTime = Time.realtimeSinceStartup;
127129

128-
UTP_RTT.Add(NetworkManager.NetworkConfig.NetworkTransport.GetCurrentRtt(NetworkManager.ServerClientId));
130+
m_UtpRTT.Add(NetworkManager.NetworkConfig.NetworkTransport.GetCurrentRtt(NetworkManager.ServerClientId));
129131
}
130132

131133
if (m_TextStat != null)
132134
{
133-
134-
textToDisplay = $"{textToDisplay}RTT: {(BossRoomRTT.LastRTT * 1000).ToString("0")} ms;\nUTP RTT {UTP_RTT.LastRTT.ToString("0")} ms";
135+
textToDisplay = $"{textToDisplay}RTT: {(m_BossRoomRTT.LastRTT * 1000).ToString("0")} ms;\nUTP RTT {m_UtpRTT.LastRTT.ToString("0")} ms";
135136
}
136137
}
137138

@@ -146,19 +147,18 @@ void FixedUpdate()
146147
}
147148
}
148149

149-
150150
[ServerRpc]
151-
public void PingServerRPC(int pingId, ServerRpcParams serverParams = default)
151+
void PingServerRPC(int pingId, ServerRpcParams serverParams = default)
152152
{
153153
PongClientRPC(pingId, m_PongClientParams);
154154
}
155155

156156
[ClientRpc]
157-
public void PongClientRPC(int pingId, ClientRpcParams clientParams = default)
157+
void PongClientRPC(int pingId, ClientRpcParams clientParams = default)
158158
{
159159
var startTime = m_PingHistoryStartTimes[pingId];
160160
m_PingHistoryStartTimes.Remove(pingId);
161-
BossRoomRTT.Add(Time.realtimeSinceStartup - startTime);
161+
m_BossRoomRTT.Add(Time.realtimeSinceStartup - startTime);
162162
}
163163

164164
public override void OnNetworkDespawn()
@@ -167,6 +167,7 @@ public override void OnNetworkDespawn()
167167
{
168168
Destroy(m_TextStat.gameObject);
169169
}
170+
170171
if (m_TextHostType != null)
171172
{
172173
Destroy(m_TextHostType.gameObject);

0 commit comments

Comments
 (0)