From f3ee5bec4ec308344673963158d8dac7b237f8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Straubmeier?= Date: Mon, 22 Nov 2021 17:51:40 +0100 Subject: [PATCH] Connection lanes implementation --- .../Interfaces/ISteamNetworkingSockets.cs | 6 +-- Facepunch.Steamworks/Networking/Connection.cs | 46 +++++++++++-------- Facepunch.Steamworks/Networking/NetMsg.cs | 2 + Generator/Types/BaseType.cs | 2 + 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworkingSockets.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworkingSockets.cs index 6314fe8..f11c901 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworkingSockets.cs @@ -254,12 +254,12 @@ namespace Steamworks #region FunctionMeta [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworkingSockets_ConfigureConnectionLanes", CallingConvention = Platform.CC)] - private static extern Result _ConfigureConnectionLanes( IntPtr self, Connection hConn, int nNumLanes, ref int pLanePriorities, ref ushort pLaneWeights ); + private static extern Result _ConfigureConnectionLanes( IntPtr self, Connection hConn, int nNumLanes, [In,Out] int[] pLanePriorities, [In,Out] ushort[] pLaneWeights ); #endregion - internal Result ConfigureConnectionLanes( Connection hConn, int nNumLanes, ref int pLanePriorities, ref ushort pLaneWeights ) + internal Result ConfigureConnectionLanes( Connection hConn, int nNumLanes, [In,Out] int[] pLanePriorities, [In,Out] ushort[] pLaneWeights ) { - var returnValue = _ConfigureConnectionLanes( Self, hConn, nNumLanes, ref pLanePriorities, ref pLaneWeights ); + var returnValue = _ConfigureConnectionLanes( Self, hConn, nNumLanes, pLanePriorities, pLaneWeights ); return returnValue; } diff --git a/Facepunch.Steamworks/Networking/Connection.cs b/Facepunch.Steamworks/Networking/Connection.cs index 34a6bb5..41f12e7 100644 --- a/Facepunch.Steamworks/Networking/Connection.cs +++ b/Facepunch.Steamworks/Networking/Connection.cs @@ -21,8 +21,8 @@ namespace Steamworks.Data public override string ToString() => Id.ToString(); public static implicit operator Connection( uint value ) => new Connection() { Id = value }; public static implicit operator uint( Connection value ) => value.Id; - public static bool operator ==( Connection value1, Connection value2 ) => value1.Equals(value2); - public static bool operator !=( Connection value1, Connection value2 ) => !value1.Equals(value2); + public static bool operator ==( Connection value1, Connection value2 ) => value1.Equals( value2 ); + public static bool operator !=( Connection value1, Connection value2 ) => !value1.Equals( value2 ); /// /// Accept an incoming connection that has been received on a listen socket. @@ -69,30 +69,31 @@ namespace Steamworks.Data /// /// This is the best version to use. /// - public unsafe Result SendMessage( IntPtr ptr, int size, SendType sendType = SendType.Reliable ) + public unsafe Result SendMessage( IntPtr ptr, int size, SendType sendType = SendType.Reliable, ushort laneIndex = 0 ) { - if ( ptr == IntPtr.Zero ) - throw new ArgumentNullException( nameof( ptr ) ); - if ( size == 0 ) - throw new ArgumentException( "`size` cannot be zero", nameof( size ) ); + if ( ptr == IntPtr.Zero ) + throw new ArgumentNullException( nameof( ptr ) ); + if ( size == 0 ) + throw new ArgumentException( "`size` cannot be zero", nameof( size ) ); - var copyPtr = BufferManager.Get( size, 1 ); - Buffer.MemoryCopy( (void*)ptr, (void*)copyPtr, size, size ); + var copyPtr = BufferManager.Get( size, 1 ); + Buffer.MemoryCopy( (void*)ptr, (void*)copyPtr, size, size ); - var message = SteamNetworkingUtils.AllocateMessage(); - message->Connection = this; - message->Flags = sendType; - message->DataPtr = copyPtr; + var message = SteamNetworkingUtils.AllocateMessage(); + message->Connection = this; + message->Flags = sendType; + message->DataPtr = copyPtr; message->DataSize = size; - message->FreeDataPtr = BufferManager.FreeFunctionPointer; + message->FreeDataPtr = BufferManager.FreeFunctionPointer; + message->IdxLane = laneIndex; long messageNumber = 0; SteamNetworkingSockets.Internal.SendMessages( 1, &message, &messageNumber ); - return messageNumber >= 0 - ? Result.OK - : (Result)(-messageNumber); - } + return messageNumber >= 0 + ? Result.OK + : (Result)(-messageNumber); + } /// /// Ideally should be using an IntPtr version unless you're being really careful with the byte[] array and @@ -157,5 +158,14 @@ namespace Steamworks.Data return connectionStatus; } + + /// + /// Configure multiple outbound messages streams ("lanes") on a connection, and + /// control head-of-line blocking between them. + /// + public Result ConfigureConnectionLanes( int[] lanePriorities, ushort[] laneWeights ) + { + return SteamNetworkingSockets.Internal.ConfigureConnectionLanes( this, lanePriorities.Length, lanePriorities, laneWeights ); + } } } diff --git a/Facepunch.Steamworks/Networking/NetMsg.cs b/Facepunch.Steamworks/Networking/NetMsg.cs index c84509f..63091cf 100644 --- a/Facepunch.Steamworks/Networking/NetMsg.cs +++ b/Facepunch.Steamworks/Networking/NetMsg.cs @@ -18,5 +18,7 @@ namespace Steamworks.Data internal int Channel; internal SendType Flags; internal long UserData; + internal ushort IdxLane; + internal ushort _pad1__; } } diff --git a/Generator/Types/BaseType.cs b/Generator/Types/BaseType.cs index 85b1075..e4c3f81 100644 --- a/Generator/Types/BaseType.cs +++ b/Generator/Types/BaseType.cs @@ -108,6 +108,8 @@ internal class BaseType if ( VarName == "pOutMessageNumber" ) return false; if ( VarName == "pOptions" ) return true; if ( VarName == "pLanes" ) return true; + if ( VarName == "pLanePriorities" ) return true; + if ( VarName == "pLaneWeights" ) return true; if ( VarName == "pOut" ) return false; if ( VarName == "pOutBuffer" ) return false;