@@ -31,6 +31,96 @@ public void TestCleanup()
3131 Game . TypeLibrary = _oldTypeLibrary ;
3232 }
3333
34+ [ TestMethod ]
35+ public void NetworkedInput ( )
36+ {
37+ Assert . IsNotNull ( TypeLibrary . GetType < ModelRenderer > ( ) , "TypeLibrary hasn't been given the game assembly" ) ;
38+
39+ using var scope = new Scene ( ) . Push ( ) ;
40+
41+ var clientAndHost = new ClientAndHost ( TypeLibrary ) ;
42+
43+ // Become the client
44+ clientAndHost . BecomeClient ( ) ;
45+
46+ var inputSettings = new InputSettings ( ) ;
47+ inputSettings . InitDefault ( ) ;
48+
49+ Input . InputSettings = inputSettings ;
50+ Input . SetAction ( "Jump" , true ) ;
51+
52+ // Send a client tick - this will build a user command as well
53+ Game . ActiveScene . SendClientTick ( SceneNetworkSystem . Instance ) ;
54+
55+ // Become the host
56+ clientAndHost . BecomeHost ( ) ;
57+
58+ clientAndHost . Host . ProcessMessages ( InternalMessageType . ClientTick , bs =>
59+ {
60+ Networking . System . OnReceiveClientTick ( bs , clientAndHost . Client ) ;
61+ } ) ;
62+
63+ clientAndHost . Client . Messages . Clear ( ) ;
64+
65+ Assert . AreEqual ( true , clientAndHost . Client . Pressed ( "Jump" ) ) ;
66+ Assert . AreEqual ( true , clientAndHost . Client . Down ( "Jump" ) ) ;
67+
68+ // Become the client
69+ clientAndHost . BecomeClient ( ) ;
70+
71+ Input . ClearActions ( ) ;
72+
73+ // Send a client tick - this will build a user command as well
74+ Game . ActiveScene . SendClientTick ( SceneNetworkSystem . Instance ) ;
75+
76+ // Become the host
77+ clientAndHost . BecomeHost ( ) ;
78+
79+ clientAndHost . Host . ProcessMessages ( InternalMessageType . ClientTick , bs =>
80+ {
81+ Networking . System . OnReceiveClientTick ( bs , clientAndHost . Client ) ;
82+ } ) ;
83+
84+ clientAndHost . Host . Messages . Clear ( ) ;
85+
86+ Assert . AreEqual ( true , clientAndHost . Client . Released ( "Jump" ) ) ;
87+ Assert . AreEqual ( false , clientAndHost . Client . Down ( "Jump" ) ) ;
88+
89+ // Let's test wrap-aware command number processing
90+ var userCommand = new UserCommand ( uint . MaxValue ) ;
91+
92+ clientAndHost . Client . Input . ApplyUserCommand ( userCommand ) ;
93+
94+ // Become the client
95+ clientAndHost . BecomeClient ( ) ;
96+
97+ Input . SetAction ( "Jump" , true ) ;
98+
99+ Assert . AreEqual ( true , Connection . Local . Pressed ( "Jump" ) ) ;
100+ Assert . AreEqual ( true , Connection . Local . Down ( "Jump" ) ) ;
101+
102+ // Send a client tick - this will build a user command as well
103+ Game . ActiveScene . SendClientTick ( SceneNetworkSystem . Instance ) ;
104+
105+ // Become the host
106+ clientAndHost . BecomeHost ( ) ;
107+
108+ clientAndHost . Host . ProcessMessages ( InternalMessageType . ClientTick , bs =>
109+ {
110+ Networking . System . OnReceiveClientTick ( bs , clientAndHost . Client ) ;
111+ } ) ;
112+
113+ Assert . AreEqual ( false , clientAndHost . Client . Pressed ( "Forward" ) ) ;
114+ Assert . AreEqual ( true , clientAndHost . Client . Pressed ( "Jump" ) ) ;
115+ Assert . AreEqual ( true , clientAndHost . Client . Down ( "Jump" ) ) ;
116+
117+ Input . ClearActions ( ) ;
118+ Input . SetAction ( "Forward" , true ) ;
119+
120+ Assert . AreEqual ( true , Connection . Local . Pressed ( "Forward" ) ) ;
121+ Assert . AreEqual ( true , Connection . Local . Down ( "Forward" ) ) ;
122+ }
123+
34124 [ TestMethod ]
35125 public void RegisterSyncProps ( )
36126 {
0 commit comments