Start on adding update function

This commit is contained in:
Chris Marsh 2017-07-07 09:41:20 -07:00
parent cb34ca725f
commit e3e2fd72f4
3 changed files with 25 additions and 2 deletions

View file

@ -70,6 +70,7 @@ static void gameLoop() {
++FrustrationLevel; ++FrustrationLevel;
updateDiscordPresence(); updateDiscordPresence();
Discord_Update();
} }
} }

View file

@ -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 {

View file

@ -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();
}
}