Added discord rpc timestamps

This commit is contained in:
KiritoDv 2021-05-24 15:09:19 +00:00
parent dc7a608abc
commit 1f07882b49
4 changed files with 22 additions and 9 deletions

View File

@ -169,7 +169,7 @@ namespace Moon {
seg2_act_name_table = current->acts.data();
seg2_course_name_table = current->courses.data();
#ifdef DISCORDRPC
DiscordUpdatePresence(true);
DiscordReloadPresence();
#endif
}

View File

@ -62,6 +62,7 @@ Discord_UpdatePresence discordUpdatePresence;
static s16 lastCourseNum = -1;
static s16 lastActNum = -1;
static int64_t timestamp;
bool reloadRPC = false;
static char stage[188];
@ -156,6 +157,14 @@ static void init_discord(void) {
initd = true;
}
static void set_time(void){
if (lastCourseNum != gCurrCourseNum) {
timestamp = 0;
discordRichPresence.startTimestamp = time(0);
lastCourseNum = gCurrCourseNum;
}
}
static void set_details(void) {
if (lastCourseNum != gCurrCourseNum || reloadRPC) {
// If we are in in Course 0 we are in the castle which doesn't have a string
@ -201,13 +210,16 @@ void set_logo(void) {
discordRichPresence.largeImageKey = largeImageKey;
}
void DiscordUpdatePresence(bool force){
if(force)
reloadRPC = true;
void DiscordReloadPresence() {
reloadRPC = true;
}
void DiscordUpdatePresence(){
if (!configDiscordRPC || !initd) return;
if (time(NULL) < lastUpdatedTime + DISCORD_UPDATE_RATE) return;
lastUpdatedTime = time(NULL);
set_time();
set_state();
set_details();
set_logo();
@ -216,8 +228,8 @@ void DiscordUpdatePresence(bool force){
}
extern "C" {
void discord_update_rich_presence(bool force) {
DiscordUpdatePresence(force);
void discord_update_rich_presence() {
DiscordUpdatePresence();
}
void discord_shutdown(void) {

View File

@ -43,11 +43,12 @@ typedef struct DiscordEventHandlers {
void discord_reset(void);
#ifndef __cplusplus
void discord_update_rich_presence(bool force);
void discord_update_rich_presence();
void discord_shutdown(void);
void discord_init(void);
#else
void DiscordUpdatePresence(bool force);
void DiscordReloadPresence();
void DiscordUpdatePresence();
#endif
#endif // DISCORDRPC_H

View File

@ -266,7 +266,7 @@ void main_func(char *argv[]) {
while (true) {
wm_api->main_loop(produce_one_frame);
#ifdef DISCORDRPC
discord_update_rich_presence(0);
discord_update_rich_presence();
#endif
}
#endif