mirror of
https://github.com/yuzu-emu/discord-rpc.git
synced 2024-12-23 04:15:39 +00:00
Start on adding update function
This commit is contained in:
parent
cb34ca725f
commit
e3e2fd72f4
|
@ -70,6 +70,7 @@ static void gameLoop() {
|
||||||
++FrustrationLevel;
|
++FrustrationLevel;
|
||||||
|
|
||||||
updateDiscordPresence();
|
updateDiscordPresence();
|
||||||
|
Discord_Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,9 @@ void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handler
|
||||||
void Discord_Shutdown();
|
void Discord_Shutdown();
|
||||||
void Discord_UpdatePresence(const DiscordRichPresence* presence);
|
void Discord_UpdatePresence(const DiscordRichPresence* presence);
|
||||||
|
|
||||||
|
/* checks for incoming messages, dispatches callbacks */
|
||||||
|
void Discord_Update();
|
||||||
|
|
||||||
/* later
|
/* later
|
||||||
|
|
||||||
struct DiscordChannelEventHandlers {
|
struct DiscordChannelEventHandlers {
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
static RpcConnection* MyConnection = nullptr;
|
static RpcConnection* MyConnection = nullptr;
|
||||||
static char ApplicationId[64]{};
|
static char ApplicationId[64]{};
|
||||||
static DiscordEventHandlers Handlers{};
|
static DiscordEventHandlers Handlers{};
|
||||||
|
static bool wasJustConnected = false;
|
||||||
|
static bool wasJustDisconnected = false;
|
||||||
|
|
||||||
void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers)
|
void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers)
|
||||||
{
|
{
|
||||||
|
@ -18,8 +20,8 @@ void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handler
|
||||||
}
|
}
|
||||||
|
|
||||||
MyConnection = RpcConnection::Create();
|
MyConnection = RpcConnection::Create();
|
||||||
MyConnection->onConnect = Handlers.ready;
|
MyConnection->onConnect = []() { wasJustConnected = true; };
|
||||||
MyConnection->onDisconnect = Handlers.disconnected;
|
MyConnection->onDisconnect = []() { wasJustDisconnected = true; };
|
||||||
MyConnection->Open();
|
MyConnection->Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,3 +40,20 @@ void Discord_UpdatePresence(const DiscordRichPresence* presence)
|
||||||
frame->length = sizeof(uint32_t) + (jsonWrite - frame->message);
|
frame->length = sizeof(uint32_t) + (jsonWrite - frame->message);
|
||||||
MyConnection->WriteFrame(frame);
|
MyConnection->WriteFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Discord_Update()
|
||||||
|
{
|
||||||
|
// check for messages
|
||||||
|
// todo
|
||||||
|
|
||||||
|
// fire callbacks
|
||||||
|
if (wasJustDisconnected && Handlers.disconnected) {
|
||||||
|
wasJustDisconnected = false;
|
||||||
|
Handlers.disconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wasJustConnected && Handlers.ready) {
|
||||||
|
wasJustConnected = false;
|
||||||
|
Handlers.ready();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue