Skip to content

Commit 0743a97

Browse files
authored
fix: adjusting netvars manual tests (#583)
1 parent b0c37e8 commit 0743a97

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

testproject/Assets/Scripts/Testing/ManualNetworkVariableTest.cs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ public class ManualNetworkVariableTest : NetworkBehaviour
1818
private string m_Problems = string.Empty;
1919
private int m_Count = 0;
2020

21-
// todo: address issue with initial values
22-
private const int k_WaitIterations = 5;
2321
private const int k_EndIterations = 1000;
2422

2523
void Start()
2624
{
27-
Debug.Log("Start");
28-
m_TestVar.Value = 0;
2925
m_TestVar.OnValueChanged = ValueChanged;
3026
m_TestVar.Settings.WritePermission = NetworkVariablePermission.Everyone;
27+
28+
if (IsOwner)
29+
{
30+
m_TestVar.Value = 0;
31+
}
3132
}
3233

3334
void Awake()
@@ -45,7 +46,7 @@ private void FixedUpdate()
4546

4647
private void ValueChanged(int before, int after)
4748
{
48-
if (!IsLocalPlayer && !IsServer)
49+
if (!IsOwner && !IsServer)
4950
{
5051
// compute the delta in tick between client and server,
5152
// as seen from the client, when it receives a value not from itself
@@ -54,37 +55,36 @@ private void ValueChanged(int before, int after)
5455
int delta = m_TestVar.LocalTick - m_TestVar.RemoteTick;
5556
m_Count++;
5657

57-
if (m_Count > k_WaitIterations)
58+
if (!m_Valid)
5859
{
59-
if (!m_Valid)
60+
m_Valid = true;
61+
m_MinDelta = delta;
62+
m_MaxDelta = delta;
63+
m_LastRemoteTick = m_TestVar.RemoteTick;
64+
}
65+
else
66+
{
67+
m_MinDelta = Math.Min(delta, m_MinDelta);
68+
m_MaxDelta = Math.Max(delta, m_MaxDelta);
69+
70+
// tick should not go backward until wrap around (which should be a long time)
71+
if (m_TestVar.RemoteTick == m_LastRemoteTick)
6072
{
61-
m_Valid = true;
62-
m_MinDelta = delta;
63-
m_MaxDelta = delta;
64-
m_LastRemoteTick = m_TestVar.RemoteTick;
73+
m_Problems += "Same remote tick receive twice\n";
6574
}
66-
else
75+
else if (m_TestVar.RemoteTick < m_LastRemoteTick)
6776
{
68-
m_MinDelta = Math.Min(delta, m_MinDelta);
69-
m_MaxDelta = Math.Max(delta, m_MaxDelta);
70-
71-
// tick should not go backward until wrap around (which should be a long time)
72-
if (m_TestVar.RemoteTick == m_LastRemoteTick)
73-
{
74-
m_Problems += "Same remote tick receive twice\n";
75-
}
76-
else if (m_TestVar.RemoteTick < m_LastRemoteTick)
77-
{
78-
m_Problems += "Ticks went backward\n";
79-
}
77+
m_Problems += "Ticks went backward\n";
8078
}
8179
}
8280
}
8381
}
8482

8583
if (m_Count == k_EndIterations)
8684
{
87-
if (m_Problems == "" && Math.Abs(m_MaxDelta - m_MinDelta) < 3)
85+
// Let's be reasonable and allow a 5 tick difference
86+
// that could be due to timing difference, lag, queueing
87+
if (m_Problems == "" && Math.Abs(m_MaxDelta - m_MinDelta) < 5)
8888
{
8989
Debug.Log("**** TEST PASSED ****");
9090
}
@@ -98,9 +98,8 @@ private void ValueChanged(int before, int after)
9898
Debug.Log(m_Problems);
9999
}
100100
}
101-
102101
enabled = false;
103102
}
104103
}
105104
}
106-
}
105+
}

0 commit comments

Comments
 (0)