From aa3e5fad1293c4595812dbd42dade99ecb4be519 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:04:14 +1000 Subject: [PATCH] simple fps display in top left corner (#527) * simple fps display in top left corner * added other languages thank you to everyone in #translation-station, and to Google translate (some languages may need revisiting later) * render from left not center, grey fps text --- 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/Polish.ini | 1 + lang/Portuguese.ini | 6 ++-- lang/Russian.ini | 4 +-- lang/Spanish.ini | 1 + src/pc/configfile.c | 2 ++ src/pc/configfile.h | 1 + src/pc/djui/djui.c | 6 ++++ src/pc/djui/djui_fps_display.c | 47 ++++++++++++++++++++++++++++++++ src/pc/djui/djui_fps_display.h | 6 ++++ src/pc/djui/djui_panel.c | 2 +- src/pc/djui/djui_panel_display.c | 5 ++-- src/pc/pc_main.c | 4 ++- 18 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 src/pc/djui/djui_fps_display.c create mode 100644 src/pc/djui/djui_fps_display.h diff --git a/lang/Czech.ini b/lang/Czech.ini index 67622e3a..f21b97c7 100644 --- a/lang/Czech.ini +++ b/lang/Czech.ini @@ -147,6 +147,7 @@ DYNOS_PACKS = "DynOS packy" ANTIALIASING = "Anti-aliasing" OFF = "Vypnuto" MUST_RESTART = "Musíte restartovat hru pro aplikování změn." +SHOW_FPS = "Zobrazit FPS" [DYNOS] DYNOS = "DYNOS" @@ -357,6 +358,3 @@ REFRESHING = "Obnovování..." ENTER_PASSWORD = "Zadejte heslo soukromé hry:" SEARCH = "Hledat" NONE_FOUND = "Nebyly nalezeny žádné hry." - -[LOADING_SCREEN] -LOADING = "Načítání" diff --git a/lang/Dutch.ini b/lang/Dutch.ini index c3b8e4c6..4352fe7d 100644 --- a/lang/Dutch.ini +++ b/lang/Dutch.ini @@ -146,6 +146,7 @@ DYNOS_PACKS = "DynOS Packs" ANTIALIASING = "Anti-aliasing" OFF = "UIT" MUST_RESTART = "Je moet de game opnieuw opstarten voor sommige veranderingen om effect te hebben." +SHOW_FPS = "Toon FPS" [DYNOS] DYNOS = "DYNOS" @@ -355,6 +356,3 @@ REFRESHING = "herladen..." ENTER_PASSWORD = "Typ het wachtwoord van de privé lobby:" SEARCH = "Zoek" NONE_FOUND = "Er zijn geen lobby's gevonden." - -[LOADING_SCREEN] -LOADING = "Bezig met laden" diff --git a/lang/English.ini b/lang/English.ini index c6e48a91..5dcb93f4 100644 --- a/lang/English.ini +++ b/lang/English.ini @@ -147,6 +147,7 @@ DYNOS_PACKS = "DynOS Packs" ANTIALIASING = "Anti-aliasing" OFF = "Off" MUST_RESTART = "Restart the game to apply some changes." +SHOW_FPS = "Show FPS" [DYNOS] DYNOS = "DYNOS" @@ -357,6 +358,3 @@ REFRESHING = "Refreshing..." ENTER_PASSWORD = "Enter the private lobby's password:" SEARCH = "Search" NONE_FOUND = "No lobbies were found." - -[LOADING_SCREEN] -LOADING = "Loading" diff --git a/lang/French.ini b/lang/French.ini index fdc7f485..f06136b5 100644 --- a/lang/French.ini +++ b/lang/French.ini @@ -147,6 +147,7 @@ DYNOS_PACKS = "Packs DynOS" ANTIALIASING = "Anti-aliasing" OFF = "Désactivé" MUST_RESTART = "Vous devez relancer le jeu pour que certains changements prennent effet." +SHOW_FPS = "Afficher FPS" [DYNOS] DYNOS = "DYNOS" @@ -357,6 +358,3 @@ REFRESHING = "Actualisation..." ENTER_PASSWORD = "Entrez le mot de passe de la partie:" SEARCH = "Rechercher" NONE_FOUND = "Aucune partie n'a été trouvée." - -[LOADING_SCREEN] -LOADING = "Chargement" diff --git a/lang/German.ini b/lang/German.ini index ff8f3729..5ce94062 100644 --- a/lang/German.ini +++ b/lang/German.ini @@ -147,6 +147,7 @@ DYNOS_PACKS = "DynOS-Pakete" ANTIALIASING = "Kantenglättung" OFF = "Aus" MUST_RESTART = "Um einige Änderungen zu übernehmen, muss das Spiel neugestartet werden." +SHOW_FPS = "FPS anzeigen" [DYNOS] DYNOS = "DYNOS" @@ -357,6 +358,3 @@ REFRESHING = "Aktualisiere..." ENTER_PASSWORD = "Gib das Passwort für die Lobby ein:" SEARCH = "Suchen" NONE_FOUND = "Keine Lobbys gefunden." - -[LOADING_SCREEN] -LOADING = "Wird geladen" diff --git a/lang/Italian.ini b/lang/Italian.ini index 533186e6..042f4e44 100644 --- a/lang/Italian.ini +++ b/lang/Italian.ini @@ -145,6 +145,7 @@ DYNOS_PACKS = "Pacchetti DynOS" ANTIALIASING = "Anti-aliasing" OFF = "Off" MUST_RESTART = "You must restart the game for some changes to take effect." +SHOW_FPS = "Mostra FPS" [DYNOS] DYNOS = "DYNOS" @@ -354,6 +355,3 @@ REFRESHING = "Refreshing..." ENTER_PASSWORD = "Enter the private lobby's password:" SEARCH = "Search" NONE_FOUND = "No lobbies were found." - -[LOADING_SCREEN] -LOADING = "Caricamento" diff --git a/lang/Polish.ini b/lang/Polish.ini index 7c59befe..46564265 100644 --- a/lang/Polish.ini +++ b/lang/Polish.ini @@ -144,6 +144,7 @@ DYNOS_PACKS = "Paczki DynOS" ANTIALIASING = "Anti-aliasing" OFF = "Wylaczone" MUST_RESTART = "Musisz zrestartowac gre, aby zmiany zaczely obowiazywac." +SHOW_FPS = "Pokaż FPS" [DYNOS] DYNOS = "DYNOS" diff --git a/lang/Portuguese.ini b/lang/Portuguese.ini index af11ca34..775fc7b8 100644 --- a/lang/Portuguese.ini +++ b/lang/Portuguese.ini @@ -147,10 +147,11 @@ DYNOS_PACKS = "DynOS Packs" ANTIALIASING = "Anti-aliasing" OFF = "Desligado" MUST_RESTART = "Você precisará reiniciar o jogo para algumas alterações serem aplicadas." +SHOW_FPS = "Mostrar FPS" [DYNOS] DYNOS = "DYNOS" - + [HOST_MESSAGE] INFO_TITLE = "INFO" WARN_DISCORD = "Convide amigos clicando com o botão direito do mouse no nome deles no Discord e clicando em\n'\\#d0d0ff\\convidar para o jogo\\#c8c8c8\\'.\n\n Você também pode convidar canais de servidores clicando em \\#d0d0ff\\mais\\#c8c8c8\\ botão ao lado do local onde você entra no chat.\n\nGame Activity \\#ffa0a0\\precisa estar\\#c8c8c8\\ ativado nas suas\n configurações do discord.\n\n status offline\\#ffa0a0\\vai prevenir\\#c8c8c8\\ convites de serem enviados." @@ -357,6 +358,3 @@ REFRESHING = "Recarregando..." ENTER_PASSWORD = "Coloque a senha para a partida privada:" SEARCH = "Pesquisar" NONE_FOUND = "Nenhuma partida foi encontrada." - -[LOADING_SCREEN] -LOADING = "Carregando" diff --git a/lang/Russian.ini b/lang/Russian.ini index bb8bdc84..21b117c6 100644 --- a/lang/Russian.ini +++ b/lang/Russian.ini @@ -146,6 +146,7 @@ DYNOS_PACKS = "Пакеты DynOS" ANTIALIASING = "Анизотропная фильтрация" OFF = "Выкл" MUST_RESTART = "Перезапустите игру, чтобы изменения вступили в силу" +SHOW_FPS = "Показывать FPS" [DYNOS] DYNOS = "DYNOS" @@ -356,6 +357,3 @@ REFRESHING = "Обновление..." ENTER_PASSWORD = "Введите пароль закрытой группы:" SEARCH = "Поиск" NONE_FOUND = "Группы не найдены." - -[LOADING_SCREEN] -LOADING = "Загрузка" diff --git a/lang/Spanish.ini b/lang/Spanish.ini index c115f85a..6f8812a5 100644 --- a/lang/Spanish.ini +++ b/lang/Spanish.ini @@ -147,6 +147,7 @@ DYNOS_PACKS = "Packs de DynOS" ANTIALIASING = "Anti-aliasing" OFF = "Desactivado" MUST_RESTART = "Tienes que reiniciar el juego para que algunos cambios surtan efecto." +SHOW_FPS = "Mostrar FPS" [DYNOS] DYNOS = "DYNOS" diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 59d2e333..02fd8b91 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -139,6 +139,7 @@ bool configMenuRandom = false; bool configMenuDemos = false; struct PlayerPalette configPlayerPalette = {{{ 0x00, 0x00, 0xff }, { 0xff, 0x00, 0x00 }, { 0xff, 0xff, 0xff }, { 0x72, 0x1c, 0x0e }, { 0x73, 0x06, 0x00 }, { 0xfe, 0xc1, 0x79 }, { 0xff, 0x00, 0x00 }}}; struct PlayerPalette configCustomPalette = {{{ 0x00, 0x00, 0xff }, { 0xff, 0x00, 0x00 }, { 0xff, 0xff, 0xff }, { 0x72, 0x1c, 0x0e }, { 0x73, 0x06, 0x00 }, { 0xfe, 0xc1, 0x79 }, { 0xff, 0x00, 0x00 }}}; +bool configShowFPS = false; bool configUncappedFramerate = true; unsigned int configFrameLimit = 60; unsigned int configDrawDistance = 5; @@ -222,6 +223,7 @@ static const struct ConfigOption options[] = { {.name = "debug_offset", .type = CONFIG_TYPE_U64 , .u64Value = &gPcDebug.bhvOffset}, {.name = "debug_tags", .type = CONFIG_TYPE_U64 , .u64Value = gPcDebug.tags}, // coop-specific + {.name = "show_fps", .type = CONFIG_TYPE_BOOL , .boolValue = &configShowFPS}, {.name = "uncapped_framerate", .type = CONFIG_TYPE_BOOL , .boolValue = &configUncappedFramerate}, {.name = "frame_limit" , .type = CONFIG_TYPE_UINT , .uintValue = &configFrameLimit}, {.name = "amount_of_players", .type = CONFIG_TYPE_UINT , .uintValue = &configAmountofPlayers}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index f0a5e200..91e5083c 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -98,6 +98,7 @@ extern bool configMenuRandom; extern bool configMenuDemos; extern struct PlayerPalette configPlayerPalette; extern struct PlayerPalette configCustomPalette; +extern bool configShowFPS; extern bool configUncappedFramerate; extern unsigned int configFrameLimit; extern unsigned int configDrawDistance; diff --git a/src/pc/djui/djui.c b/src/pc/djui/djui.c index 20a2f1ba..9a83ef4f 100644 --- a/src/pc/djui/djui.c +++ b/src/pc/djui/djui.c @@ -6,6 +6,7 @@ #include "djui_panel_join.h" #include "djui_panel_join_message.h" #include "djui_console.h" +#include "djui_fps_display.h" #include "../debuglog.h" #include "pc/cliopts.h" #include "game/level_update.h" @@ -82,6 +83,9 @@ void djui_init(void) { djui_panel_playerlist_create(NULL); djui_console_create(); + + djui_fps_display_create(); + sDjuiInited = true; } @@ -140,6 +144,8 @@ void djui_render(void) { djui_base_render(&gDjuiRoot->base); } + djui_fps_display_render(); + if (sDjuiLuaErrorTimeout > 0) { sDjuiLuaErrorTimeout--; if (sDjuiLuaErrorTimeout == 0) { diff --git a/src/pc/djui/djui_fps_display.c b/src/pc/djui/djui_fps_display.c new file mode 100644 index 00000000..c9948383 --- /dev/null +++ b/src/pc/djui/djui_fps_display.c @@ -0,0 +1,47 @@ +#include "djui.h" +#include "../pc_main.h" + +struct DjuiFpsDisplay { + struct DjuiText *text; + struct DjuiBase base; +}; + +struct DjuiFpsDisplay *sFpsDisplay = NULL; + +void djui_fps_display_update(s16 fps) { + if (configShowFPS) { + char fpsText[30] = ""; + snprintf(fpsText, 30, "\\#dcdcdc\\FPS \\#ffffff\\%d", fps); + djui_text_set_text(sFpsDisplay->text, fpsText); + } +} + +void djui_fps_display_render(void) { + if (configShowFPS) { + djui_rect_render(&sFpsDisplay->base); + djui_base_render(&sFpsDisplay->base); + } +} + +void djui_fps_display_create(void) { + struct DjuiFpsDisplay *fpsDisplay = malloc(sizeof(struct DjuiFpsDisplay)); + struct DjuiBase* base = &fpsDisplay->base; + djui_base_init(NULL, base, NULL, NULL); + djui_base_set_size(base, 150, 50); + djui_base_set_color(base, 0, 0, 0, 240); + djui_base_set_border_color(base, 0, 0, 0, 200); + djui_base_set_border_width(base, 8); + djui_base_set_padding(base, 16, 16, 16, 16); + + { + // FPS text + struct DjuiText *text = djui_text_create(base, ""); + djui_base_set_size_type(&text->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&text->base, 1.0f, text->fontScale * 2); + djui_base_set_location(&text->base, 0, -text->fontScale / 2); + + fpsDisplay->text = text; + } + + sFpsDisplay = fpsDisplay; +} diff --git a/src/pc/djui/djui_fps_display.h b/src/pc/djui/djui_fps_display.h new file mode 100644 index 00000000..a35ea17b --- /dev/null +++ b/src/pc/djui/djui_fps_display.h @@ -0,0 +1,6 @@ +#pragma once +#include "djui.h" + +void djui_fps_display_update(s16 fps); +void djui_fps_display_render(void); +void djui_fps_display_create(void); diff --git a/src/pc/djui/djui_panel.c b/src/pc/djui/djui_panel.c index 400ff1e8..e29f8de0 100644 --- a/src/pc/djui/djui_panel.c +++ b/src/pc/djui/djui_panel.c @@ -28,7 +28,7 @@ struct DjuiBase* djui_panel_find_first_interactable(struct DjuiBaseChild* child) } // If we didn't find anything at all. Return NULL. - LOG_ERROR("Failed to find a interactable for child %p.", child); + // LOG_ERROR("Failed to find a interactable for child %p.", child); return NULL; } diff --git a/src/pc/djui/djui_panel_display.c b/src/pc/djui/djui_panel_display.c index bfec8630..db7a28e6 100644 --- a/src/pc/djui/djui_panel_display.c +++ b/src/pc/djui/djui_panel_display.c @@ -65,10 +65,11 @@ void djui_panel_display_create(struct DjuiBase* caller) { djui_checkbox_create(body, DLANG(DISPLAY, FORCE_4BY3), &configForce4By3, djui_panel_display_apply); - #ifdef EXTERNAL_DATA +#ifdef EXTERNAL_DATA djui_checkbox_create(body, DLANG(DISPLAY, PRELOAD_TEXTURES), &configPrecacheRes, NULL); - #endif +#endif + 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); diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 46cbf65c..17c085dd 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -43,6 +43,7 @@ #include "pc/djui/djui_unicode.h" #include "pc/djui/djui_panel.h" #include "pc/djui/djui_panel_modlist.h" +#include "pc/djui/djui_fps_display.h" #include "pc/debuglog.h" #include "pc/utils/misc.h" @@ -194,7 +195,8 @@ void produce_interpolation_frames_and_delay(void) { u32 fps = sFramesSinceFpsUpdate / ((f32)(sCurrentFpsUpdateTime - sLastFpsUpdateTime)); sLastFpsUpdateTime = sCurrentFpsUpdateTime; sFramesSinceFpsUpdate = 0; - //printf("fps: %u\n", fps); + + djui_fps_display_update(floor(fps)); } sFrameTimeStart = sFrameTargetTime;