Unstable 1.1.14.0
This commit is contained in:
@@ -11,13 +11,18 @@ namespace Steamworks.Data
|
||||
/// You can override all the virtual functions to turn it into what you
|
||||
/// want it to do.
|
||||
/// </summary>
|
||||
public struct Connection
|
||||
public struct Connection : IEquatable<Connection>
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
|
||||
public bool Equals( Connection other ) => Id == other.Id;
|
||||
public override bool Equals( object obj ) => obj is Connection other && Id == other.Id;
|
||||
public override int GetHashCode() => Id.GetHashCode();
|
||||
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 );
|
||||
|
||||
/// <summary>
|
||||
/// Accept an incoming connection that has been received on a listen socket.
|
||||
@@ -64,21 +69,41 @@ namespace Steamworks.Data
|
||||
/// <summary>
|
||||
/// This is the best version to use.
|
||||
/// </summary>
|
||||
public 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 ) );
|
||||
|
||||
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;
|
||||
message->DataSize = size;
|
||||
message->FreeDataPtr = BufferManager.FreeFunctionPointer;
|
||||
message->IdxLane = laneIndex;
|
||||
|
||||
long messageNumber = 0;
|
||||
return SteamNetworkingSockets.Internal?.SendMessageToConnection( this, ptr, (uint) size, (int)sendType, ref messageNumber ) ?? Result.Fail;
|
||||
SteamNetworkingSockets.Internal?.SendMessages( 1, &message, &messageNumber );
|
||||
|
||||
return messageNumber >= 0
|
||||
? Result.OK
|
||||
: (Result)(-messageNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ideally should be using an IntPtr version unless you're being really careful with the byte[] array and
|
||||
/// you're not creating a new one every frame (like using .ToArray())
|
||||
/// </summary>
|
||||
public unsafe Result SendMessage( byte[] data, SendType sendType = SendType.Reliable )
|
||||
public unsafe Result SendMessage( byte[] data, SendType sendType = SendType.Reliable, ushort laneIndex = 0 )
|
||||
{
|
||||
fixed ( byte* ptr = data )
|
||||
{
|
||||
return SendMessage( (IntPtr)ptr, data.Length, sendType );
|
||||
return SendMessage( (IntPtr)ptr, data.Length, sendType, laneIndex );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,21 +111,21 @@ namespace Steamworks.Data
|
||||
/// Ideally should be using an IntPtr version unless you're being really careful with the byte[] array and
|
||||
/// you're not creating a new one every frame (like using .ToArray())
|
||||
/// </summary>
|
||||
public unsafe Result SendMessage( byte[] data, int offset, int length, SendType sendType = SendType.Reliable )
|
||||
public unsafe Result SendMessage( byte[] data, int offset, int length, SendType sendType = SendType.Reliable, ushort laneIndex = 0 )
|
||||
{
|
||||
fixed ( byte* ptr = data )
|
||||
{
|
||||
return SendMessage( (IntPtr)ptr + offset, length, sendType );
|
||||
return SendMessage( (IntPtr)ptr + offset, length, sendType, laneIndex );
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This creates a ton of garbage - so don't do anything with this beyond testing!
|
||||
/// </summary>
|
||||
public unsafe Result SendMessage( string str, SendType sendType = SendType.Reliable )
|
||||
public unsafe Result SendMessage( string str, SendType sendType = SendType.Reliable, ushort laneIndex = 0 )
|
||||
{
|
||||
var bytes = System.Text.Encoding.UTF8.GetBytes( str );
|
||||
return SendMessage( bytes, sendType );
|
||||
return SendMessage( bytes, sendType, laneIndex );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -121,5 +146,27 @@ namespace Steamworks.Data
|
||||
|
||||
return strVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a small set of information about the real-time state of the connection.
|
||||
/// </summary>
|
||||
public ConnectionStatus QuickStatus()
|
||||
{
|
||||
ConnectionStatus connectionStatus = default( ConnectionStatus );
|
||||
|
||||
SteamNetworkingSockets.Internal?.GetConnectionRealTimeStatus( this, ref connectionStatus, 0, null );
|
||||
|
||||
return connectionStatus;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure multiple outbound messages streams ("lanes") on a connection, and
|
||||
/// control head-of-line blocking between them.
|
||||
/// </summary>
|
||||
public Result ConfigureConnectionLanes( int[] lanePriorities, ushort[] laneWeights )
|
||||
{
|
||||
return SteamNetworkingSockets.Internal?.ConfigureConnectionLanes( this, lanePriorities.Length, lanePriorities, laneWeights )
|
||||
?? Result.Fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user