mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-26 23:09:37 +03:00
Make SendMessage call SendMessages instead of SendMessageToConnection
This commit is contained in:
parent
28effd140b
commit
5c11508f41
@ -48,7 +48,7 @@ namespace Steamworks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
|
||||||
private delegate void FreeFn( NetMsg* msg );
|
private delegate void FreeFn( NetMsg* msg );
|
||||||
|
|
||||||
private static readonly Stack<ReferenceCounter> ReferenceCounterPool =
|
private static readonly Stack<ReferenceCounter> ReferenceCounterPool =
|
||||||
@ -246,7 +246,7 @@ namespace Steamworks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const int Bucket512 = 512;
|
private const int Bucket512 = 512;
|
||||||
private const int Bucket1Kb = 1 * 1024;
|
private const int Bucket1Kb = 1 * 1024;
|
||||||
private const int Bucket4Kb = 4 * 1024;
|
private const int Bucket4Kb = 4 * 1024;
|
||||||
private const int Bucket16Kb = 16 * 1024;
|
private const int Bucket16Kb = 16 * 1024;
|
||||||
@ -254,8 +254,8 @@ namespace Steamworks
|
|||||||
private const int Bucket256Kb = 256 * 1024;
|
private const int Bucket256Kb = 256 * 1024;
|
||||||
|
|
||||||
private static int GetBucketSize( int size )
|
private static int GetBucketSize( int size )
|
||||||
{
|
{
|
||||||
if ( size <= Bucket512 ) return Bucket512;
|
if ( size <= Bucket512 ) return Bucket512;
|
||||||
if ( size <= Bucket1Kb ) return Bucket1Kb;
|
if ( size <= Bucket1Kb ) return Bucket1Kb;
|
||||||
if ( size <= Bucket4Kb ) return Bucket4Kb;
|
if ( size <= Bucket4Kb ) return Bucket4Kb;
|
||||||
if ( size <= Bucket16Kb ) return Bucket16Kb;
|
if ( size <= Bucket16Kb ) return Bucket16Kb;
|
||||||
|
@ -65,11 +65,30 @@ namespace Steamworks.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the best version to use.
|
/// This is the best version to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Result SendMessage( IntPtr ptr, int size, SendType sendType = SendType.Reliable )
|
public unsafe Result SendMessage( IntPtr ptr, int size, SendType sendType = SendType.Reliable )
|
||||||
{
|
{
|
||||||
|
if ( ptr == IntPtr.Zero )
|
||||||
|
throw new ArgumentNullException( nameof( ptr ) );
|
||||||
|
if ( size == 0 )
|
||||||
|
throw new ArgumentException( "`size` cannot be zero", nameof( size ) );
|
||||||
|
|
||||||
|
var copyPtr = BroadcastBufferManager.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 = BroadcastBufferManager.FreeFunctionPointer;
|
||||||
|
|
||||||
long messageNumber = 0;
|
long messageNumber = 0;
|
||||||
return SteamNetworkingSockets.Internal.SendMessageToConnection( this, ptr, (uint) size, (int)sendType, ref messageNumber );
|
SteamNetworkingSockets.Internal.SendMessages( 1, &message, &messageNumber );
|
||||||
}
|
|
||||||
|
return messageNumber >= 0
|
||||||
|
? Result.OK
|
||||||
|
: (Result)(-messageNumber);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ideally should be using an IntPtr version unless you're being really careful with the byte[] array and
|
/// Ideally should be using an IntPtr version unless you're being really careful with the byte[] array and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user