mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2025-04-21 21:52:06 +02:00
Create GOLDBERG_CALLBACK_INTERNAL() macro.
This allows the usage of steam callbacks within the emulator itself.
This commit is contained in:
parent
1fa0f4d4d5
commit
cde29f0fd0
1 changed files with 66 additions and 0 deletions
66
dll/dll.h
66
dll/dll.h
|
@ -25,6 +25,72 @@
|
||||||
#define STEAMCLIENT_API static
|
#define STEAMCLIENT_API static
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define GOLDBERG_CALLBACK_INTERNAL(parent, fname, cb_type) \
|
||||||
|
struct GB_CCallbackInternal_ ## fname : private GB_CCallbackInterImp< sizeof(cb_type) > { \
|
||||||
|
public: \
|
||||||
|
~GB_CCallbackInternal_ ## fname () { if (m_nCallbackFlags & k_ECallbackFlagsRegistered) { \
|
||||||
|
bool ready = false; \
|
||||||
|
do { \
|
||||||
|
if (global_mutex.try_lock() == true) { \
|
||||||
|
Steam_Client * client = get_steam_client(); \
|
||||||
|
if (client != NULL) { \
|
||||||
|
get_steam_client()->UnregisterCallback(this); \
|
||||||
|
ready = true; \
|
||||||
|
} \
|
||||||
|
global_mutex.unlock(); \
|
||||||
|
} \
|
||||||
|
} while (!ready); \
|
||||||
|
} }\
|
||||||
|
GB_CCallbackInternal_ ## fname () {} \
|
||||||
|
GB_CCallbackInternal_ ## fname ( const GB_CCallbackInternal_ ## fname & ) {} \
|
||||||
|
GB_CCallbackInternal_ ## fname & operator=(const GB_CCallbackInternal_ ## fname &) { return *this; } \
|
||||||
|
private: \
|
||||||
|
virtual void Run(void *callback) { \
|
||||||
|
if (!(m_nCallbackFlags & k_ECallbackFlagsRegistered)) { \
|
||||||
|
bool ready = false; \
|
||||||
|
do { \
|
||||||
|
if (global_mutex.try_lock() == true) { \
|
||||||
|
Steam_Client * client = get_steam_client(); \
|
||||||
|
if (client != NULL) { \
|
||||||
|
client->RegisterCallback(this, cb_type::k_iCallback); \
|
||||||
|
ready = true; \
|
||||||
|
} \
|
||||||
|
global_mutex.unlock(); \
|
||||||
|
} \
|
||||||
|
} while (!ready); \
|
||||||
|
} \
|
||||||
|
if (m_nCallbackFlags & k_ECallbackFlagsRegistered) { \
|
||||||
|
parent *obj = reinterpret_cast<parent*>(reinterpret_cast<char*>(this) - offsetof(parent, m_steamcallback_ ## fname)); \
|
||||||
|
obj->fname(reinterpret_cast<cb_type*>(callback)); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} m_steamcallback_ ## fname ; void fname( cb_type *callback )
|
||||||
|
|
||||||
|
template<int sizeof_cb_type>
|
||||||
|
class GB_CCallbackInterImp : protected CCallbackBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~GB_CCallbackInterImp() { if (m_nCallbackFlags & k_ECallbackFlagsRegistered) {
|
||||||
|
bool ready = false;
|
||||||
|
do {
|
||||||
|
if (global_mutex.try_lock() == true) {
|
||||||
|
Steam_Client * client = get_steam_client();
|
||||||
|
if (client != NULL) {
|
||||||
|
get_steam_client()->UnregisterCallback(this);
|
||||||
|
ready = true;
|
||||||
|
}
|
||||||
|
global_mutex.unlock();
|
||||||
|
}
|
||||||
|
} while (!ready);
|
||||||
|
} }
|
||||||
|
void SetGameserverFlag() { m_nCallbackFlags |= k_ECallbackFlagsGameServer; }
|
||||||
|
protected:
|
||||||
|
friend class CCallbackMgr;
|
||||||
|
virtual void Run(void *callback) = 0;
|
||||||
|
virtual void Run( void *callback, bool io_failure, SteamAPICall_t api_fp) { Run(callback); }
|
||||||
|
virtual int GetCallbackSizeBytes() { return sizeof_cb_type; }
|
||||||
|
};
|
||||||
|
|
||||||
Steam_Client *get_steam_client();
|
Steam_Client *get_steam_client();
|
||||||
bool steamclient_has_ipv6_functions();
|
bool steamclient_has_ipv6_functions();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue