mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-12 22:58:01 +03:00
Internal interfaces do the await callback automatically
This commit is contained in:
parent
cce25e6f77
commit
d9da40c0e8
@ -16,13 +16,23 @@ namespace Steamworks
|
|||||||
CallHandle = callbackHandle;
|
CallHandle = callbackHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsComplete()
|
public bool IsComplete( out bool failed )
|
||||||
{
|
{
|
||||||
return Utils.IsCallComplete( CallHandle, out bool failed );
|
return Utils.IsCallComplete( CallHandle, out failed );
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? GetResult()
|
public async Task<T?> GetResult()
|
||||||
{
|
{
|
||||||
|
bool failed = false;
|
||||||
|
|
||||||
|
while ( !IsComplete( out failed ) )
|
||||||
|
{
|
||||||
|
await Task.Delay( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( failed )
|
||||||
|
return null;
|
||||||
|
|
||||||
return Utils.GetResult<T>( CallHandle );
|
return Utils.GetResult<T>( CallHandle );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using SteamNative;
|
using SteamNative;
|
||||||
|
|
||||||
|
|
||||||
@ -337,9 +338,9 @@ namespace Steamworks.Internal
|
|||||||
private GetFileDetailsDelegate GetFileDetailsDelegatePointer;
|
private GetFileDetailsDelegate GetFileDetailsDelegatePointer;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
public SteamApiCallback<FileDetailsResult_t> GetFileDetails( string pszFileName )
|
public async Task<FileDetailsResult_t?> GetFileDetails( string pszFileName )
|
||||||
{
|
{
|
||||||
return new SteamApiCallback<FileDetailsResult_t>( GetFileDetailsDelegatePointer( Self, pszFileName ) );
|
return await (new SteamApiCallback<FileDetailsResult_t>( GetFileDetailsDelegatePointer( Self, pszFileName ) )).GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region FunctionMeta
|
#region FunctionMeta
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using SteamNative;
|
using SteamNative;
|
||||||
|
|
||||||
|
|
||||||
@ -266,9 +267,9 @@ namespace Steamworks.Internal
|
|||||||
private CheckFileSignatureDelegate CheckFileSignatureDelegatePointer;
|
private CheckFileSignatureDelegate CheckFileSignatureDelegatePointer;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
public SteamApiCallback<CheckFileSignature_t> CheckFileSignature( string szFileName )
|
public async Task<CheckFileSignature_t?> CheckFileSignature( string szFileName )
|
||||||
{
|
{
|
||||||
return new SteamApiCallback<CheckFileSignature_t>( CheckFileSignatureDelegatePointer( Self, szFileName ) );
|
return await (new SteamApiCallback<CheckFileSignature_t>( CheckFileSignatureDelegatePointer( Self, szFileName ) )).GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region FunctionMeta
|
#region FunctionMeta
|
||||||
|
@ -17,6 +17,7 @@ namespace Generator
|
|||||||
WriteLine( $"using System;" );
|
WriteLine( $"using System;" );
|
||||||
WriteLine( $"using System.Runtime.InteropServices;" );
|
WriteLine( $"using System.Runtime.InteropServices;" );
|
||||||
WriteLine( $"using System.Text;" );
|
WriteLine( $"using System.Text;" );
|
||||||
|
WriteLine( $"using System.Threading.Tasks;" );
|
||||||
WriteLine( $"using SteamNative;" );
|
WriteLine( $"using SteamNative;" );
|
||||||
WriteLine();
|
WriteLine();
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ internal class SteamApiCallType : BaseType
|
|||||||
{
|
{
|
||||||
public string CallResult;
|
public string CallResult;
|
||||||
public override string TypeName => "SteamAPICall_t";
|
public override string TypeName => "SteamAPICall_t";
|
||||||
public override string Return( string varname ) => $"return new SteamApiCallback<{CallResult}>( {varname} );";
|
public override string Return( string varname ) => $"return await (new SteamApiCallback<{CallResult}>( {varname} )).GetResult();";
|
||||||
public override string ReturnType => $"SteamApiCallback<{CallResult}>";
|
public override string ReturnType => $"async Task<{CallResult}?>";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CSteamIdType : BaseType
|
internal class CSteamIdType : BaseType
|
||||||
|
Loading…
x
Reference in New Issue
Block a user