mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
CallResults are queried
This commit is contained in:
parent
a82f6fc8ed
commit
04c7eb59dc
@ -171,6 +171,11 @@ public void AddScoresCallback()
|
|||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
client.Update();
|
client.Update();
|
||||||
|
|
||||||
|
if ( board.IsError )
|
||||||
|
{
|
||||||
|
throw new Exception( "Board is Error" );
|
||||||
|
}
|
||||||
|
|
||||||
if (time.Elapsed.TotalSeconds > 10)
|
if (time.Elapsed.TotalSeconds > 10)
|
||||||
{
|
{
|
||||||
throw new Exception("board.IsValid took too long");
|
throw new Exception("board.IsValid took too long");
|
||||||
|
@ -25,6 +25,7 @@ public class BaseSteamworks : IDisposable
|
|||||||
internal Interop.NativeInterface native;
|
internal Interop.NativeInterface native;
|
||||||
|
|
||||||
private List<SteamNative.CallbackHandle> CallbackHandles = new List<SteamNative.CallbackHandle>();
|
private List<SteamNative.CallbackHandle> CallbackHandles = new List<SteamNative.CallbackHandle>();
|
||||||
|
private List<SteamNative.CallResult> CallResults = new List<SteamNative.CallResult>();
|
||||||
|
|
||||||
|
|
||||||
protected BaseSteamworks( uint appId )
|
protected BaseSteamworks( uint appId )
|
||||||
@ -46,6 +47,12 @@ public virtual void Dispose()
|
|||||||
}
|
}
|
||||||
CallbackHandles.Clear();
|
CallbackHandles.Clear();
|
||||||
|
|
||||||
|
foreach ( var h in CallResults )
|
||||||
|
{
|
||||||
|
h.Dispose();
|
||||||
|
}
|
||||||
|
CallResults.Clear();
|
||||||
|
|
||||||
if ( Workshop != null )
|
if ( Workshop != null )
|
||||||
{
|
{
|
||||||
Workshop.Dispose();
|
Workshop.Dispose();
|
||||||
@ -98,6 +105,16 @@ internal void RegisterCallbackHandle( SteamNative.CallbackHandle handle )
|
|||||||
CallbackHandles.Add( handle );
|
CallbackHandles.Add( handle );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void RegisterCallResult( SteamNative.CallResult handle )
|
||||||
|
{
|
||||||
|
CallResults.Add( handle );
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void UnregisterCallResult( SteamNative.CallResult handle )
|
||||||
|
{
|
||||||
|
CallResults.Remove( handle );
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Update()
|
public virtual void Update()
|
||||||
{
|
{
|
||||||
Inventory.Update();
|
Inventory.Update();
|
||||||
@ -114,6 +131,11 @@ public void RunUpdateCallbacks()
|
|||||||
{
|
{
|
||||||
if ( OnUpdate != null )
|
if ( OnUpdate != null )
|
||||||
OnUpdate();
|
OnUpdate();
|
||||||
|
|
||||||
|
for( int i=0; i < CallResults.Count; i++ )
|
||||||
|
{
|
||||||
|
CallResults[i].Try();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -107,6 +107,9 @@ private bool DeferOnCreated( Action onValid, FailureCallback onFailure = null )
|
|||||||
|
|
||||||
internal void OnBoardCreated( LeaderboardFindResult_t result, bool error )
|
internal void OnBoardCreated( LeaderboardFindResult_t result, bool error )
|
||||||
{
|
{
|
||||||
|
Console.WriteLine( $"result.LeaderboardFound: {result.LeaderboardFound}" );
|
||||||
|
Console.WriteLine( $"result.SteamLeaderboard: {result.SteamLeaderboard}" );
|
||||||
|
|
||||||
if ( error || ( result.LeaderboardFound == 0 ) )
|
if ( error || ( result.LeaderboardFound == 0 ) )
|
||||||
{
|
{
|
||||||
IsError = true;
|
IsError = true;
|
||||||
@ -234,7 +237,7 @@ public bool AttachRemoteFile( RemoteFile file, AttachRemoteFileCallback onSucces
|
|||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return handle.CallResultHandle != 0;
|
return handle.IsValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Share( () =>
|
file.Share( () =>
|
||||||
|
@ -50,21 +50,23 @@ internal class StdCall
|
|||||||
//
|
//
|
||||||
internal class CallbackHandle : IDisposable
|
internal class CallbackHandle : IDisposable
|
||||||
{
|
{
|
||||||
internal BaseSteamworks steamworks;
|
internal BaseSteamworks Steamworks;
|
||||||
internal SteamAPICall_t CallResultHandle;
|
|
||||||
internal bool CallResult;
|
// Get Rid
|
||||||
internal GCHandle FuncA;
|
internal GCHandle FuncA;
|
||||||
internal GCHandle FuncB;
|
internal GCHandle FuncB;
|
||||||
internal GCHandle FuncC;
|
internal GCHandle FuncC;
|
||||||
internal IntPtr vTablePtr;
|
internal IntPtr vTablePtr;
|
||||||
internal GCHandle PinnedCallback;
|
internal GCHandle PinnedCallback;
|
||||||
|
|
||||||
|
internal CallbackHandle( Facepunch.Steamworks.BaseSteamworks steamworks )
|
||||||
|
{
|
||||||
|
Steamworks = steamworks;
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if ( CallResult )
|
UnregisterCallback();
|
||||||
UnregisterCallResult();
|
|
||||||
else
|
|
||||||
UnregisterCallback();
|
|
||||||
|
|
||||||
if ( FuncA.IsAllocated )
|
if ( FuncA.IsAllocated )
|
||||||
FuncA.Free();
|
FuncA.Free();
|
||||||
@ -90,19 +92,81 @@ private void UnregisterCallback()
|
|||||||
if ( !PinnedCallback.IsAllocated )
|
if ( !PinnedCallback.IsAllocated )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
steamworks.native.api.SteamAPI_UnregisterCallback( PinnedCallback.AddrOfPinnedObject() );
|
Steamworks.native.api.SteamAPI_UnregisterCallback( PinnedCallback.AddrOfPinnedObject() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UnregisterCallResult()
|
public virtual bool IsValid { get { return true; } }
|
||||||
{
|
|
||||||
if ( CallResultHandle == 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( !PinnedCallback.IsAllocated )
|
|
||||||
return;
|
|
||||||
|
|
||||||
steamworks.native.api.SteamAPI_UnregisterCallResult( PinnedCallback.AddrOfPinnedObject(), CallResultHandle );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal abstract class CallResult : CallbackHandle
|
||||||
|
{
|
||||||
|
internal SteamAPICall_t Call;
|
||||||
|
public override bool IsValid { get { return Call > 0; } }
|
||||||
|
|
||||||
|
|
||||||
|
internal CallResult( Facepunch.Steamworks.BaseSteamworks steamworks, SteamAPICall_t call ) : base( steamworks )
|
||||||
|
{
|
||||||
|
Call = call;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Try()
|
||||||
|
{
|
||||||
|
bool failed = false;
|
||||||
|
|
||||||
|
if ( !Steamworks.native.utils.IsAPICallCompleted( Call, ref failed ))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Steamworks.UnregisterCallResult( this );
|
||||||
|
|
||||||
|
RunCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal abstract void RunCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal class CallResult<T> : CallResult
|
||||||
|
{
|
||||||
|
private static byte[] resultBuffer = new byte[1024 * 16];
|
||||||
|
|
||||||
|
internal delegate T ConvertFromPointer( IntPtr p );
|
||||||
|
|
||||||
|
Action<T, bool> CallbackFunction;
|
||||||
|
ConvertFromPointer ConvertFromPointerFunction;
|
||||||
|
|
||||||
|
internal int ResultSize = -1;
|
||||||
|
internal int CallbackId = 0;
|
||||||
|
|
||||||
|
internal CallResult( Facepunch.Steamworks.BaseSteamworks steamworks, SteamAPICall_t call, Action<T, bool> callbackFunction, ConvertFromPointer fromPointer, int resultSize, int callbackId ) : base( steamworks, call )
|
||||||
|
{
|
||||||
|
ResultSize = resultSize;
|
||||||
|
CallbackId = callbackId;
|
||||||
|
CallbackFunction = callbackFunction;
|
||||||
|
ConvertFromPointerFunction = fromPointer;
|
||||||
|
|
||||||
|
Steamworks.RegisterCallResult( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"CallResult( {typeof(T).Name}, {CallbackId}, {ResultSize}b )";
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe internal override void RunCallback()
|
||||||
|
{
|
||||||
|
bool failed = false;
|
||||||
|
|
||||||
|
fixed ( byte* ptr = resultBuffer )
|
||||||
|
{
|
||||||
|
if ( !Steamworks.native.utils.GetAPICallResult( Call, (IntPtr)ptr, resultBuffer.Length, CallbackId, ref failed ) || failed )
|
||||||
|
{
|
||||||
|
CallbackFunction( default(T), true );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var val = ConvertFromPointerFunction( (IntPtr)ptr );
|
||||||
|
CallbackFunction( val, false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -9,10 +9,12 @@ namespace Generator
|
|||||||
public partial class CodeWriter
|
public partial class CodeWriter
|
||||||
{
|
{
|
||||||
bool LargePack;
|
bool LargePack;
|
||||||
|
bool X86;
|
||||||
|
|
||||||
private void PlatformClass( string type, string libraryName, bool LargePack )
|
private void PlatformClass( string type, string libraryName, bool LargePack )
|
||||||
{
|
{
|
||||||
this.LargePack = LargePack;
|
this.LargePack = LargePack;
|
||||||
|
X86 = type.EndsWith( "32" );
|
||||||
|
|
||||||
StartBlock( $"internal static partial class Platform" );
|
StartBlock( $"internal static partial class Platform" );
|
||||||
{
|
{
|
||||||
@ -187,7 +189,10 @@ private void InteropClassMethod( string library, string classname, SteamApiDefin
|
|||||||
|
|
||||||
if ( argstring != "" ) argstring = $" {argstring} ";
|
if ( argstring != "" ) argstring = $" {argstring} ";
|
||||||
|
|
||||||
Write( $"[DllImportAttribute( \"{library}\" )] " );
|
if ( X86 )
|
||||||
|
Write( $"[DllImport( \"{library}\", CallingConvention = CallingConvention.Cdecl )] " );
|
||||||
|
else
|
||||||
|
Write( $"[DllImport( \"{library}\" )] " );
|
||||||
|
|
||||||
if ( ret.Return() == "bool" ) WriteLine( "[return: MarshalAs(UnmanagedType.U1)]" );
|
if ( ret.Return() == "bool" ) WriteLine( "[return: MarshalAs(UnmanagedType.U1)]" );
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ void Structs()
|
|||||||
{
|
{
|
||||||
if ( !string.IsNullOrEmpty( c.CallbackId ) )
|
if ( !string.IsNullOrEmpty( c.CallbackId ) )
|
||||||
{
|
{
|
||||||
WriteLine( "public const int CallbackId = " + c.CallbackId + ";" );
|
WriteLine( "internal const int CallbackId = " + c.CallbackId + ";" );
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -70,7 +70,7 @@ void Structs()
|
|||||||
WriteLine( "//" );
|
WriteLine( "//" );
|
||||||
WriteLine( "// Read this struct from a pointer, usually from Native. It will automatically do the awesome stuff." );
|
WriteLine( "// Read this struct from a pointer, usually from Native. It will automatically do the awesome stuff." );
|
||||||
WriteLine( "//" );
|
WriteLine( "//" );
|
||||||
StartBlock( $"public static {c.Name} FromPointer( IntPtr p )" );
|
StartBlock( $"internal static {c.Name} FromPointer( IntPtr p )" );
|
||||||
{
|
{
|
||||||
WriteLine( $"if ( Platform.PackSmall ) return (PackSmall) Marshal.PtrToStructure( p, typeof(PackSmall) );" );
|
WriteLine( $"if ( Platform.PackSmall ) return (PackSmall) Marshal.PtrToStructure( p, typeof(PackSmall) );" );
|
||||||
|
|
||||||
@ -78,6 +78,18 @@ void Structs()
|
|||||||
}
|
}
|
||||||
EndBlock();
|
EndBlock();
|
||||||
|
|
||||||
|
WriteLine();
|
||||||
|
WriteLine( "//" );
|
||||||
|
WriteLine( "// Get the size of the structure we're going to be using." );
|
||||||
|
WriteLine( "//" );
|
||||||
|
StartBlock( $"internal static int StructSize()" );
|
||||||
|
{
|
||||||
|
WriteLine( $"if ( Platform.PackSmall ) return System.Runtime.InteropServices.Marshal.SizeOf( typeof(PackSmall) );" );
|
||||||
|
|
||||||
|
WriteLine( $"return System.Runtime.InteropServices.Marshal.SizeOf( typeof({c.Name}) );" );
|
||||||
|
}
|
||||||
|
EndBlock();
|
||||||
|
|
||||||
if ( defaultPack == 8 )
|
if ( defaultPack == 8 )
|
||||||
defaultPack = 4;
|
defaultPack = 4;
|
||||||
|
|
||||||
@ -199,17 +211,16 @@ private void StructFields( SteamApiDefinition.StructDef.StructFields[] fields )
|
|||||||
WriteLine($"[MarshalAs(UnmanagedType.ByValArray, SizeConst = {num}, ArraySubType = UnmanagedType.U4)]");
|
WriteLine($"[MarshalAs(UnmanagedType.ByValArray, SizeConst = {num}, ArraySubType = UnmanagedType.U4)]");
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteLine( $"public {t} {CleanMemberName( m.Name )}; // {m.Name} {m.Type}" );
|
WriteLine( $"internal {t} {CleanMemberName( m.Name )}; // {m.Name} {m.Type}" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Callback( SteamApiDefinition.StructDef c )
|
private void Callback( SteamApiDefinition.StructDef c )
|
||||||
{
|
{
|
||||||
WriteLine();
|
WriteLine();
|
||||||
StartBlock( $"public static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action<{c.Name}, bool> CallbackFunction )" );
|
StartBlock( $"internal static void RegisterCallback( Facepunch.Steamworks.BaseSteamworks steamworks, Action<{c.Name}, bool> CallbackFunction )" );
|
||||||
{
|
{
|
||||||
WriteLine( $"var handle = new CallbackHandle();" );
|
WriteLine( $"var handle = new CallbackHandle( steamworks );" );
|
||||||
WriteLine( $"handle.steamworks = steamworks;" );
|
|
||||||
WriteLine( $"" );
|
WriteLine( $"" );
|
||||||
|
|
||||||
CallbackCallresultShared( c, false );
|
CallbackCallresultShared( c, false );
|
||||||
@ -230,24 +241,21 @@ private void Callback( SteamApiDefinition.StructDef c )
|
|||||||
private void CallResult( SteamApiDefinition.StructDef c )
|
private void CallResult( SteamApiDefinition.StructDef c )
|
||||||
{
|
{
|
||||||
WriteLine();
|
WriteLine();
|
||||||
StartBlock( $"public static CallbackHandle CallResult( Facepunch.Steamworks.BaseSteamworks steamworks, SteamAPICall_t call, Action<{c.Name}, bool> CallbackFunction )" );
|
StartBlock( $"internal static CallResult<{c.Name}> CallResult( Facepunch.Steamworks.BaseSteamworks steamworks, SteamAPICall_t call, Action<{c.Name}, bool> CallbackFunction )" );
|
||||||
{
|
{
|
||||||
WriteLine( $"var handle = new CallbackHandle();" );
|
WriteLine( $"return new CallResult<{c.Name}>( steamworks, call, CallbackFunction, FromPointer, StructSize(), CallbackId );" );
|
||||||
WriteLine( $"handle.steamworks = steamworks;" );
|
// WriteLine( $"" );
|
||||||
WriteLine( $"handle.CallResultHandle = call;" );
|
|
||||||
WriteLine( $"handle.CallResult = true;" );
|
|
||||||
WriteLine( $"" );
|
|
||||||
|
|
||||||
CallbackCallresultShared( c, true );
|
// CallbackCallresultShared( c, true );
|
||||||
|
|
||||||
WriteLine( "" );
|
// WriteLine( "" );
|
||||||
WriteLine( "//" );
|
// WriteLine( "//" );
|
||||||
WriteLine( "// Register the callback with Steam" );
|
// WriteLine( "// Register the callback with Steam" );
|
||||||
WriteLine( "//" );
|
// WriteLine( "//" );
|
||||||
WriteLine( $"steamworks.native.api.SteamAPI_RegisterCallResult( handle.PinnedCallback.AddrOfPinnedObject(), call );" );
|
// WriteLine( $"steamworks.native.api.SteamAPI_RegisterCallResult( handle.PinnedCallback.AddrOfPinnedObject(), call );" );
|
||||||
|
|
||||||
WriteLine();
|
// WriteLine();
|
||||||
WriteLine( "return handle;" );
|
//WriteLine( "return handle;" );
|
||||||
}
|
}
|
||||||
EndBlock();
|
EndBlock();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user