Re-add Stomped Connection Input Unit Test (#3543)

This commit is contained in:
Conna Wiles
2025-12-03 11:53:34 +00:00
committed by GitHub
parent 3efe8ef209
commit 68538b93b0
2 changed files with 96 additions and 6 deletions

View File

@@ -113,8 +113,8 @@ public abstract partial class Connection
/// </summary>
public bool Down( [InputAction] string action )
{
// If we're the host, just use our local input instead.
if ( IsHost )
// If this connection is us, just use our local input instead.
if ( Local == this )
return Sandbox.Input.Down( action );
if ( string.IsNullOrWhiteSpace( action ) )
@@ -133,8 +133,8 @@ public abstract partial class Connection
/// </summary>
public bool Pressed( [InputAction] string action )
{
// If we're the host, just use our local input instead.
if ( IsHost )
// If this connection is us, just use our local input instead.
if ( Local == this )
return Sandbox.Input.Pressed( action );
if ( string.IsNullOrWhiteSpace( action ) )
@@ -155,8 +155,8 @@ public abstract partial class Connection
/// </summary>
public bool Released( [InputAction] string action )
{
// If we're the host, just use our local input instead.
if ( IsHost )
// If this connection is us, just use our local input instead.
if ( Local == this )
return Sandbox.Input.Released( action );
if ( string.IsNullOrWhiteSpace( action ) )

View File

@@ -31,6 +31,96 @@ public class NetworkTests
Game.TypeLibrary = _oldTypeLibrary;
}
[TestMethod]
public void NetworkedInput()
{
Assert.IsNotNull( TypeLibrary.GetType<ModelRenderer>(), "TypeLibrary hasn't been given the game assembly" );
using var scope = new Scene().Push();
var clientAndHost = new ClientAndHost( TypeLibrary );
// Become the client
clientAndHost.BecomeClient();
var inputSettings = new InputSettings();
inputSettings.InitDefault();
Input.InputSettings = inputSettings;
Input.SetAction( "Jump", true );
// Send a client tick - this will build a user command as well
Game.ActiveScene.SendClientTick( SceneNetworkSystem.Instance );
// Become the host
clientAndHost.BecomeHost();
clientAndHost.Host.ProcessMessages( InternalMessageType.ClientTick, bs =>
{
Networking.System.OnReceiveClientTick( bs, clientAndHost.Client );
} );
clientAndHost.Client.Messages.Clear();
Assert.AreEqual( true, clientAndHost.Client.Pressed( "Jump" ) );
Assert.AreEqual( true, clientAndHost.Client.Down( "Jump" ) );
// Become the client
clientAndHost.BecomeClient();
Input.ClearActions();
// Send a client tick - this will build a user command as well
Game.ActiveScene.SendClientTick( SceneNetworkSystem.Instance );
// Become the host
clientAndHost.BecomeHost();
clientAndHost.Host.ProcessMessages( InternalMessageType.ClientTick, bs =>
{
Networking.System.OnReceiveClientTick( bs, clientAndHost.Client );
} );
clientAndHost.Host.Messages.Clear();
Assert.AreEqual( true, clientAndHost.Client.Released( "Jump" ) );
Assert.AreEqual( false, clientAndHost.Client.Down( "Jump" ) );
// Let's test wrap-aware command number processing
var userCommand = new UserCommand( uint.MaxValue );
clientAndHost.Client.Input.ApplyUserCommand( userCommand );
// Become the client
clientAndHost.BecomeClient();
Input.SetAction( "Jump", true );
Assert.AreEqual( true, Connection.Local.Pressed( "Jump" ) );
Assert.AreEqual( true, Connection.Local.Down( "Jump" ) );
// Send a client tick - this will build a user command as well
Game.ActiveScene.SendClientTick( SceneNetworkSystem.Instance );
// Become the host
clientAndHost.BecomeHost();
clientAndHost.Host.ProcessMessages( InternalMessageType.ClientTick, bs =>
{
Networking.System.OnReceiveClientTick( bs, clientAndHost.Client );
} );
Assert.AreEqual( false, clientAndHost.Client.Pressed( "Forward" ) );
Assert.AreEqual( true, clientAndHost.Client.Pressed( "Jump" ) );
Assert.AreEqual( true, clientAndHost.Client.Down( "Jump" ) );
Input.ClearActions();
Input.SetAction( "Forward", true );
Assert.AreEqual( true, Connection.Local.Pressed( "Forward" ) );
Assert.AreEqual( true, Connection.Local.Down( "Forward" ) );
}
[TestMethod]
public void RegisterSyncProps()
{