From d2fd7223be3dd03f15f9eada6ec53579bccea8fa Mon Sep 17 00:00:00 2001 From: iZePlayzYT Date: Tue, 14 Jan 2025 09:12:10 +0100 Subject: [PATCH] added different rendering options for when game window is not focused --- lang/Czech.ini | 4 ++++ lang/Dutch.ini | 4 ++++ lang/English.ini | 4 ++++ lang/French.ini | 4 ++++ lang/German.ini | 4 ++++ lang/Italian.ini | 4 ++++ lang/Japanese.ini | 4 ++++ lang/Polish.ini | 4 ++++ lang/Portuguese.ini | 4 ++++ lang/Russian.ini | 4 ++++ lang/Spanish.ini | 4 ++++ src/game/area.c | 7 +++++-- src/pc/configfile.c | 2 ++ src/pc/configfile.h | 1 + src/pc/djui/djui_panel_display.c | 4 +++- src/pc/gfx/gfx_pc.c | 32 +++++++++++++++++--------------- 16 files changed, 72 insertions(+), 18 deletions(-) diff --git a/lang/Czech.ini b/lang/Czech.ini index 9ba4a2a65..7371a122b 100644 --- a/lang/Czech.ini +++ b/lang/Czech.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "Vždy 4:3" PRELOAD_TEXTURES = "Načíst textury předem" VSYNC = "VSync" UNCAPPED_FRAMERATE = "Neomezené FPS" +RENDER_WHEN_UNFOCUSED = "Vykreslovat i když není aktivní" +RENDER_EVERYTHING = "Vše" +RENDER_HUD_AND_UI = "HUD a UI" +RENDER_NOTHING = "Nic" FRAME_LIMIT = "FPS Limit" FAST = "Optimalizované" ACCURATE = "Přesné" diff --git a/lang/Dutch.ini b/lang/Dutch.ini index 34e5388a9..377505fa7 100644 --- a/lang/Dutch.ini +++ b/lang/Dutch.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "Forceer 4:3" PRELOAD_TEXTURES = "Textures Voorladen" VSYNC = "VSync" UNCAPPED_FRAMERATE = "Ongelimiteerde Framerate" +RENDER_WHEN_UNFOCUSED = "Renderen als niet gefocust" +RENDER_EVERYTHING = "Alles" +RENDER_HUD_AND_UI = "HUD en UI" +RENDER_NOTHING = "Niets" FRAME_LIMIT = "Frame limiet" FAST = "Snel" ACCURATE = "Accuraat" diff --git a/lang/English.ini b/lang/English.ini index 596aba37c..cb291bdf0 100644 --- a/lang/English.ini +++ b/lang/English.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "Force 4:3" PRELOAD_TEXTURES = "Preload Textures" VSYNC = "VSync" UNCAPPED_FRAMERATE = "Uncapped Framerate" +RENDER_WHEN_UNFOCUSED = "Render When Unfocused" +RENDER_EVERYTHING = "Everything" +RENDER_HUD_AND_UI = "HUD and UI" +RENDER_NOTHING = "Nothing" FRAME_LIMIT = "Frame Limit" FAST = "Fast" ACCURATE = "Accurate" diff --git a/lang/French.ini b/lang/French.ini index e47bc1204..bd3983a8e 100644 --- a/lang/French.ini +++ b/lang/French.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "Forcer l'affichage 4:3" PRELOAD_TEXTURES = "Textures Préchargées" VSYNC = "VSync" UNCAPPED_FRAMERATE = "FPS Illimités" +RENDER_WHEN_UNFOCUSED = "Rendre quand non focalisé" +RENDER_EVERYTHING = "Tout" +RENDER_HUD_AND_UI = "HUD et UI" +RENDER_NOTHING = "Rien" FRAME_LIMIT = "Limite de FPS" FAST = "Rapide" ACCURATE = "Précis" diff --git a/lang/German.ini b/lang/German.ini index 0323a78d2..744d01a24 100644 --- a/lang/German.ini +++ b/lang/German.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "Erzwinge 4:3" PRELOAD_TEXTURES = "Texturen vorladen" VSYNC = "VSync" UNCAPPED_FRAMERATE = "Unbegrenzte Bildrate" +RENDER_WHEN_UNFOCUSED = "Rendern wenn nicht fokussiert" +RENDER_EVERYTHING = "Alles" +RENDER_HUD_AND_UI = "HUD und UI" +RENDER_NOTHING = "Nichts" FRAME_LIMIT = "Bildrate-Limit" FAST = "Schnell" ACCURATE = "Präzise" diff --git a/lang/Italian.ini b/lang/Italian.ini index 4e774cf59..69f3e3746 100644 --- a/lang/Italian.ini +++ b/lang/Italian.ini @@ -122,6 +122,10 @@ FORCE_4BY3 = "Force 4:3" PRELOAD_TEXTURES = "Precarica Textures" VSYNC = "VSync" UNCAPPED_FRAMERATE = "Fotogrammi Illimitati" +RENDER_WHEN_UNFOCUSED = "Renderizza quando non a fuoco" +RENDER_EVERYTHING = "Tutto" +RENDER_HUD_AND_UI = "HUD e UI" +RENDER_NOTHING = "Niente" FRAME_LIMIT = "Limite Fotogrammi" FAST = "Veloce" ACCURATE = "Accurata" diff --git a/lang/Japanese.ini b/lang/Japanese.ini index 4e1186b41..11b331b6b 100644 --- a/lang/Japanese.ini +++ b/lang/Japanese.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "画面比を4:3に強制" PRELOAD_TEXTURES = "テクスチャを事前に読み込む" VSYNC = "垂直同期(VSYNC)を有効にする" UNCAPPED_FRAMERATE = "FPSを制限しない" +RENDER_WHEN_UNFOCUSED = "フォーカスが外れたときに描画" +RENDER_EVERYTHING = "すべて" +RENDER_HUD_AND_UI = "HUDとUI" +RENDER_NOTHING = "なし" FRAME_LIMIT = "FPSの制限" FAST = "速い" ACCURATE = "正確" diff --git a/lang/Polish.ini b/lang/Polish.ini index 80478d812..f70a79a69 100644 --- a/lang/Polish.ini +++ b/lang/Polish.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "Wymuś proporcję 4:3" PRELOAD_TEXTURES = "Załaduj Wstępnie Tekstury" VSYNC = "Synchronizacja Pionowa" UNCAPPED_FRAMERATE = "Nieograniczona Liczba Klatek" +RENDER_WHEN_UNFOCUSED = "Renderuj gdy nieaktywne" +RENDER_EVERYTHING = "Wszystko" +RENDER_HUD_AND_UI = "HUD i UI" +RENDER_NOTHING = "Nic" FRAME_LIMIT = "Limit Klatek na Sekundę" FAST = "Szybka" ACCURATE = "Dokładna" diff --git a/lang/Portuguese.ini b/lang/Portuguese.ini index d66b4d9eb..16d9793bf 100644 --- a/lang/Portuguese.ini +++ b/lang/Portuguese.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "Forçar 4:3" PRELOAD_TEXTURES = "Pré-carregar texturas" VSYNC = "Sincronização vertical" UNCAPPED_FRAMERATE = "FPS ilimitado" +RENDER_WHEN_UNFOCUSED = "Renderizar quando não estiver focado" +RENDER_EVERYTHING = "Tudo" +RENDER_HUD_AND_UI = "HUD e UI" +RENDER_NOTHING = "Nada" FRAME_LIMIT = "Limite de FPS" FAST = "Rápida" ACCURATE = "Precisa" diff --git a/lang/Russian.ini b/lang/Russian.ini index 8aa608004..df045d58f 100644 --- a/lang/Russian.ini +++ b/lang/Russian.ini @@ -123,6 +123,10 @@ FORCE_4BY3 = "Экран 4:3" PRELOAD_TEXTURES = "Предварительная загрузка текстур" VSYNC = "Вертикальная синхронизация" UNCAPPED_FRAMERATE = "Неограниченная частота кадров" +RENDER_WHEN_UNFOCUSED = "Отрисовывать если не активно" +RENDER_EVERYTHING = "Всё" +RENDER_HUD_AND_UI = "HUD и UI" +RENDER_NOTHING = "Ничего" FRAME_LIMIT = "Лимит кадров" FAST = "Быстро" ACCURATE = "Точно" diff --git a/lang/Spanish.ini b/lang/Spanish.ini index 555eaad91..8654a8a1a 100644 --- a/lang/Spanish.ini +++ b/lang/Spanish.ini @@ -124,6 +124,10 @@ FORCE_4BY3 = "Forzar 4:3" PRELOAD_TEXTURES = "Precargar texturas" VSYNC = "Sincronización vertical" UNCAPPED_FRAMERATE = "FPS sin límite" +RENDER_WHEN_UNFOCUSED = "Renderizar cuando no está enfocado" +RENDER_EVERYTHING = "Todo" +RENDER_HUD_AND_UI = "HUD y UI" +RENDER_NOTHING = "Nada" FRAME_LIMIT = "Límite de FPS" FAST = "Rápida" ACCURATE = "Precisa" diff --git a/src/game/area.c b/src/game/area.c index 0e37980c3..d1ac46f9a 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -28,6 +28,7 @@ #include "pc/djui/djui.h" #include "pc/djui/djui_panel_pause.h" #include "pc/nametags.h" +#include "pc/pc_main.h" struct SpawnInfo gPlayerSpawnInfos[MAX_PLAYERS]; struct Area gAreaData[MAX_AREAS]; @@ -437,8 +438,10 @@ void play_transition_after_delay(s16 transType, s16 time, u8 red, u8 green, u8 b void render_game(void) { dynos_update_gfx(); if (gCurrentArea != NULL && !gWarpTransition.pauseRendering) { - geo_process_root(gCurrentArea->unk04, D_8032CE74, D_8032CE78, gFBSetColor); - + if (WAPI.has_focus() || configRenderWhenUnfocused == 0) { + geo_process_root(gCurrentArea->unk04, D_8032CE74, D_8032CE78, gFBSetColor); + } + gSPViewport(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&D_8032CF00)); gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, BORDER_HEIGHT, SCREEN_WIDTH, diff --git a/src/pc/configfile.c b/src/pc/configfile.c index e0836beed..7a286e705 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -81,6 +81,7 @@ ConfigWindow configWindow = { unsigned int configFiltering = 2; // 0 = Nearest, 1 = Bilinear, 2 = Trilinear bool configShowFPS = false; bool configUncappedFramerate = true; +unsigned int configRenderWhenUnfocused = 0; // 0 = Everything, 1 = HUD and UI, 2 = Nothing unsigned int configFrameLimit = 60; unsigned int configInterpolationMode = 1; unsigned int configDrawDistance = 4; @@ -205,6 +206,7 @@ static const struct ConfigOption options[] = { {.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering}, {.name = "show_fps", .type = CONFIG_TYPE_BOOL, .boolValue = &configShowFPS}, {.name = "uncapped_framerate", .type = CONFIG_TYPE_BOOL, .boolValue = &configUncappedFramerate}, + {.name = "render_when_unfocused", .type = CONFIG_TYPE_UINT, .uintValue = &configRenderWhenUnfocused}, {.name = "frame_limit", .type = CONFIG_TYPE_UINT, .uintValue = &configFrameLimit}, {.name = "interpolation_mode", .type = CONFIG_TYPE_UINT, .uintValue = &configInterpolationMode}, {.name = "coop_draw_distance", .type = CONFIG_TYPE_UINT, .uintValue = &configDrawDistance}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 046d898bc..e14eccc03 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -34,6 +34,7 @@ extern ConfigWindow configWindow; extern unsigned int configFiltering; extern bool configShowFPS; extern bool configUncappedFramerate; +extern unsigned int configRenderWhenUnfocused; extern unsigned int configFrameLimit; extern unsigned int configInterpolationMode; extern unsigned int configDrawDistance; diff --git a/src/pc/djui/djui_panel_display.c b/src/pc/djui/djui_panel_display.c index 9dd68dad3..deb9cdc8d 100644 --- a/src/pc/djui/djui_panel_display.c +++ b/src/pc/djui/djui_panel_display.c @@ -64,7 +64,9 @@ void djui_panel_display_create(struct DjuiBase* caller) { djui_checkbox_create(body, DLANG(DISPLAY, SHOW_FPS), &configShowFPS, NULL); djui_checkbox_create(body, DLANG(DISPLAY, VSYNC), &configWindow.vsync, djui_panel_display_apply); djui_checkbox_create(body, DLANG(DISPLAY, UNCAPPED_FRAMERATE), &configUncappedFramerate, djui_panel_display_uncapped_change); - + char* renderChoicesUnfocused[3] = { DLANG(DISPLAY, RENDER_EVERYTHING), DLANG(DISPLAY, RENDER_HUD_AND_UI), DLANG(DISPLAY, RENDER_NOTHING) }; + djui_selectionbox_create(body, DLANG(DISPLAY, RENDER_WHEN_UNFOCUSED), renderChoicesUnfocused, 3, &configRenderWhenUnfocused, NULL); + struct DjuiRect* rect1 = djui_rect_container_create(body, 32); { if (configFrameLimit < 30) { configFrameLimit = 30; } diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index d5c1614f9..125f23712 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -1858,24 +1858,26 @@ void gfx_start_frame(void) { } void gfx_run(Gfx *commands) { - gfx_sp_reset(); + if (WAPI.has_focus() || configRenderWhenUnfocused != 2) { + gfx_sp_reset(); - //puts("New frame"); + //puts("New frame"); - if (!gfx_wapi->start_frame()) { - dropped_frame = true; - return; - } - dropped_frame = false; + if (!gfx_wapi->start_frame()) { + dropped_frame = true; + return; + } + dropped_frame = false; - //double t0 = gfx_wapi->get_time(); - gfx_rapi->start_frame(); - gfx_run_dl(commands); - gfx_flush(); - //double t1 = gfx_wapi->get_time(); - //printf("Process %f %f\n", t1, t1 - t0); - gfx_rapi->end_frame(); - gfx_wapi->swap_buffers_begin(); + //double t0 = gfx_wapi->get_time(); + gfx_rapi->start_frame(); + gfx_run_dl(commands); + gfx_flush(); + //double t1 = gfx_wapi->get_time(); + //printf("Process %f %f\n", t1, t1 - t0); + gfx_rapi->end_frame(); + gfx_wapi->swap_buffers_begin(); + } } void gfx_end_frame(void) {