mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-26 14:45:51 +03:00
Do Callbacks
This commit is contained in:
parent
f06e5a7960
commit
008f317b43
@ -29,8 +29,8 @@ internal struct CallbackMsg_t
|
|||||||
{
|
{
|
||||||
public HSteamUser m_hSteamUser; // Specific user to whom this callback applies.
|
public HSteamUser m_hSteamUser; // Specific user to whom this callback applies.
|
||||||
public CallbackType Type; // Callback identifier. (Corresponds to the k_iCallback enum in the callback structure.)
|
public CallbackType Type; // Callback identifier. (Corresponds to the k_iCallback enum in the callback structure.)
|
||||||
public IntPtr m_pubParam; // Points to the callback structure
|
public IntPtr Data; // Points to the callback structure
|
||||||
public int m_cubParam; // Size of the data pointed to by m_pubParam
|
public int DataSize; // Size of the data pointed to by m_pubParam
|
||||||
};
|
};
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -80,11 +80,19 @@ private static void ProcessCallback( CallbackMsg_t msg )
|
|||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine( $"Callback: {msg.Type}" );
|
Console.WriteLine( $"Callback: {msg.Type}" );
|
||||||
|
|
||||||
|
if ( Callbacks.TryGetValue( msg.Type, out var list ) )
|
||||||
|
{
|
||||||
|
foreach ( var item in list )
|
||||||
|
{
|
||||||
|
item.action( msg.Data );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ProcessResult( CallbackMsg_t msg )
|
private static void ProcessResult( CallbackMsg_t msg )
|
||||||
{
|
{
|
||||||
var result = msg.m_pubParam.ToType<SteamAPICallCompleted_t>();
|
var result = msg.Data.ToType<SteamAPICallCompleted_t>();
|
||||||
|
|
||||||
Console.WriteLine( $"Result: {result.AsyncCall} / {result.Callback}" );
|
Console.WriteLine( $"Result: {result.AsyncCall} / {result.Callback}" );
|
||||||
|
|
||||||
@ -150,16 +158,17 @@ struct Callback
|
|||||||
public bool server;
|
public bool server;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dictionary<int, List<Callback>> Callbacks = new Dictionary<int, List<Callback>>();
|
static Dictionary<CallbackType, List<Callback>> Callbacks = new Dictionary<CallbackType, List<Callback>>();
|
||||||
|
|
||||||
internal static void Install<T>( Action<T> p, bool server = false ) where T : ICallbackData
|
internal static void Install<T>( Action<T> p, bool server = false ) where T : ICallbackData
|
||||||
{
|
{
|
||||||
var t = default( T );
|
var t = default( T );
|
||||||
|
var type = (CallbackType)t.CallbackId;
|
||||||
|
|
||||||
if ( !Callbacks.TryGetValue( t.CallbackId, out var list ) )
|
if ( !Callbacks.TryGetValue( type, out var list ) )
|
||||||
{
|
{
|
||||||
list = new List<Callback>();
|
list = new List<Callback>();
|
||||||
Callbacks[t.CallbackId] = list;
|
Callbacks[type] = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Add( new Callback
|
list.Add( new Callback
|
||||||
@ -171,7 +180,7 @@ internal static void Install<T>( Action<T> p, bool server = false ) where T : IC
|
|||||||
|
|
||||||
internal static void Wipe()
|
internal static void Wipe()
|
||||||
{
|
{
|
||||||
Callbacks = new Dictionary<int, List<Callback>>();
|
Callbacks = new Dictionary<CallbackType, List<Callback>>();
|
||||||
ResultCallbacks = new Dictionary<ulong, ResultCallback>();
|
ResultCallbacks = new Dictionary<ulong, ResultCallback>();
|
||||||
ClientPipe = 0;
|
ClientPipe = 0;
|
||||||
ServerPipe = 0;
|
ServerPipe = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user