From 208bfdcbf3ac21ea592bf1889cb3d482ce1c7062 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sat, 13 Jun 2020 04:21:47 +0300 Subject: [PATCH] move all the discordrpc stuff to pc_main.c that means it will now work in D3D11 and D3D12 also 'normalized' the sdl2 main loop --- src/game/area.c | 8 -------- src/pc/gfx/gfx_sdl2.c | 25 +++++-------------------- src/pc/pc_main.c | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/game/area.c b/src/game/area.c index 6e7a3ff2..d408190c 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -23,10 +23,6 @@ #include "gfx_dimensions.h" -#ifdef DISCORDRPC -#include "pc/discord/discordrpc.h" -#endif - struct SpawnInfo gPlayerSpawnInfos[1]; struct GraphNode *D_8033A160[0x100]; struct Area gAreaData[8]; @@ -425,8 +421,4 @@ void render_game(void) { D_8032CE74 = NULL; D_8032CE78 = 0; - -#ifdef DISCORDRPC - discord_update_rich_presence(); -#endif } diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index f72f2dda..e46c186e 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -34,10 +34,6 @@ #include "src/pc/controller/controller_keyboard.h" -#ifdef DISCORDRPC -#include "pc/discord/discordrpc.h" -#endif - // TODO: figure out if this shit even works #ifdef VERSION_EU # define FRAMERATE 25 @@ -50,7 +46,6 @@ static const Uint32 FRAME_TIME = 1000 / FRAMERATE; static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; -static Uint32 frame_start = 0; static kb_callback_t kb_key_down = NULL; static kb_callback_t kb_key_up = NULL; @@ -189,17 +184,11 @@ static void gfx_sdl_init(const char *window_title) { } static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) { - Uint32 t; -#ifdef DISCORDRPC - discord_init(); -#endif - while (1) { - t = SDL_GetTicks(); - run_one_game_iter(); - t = SDL_GetTicks() - t; - if (t < FRAME_TIME && configWindow.vsync <= 1) - SDL_Delay(FRAME_TIME - t); - } + Uint32 t = SDL_GetTicks(); + run_one_game_iter(); + t = SDL_GetTicks() - t; + if (t < FRAME_TIME && configWindow.vsync <= 1) + SDL_Delay(FRAME_TIME - t); } static void gfx_sdl_get_dimensions(uint32_t *width, uint32_t *height) { @@ -261,9 +250,6 @@ static void gfx_sdl_handle_events(void) { } break; case SDL_QUIT: -#ifdef DISCORDRPC - discord_shutdown(); -#endif game_exit(); break; } @@ -283,7 +269,6 @@ static void gfx_sdl_set_keyboard_callbacks(kb_callback_t on_key_down, kb_callbac } static bool gfx_sdl_start_frame(void) { - frame_start = SDL_GetTicks(); return true; } diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index c74624e4..dfc62463 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -32,6 +32,10 @@ #include "game/main.h" #include "game/thread6.h" +#ifdef DISCORDRPC +#include "pc/discord/discordrpc.h" +#endif + OSMesg D_80339BEC; OSMesgQueue gSIEventMesgQueue; @@ -106,6 +110,9 @@ void audio_shutdown(void) { } void game_deinit(void) { +#ifdef DISCORDRPC + discord_shutdown(); +#endif configfile_save(configfile_name()); controller_shutdown(); audio_shutdown(); @@ -228,12 +235,20 @@ void main_func(void) { } #endif +#ifdef DISCORDRPC + discord_init(); +#endif + #ifdef TARGET_WEB emscripten_set_main_loop(em_main_loop, 0, 0); request_anim_frame(on_anim_frame); #else - while (true) + while (true) { wm_api->main_loop(produce_one_frame); +#ifdef DISCORDRPC + discord_update_rich_presence(); +#endif + } #endif }