@@ -18,16 +18,17 @@ public class ManualNetworkVariableTest : NetworkBehaviour
18
18
private string m_Problems = string . Empty ;
19
19
private int m_Count = 0 ;
20
20
21
- // todo: address issue with initial values
22
- private const int k_WaitIterations = 5 ;
23
21
private const int k_EndIterations = 1000 ;
24
22
25
23
void Start ( )
26
24
{
27
- Debug . Log ( "Start" ) ;
28
- m_TestVar . Value = 0 ;
29
25
m_TestVar . OnValueChanged = ValueChanged ;
30
26
m_TestVar . Settings . WritePermission = NetworkVariablePermission . Everyone ;
27
+
28
+ if ( IsOwner )
29
+ {
30
+ m_TestVar . Value = 0 ;
31
+ }
31
32
}
32
33
33
34
void Awake ( )
@@ -45,7 +46,7 @@ private void FixedUpdate()
45
46
46
47
private void ValueChanged ( int before , int after )
47
48
{
48
- if ( ! IsLocalPlayer && ! IsServer )
49
+ if ( ! IsOwner && ! IsServer )
49
50
{
50
51
// compute the delta in tick between client and server,
51
52
// as seen from the client, when it receives a value not from itself
@@ -54,37 +55,36 @@ private void ValueChanged(int before, int after)
54
55
int delta = m_TestVar . LocalTick - m_TestVar . RemoteTick ;
55
56
m_Count ++ ;
56
57
57
- if ( m_Count > k_WaitIterations )
58
+ if ( ! m_Valid )
58
59
{
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 )
60
72
{
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 " ;
65
74
}
66
- else
75
+ else if ( m_TestVar . RemoteTick < m_LastRemoteTick )
67
76
{
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 " ;
80
78
}
81
79
}
82
80
}
83
81
}
84
82
85
83
if ( m_Count == k_EndIterations )
86
84
{
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 )
88
88
{
89
89
Debug . Log ( "**** TEST PASSED ****" ) ;
90
90
}
@@ -98,9 +98,8 @@ private void ValueChanged(int before, int after)
98
98
Debug . Log ( m_Problems ) ;
99
99
}
100
100
}
101
-
102
101
enabled = false ;
103
102
}
104
103
}
105
104
}
106
- }
105
+ }
0 commit comments