internal static void Register(Callback cb) { int callbackIdentity = CallbackIdentities.GetCallbackIdentity(cb.GetCallbackType()); Dictionary <int, List <Callback> > dictionary = (cb.IsGameServer ? m_registeredGameServerCallbacks : m_registeredCallbacks); lock (m_sync) { if (!dictionary.TryGetValue(callbackIdentity, out var value)) { value = new List <Callback>(); dictionary.Add(callbackIdentity, value); } value.Add(cb); } }
internal static void Register(Callback cb) { int iCallback = CallbackIdentities.GetCallbackIdentity(cb.GetCallbackType()); var callbacksRegistry = cb.IsGameServer ? m_registeredGameServerCallbacks : m_registeredCallbacks; lock (m_sync) { List <Callback> callbacksList; if (!callbacksRegistry.TryGetValue(iCallback, out callbacksList)) { callbacksList = new List <Callback>(); callbacksRegistry.Add(iCallback, callbacksList); } callbacksList.Add(cb); } }
internal static void Unregister(Callback cb) { int iCallback = CallbackIdentities.GetCallbackIdentity(cb.GetCallbackType()); var callbacksRegistry = cb.IsGameServer ? m_registeredGameServerCallbacks : m_registeredCallbacks; lock (m_sync) { if (callbacksRegistry.TryGetValue(iCallback, out var callbacksList)) { callbacksList.Remove(cb); if (callbacksList.Count == 0) { callbacksRegistry.Remove(iCallback); } } } }
private void BuildCCallbackBase() { this.VTable = new CCallbackBaseVTable { m_RunCallback = new CCallbackBaseVTable.RunCBDel(this.OnRunCallback), m_RunCallResult = new CCallbackBaseVTable.RunCRDel(this.OnRunCallResult), m_GetCallbackSizeBytes = new CCallbackBaseVTable.GetCallbackSizeBytesDel(this.OnGetCallbackSizeBytes) }; this.m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CCallbackBaseVTable))); Marshal.StructureToPtr(this.VTable, this.m_pVTable, false); this.m_CCallbackBase = new CCallbackBase { m_vfptr = this.m_pVTable, m_iCallback = CallbackIdentities.GetCallbackIdentity(typeof(T)) }; this.m_pCCallbackBase = GCHandle.Alloc(this.m_CCallbackBase, GCHandleType.Pinned); }
internal static void Unregister(Callback cb) { int callbackIdentity = CallbackIdentities.GetCallbackIdentity(cb.GetCallbackType()); Dictionary <int, List <Callback> > dictionary = (cb.IsGameServer ? m_registeredGameServerCallbacks : m_registeredCallbacks); lock (m_sync) { if (dictionary.TryGetValue(callbackIdentity, out var value)) { value.Remove(cb); if (value.Count == 0) { dictionary.Remove(callbackIdentity); } } } }
// Steamworks.NET Specific private void BuildCCallbackBase() { VTable = new CCallbackBaseVTable() { m_RunCallback = OnRunCallback, m_RunCallResult = OnRunCallResult, m_GetCallbackSizeBytes = OnGetCallbackSizeBytes }; m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CCallbackBaseVTable))); Marshal.StructureToPtr(VTable, m_pVTable, false); m_CCallbackBase = new CCallbackBase() { m_vfptr = m_pVTable, m_nCallbackFlags = 0, m_iCallback = CallbackIdentities.GetCallbackIdentity(typeof(T)) }; m_pCCallbackBase = GCHandle.Alloc(m_CCallbackBase, GCHandleType.Pinned); }
// Steamworks.NET Specific private void BuildCCallbackBase() { _vTable = new CCallbackBaseVTable { RunCallback = OnRunCallback, RunCallResult = OnRunCallResult, GetCallbackSizeBytes = OnGetCallbackSizeBytes }; _pVTable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CCallbackBaseVTable))); Marshal.StructureToPtr(_vTable, _pVTable, false); _callbackBase = new CallbackBase { VFPtr = _pVTable, CallbackFlags = 0, Callback = CallbackIdentities.GetCallbackIdentity(typeof(T)) }; _pCCallbackBase = GCHandle.Alloc(_callbackBase, GCHandleType.Pinned); }
// Manual registration of the callback public void Register(DispatchDelegate func) { if (func == null) { throw new Exception("Callback function must not be null."); } if ((m_CCallbackBase.m_nCallbackFlags & CCallbackBase.k_ECallbackFlagsRegistered) == CCallbackBase.k_ECallbackFlagsRegistered) { Unregister(); } if (m_bGameServer) { SetGameserverFlag(); } m_Func = func; // k_ECallbackFlagsRegistered is set by SteamAPI_RegisterCallback. NativeMethods.SteamAPI_RegisterCallback(m_pCCallbackBase.AddrOfPinnedObject(), CallbackIdentities.GetCallbackIdentity(typeof(T))); }
public void Register(DispatchDelegate <T> func) { if (func == null) { throw new Exception("Callback function must not be null."); } if ((this.m_CCallbackBase.m_nCallbackFlags & 1) == 1) { this.Unregister(); } if (this.m_bGameServer) { this.SetGameserverFlag(); } this.m_Func = func; NativeMethods.SteamAPI_RegisterCallback(this.m_pCCallbackBase.AddrOfPinnedObject(), CallbackIdentities.GetCallbackIdentity(typeof(T))); }
public CallResult() { m_iCallback = CallbackIdentities.GetCallbackIdentity(typeof(T)); m_Size = Marshal.SizeOf(typeof(T)); }
public void UnRegister() { CallbackDispatcher.UnRegisterCallback(this, CallbackIdentities.GetCallbackIdentity(typeof(T))); }