From 4fef9d92038ac44224cb054e538cf871e6a8ac28 Mon Sep 17 00:00:00 2001
From: thecozies <79979276+thecozies@users.noreply.github.com>
Date: Mon, 22 Apr 2024 08:11:13 -0500
Subject: [PATCH] show display refresh rate in description
---
assets/config_menu/graphics.rml | 5 ++++-
include/recomp_ui.h | 1 +
src/ui/ui_config.cpp | 16 ++++++++++++++++
src/ui/ui_renderer.cpp | 1 +
ultramodern/events.cpp | 4 ++++
ultramodern/ultramodern.hpp | 1 +
6 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/assets/config_menu/graphics.rml b/assets/config_menu/graphics.rml
index 1e1dedb..c6eb987 100644
--- a/assets/config_menu/graphics.rml
+++ b/assets/config_menu/graphics.rml
@@ -283,7 +283,10 @@
Sets the game's output framerate. This option does not affect gameplay.
- Note: If you have issues with Display mode while using an external frame limiter, use Manual mode instead and configure it to that same frame limit.
+ Note: If you have issues with Display mode while using an external frame limiter, use Manual mode instead and configure it to that same frame limit.
+
+
+ Detected display refresh rate: {{display_refresh_rate}}hz
Sets the multisample anti-aliasing (MSAA) quality level. This reduces jagged edges in the final image at the expense of rendering performance.
diff --git a/include/recomp_ui.h b/include/recomp_ui.h
index cae598f..3652ac7 100644
--- a/include/recomp_ui.h
+++ b/include/recomp_ui.h
@@ -72,6 +72,7 @@ namespace recomp {
void set_cursor_visible(bool visible);
void update_supported_options();
void toggle_fullscreen();
+ void update_rml_display_refresh_rate();
extern const std::unordered_map button_variants;
diff --git a/src/ui/ui_config.cpp b/src/ui/ui_config.cpp
index c92035b..28624d4 100644
--- a/src/ui/ui_config.cpp
+++ b/src/ui/ui_config.cpp
@@ -377,6 +377,17 @@ struct DebugContext {
}
};
+void recomp::update_rml_display_refresh_rate() {
+ static uint32_t lastRate = 0;
+ if (!graphics_model_handle) return;
+
+ uint32_t curRate = ultramodern::get_display_refresh_rate();
+ if (curRate != lastRate) {
+ graphics_model_handle.DirtyVariable("display_refresh_rate");
+ }
+ lastRate = curRate;
+}
+
DebugContext debug_context;
class ConfigMenu : public recomp::MenuController {
@@ -523,6 +534,11 @@ public:
graphics_model_handle.DirtyVariable("ds_info");
});
+ constructor.BindFunc("display_refresh_rate",
+ [](Rml::Variant& out) {
+ out = ultramodern::get_display_refresh_rate();
+ });
+
constructor.BindFunc("options_changed",
[](Rml::Variant& out) {
out = (ultramodern::get_graphics_config() != new_options);
diff --git a/src/ui/ui_renderer.cpp b/src/ui/ui_renderer.cpp
index 0b04879..403e646 100644
--- a/src/ui/ui_renderer.cpp
+++ b/src/ui/ui_renderer.cpp
@@ -956,6 +956,7 @@ struct UIContext {
void update_config_menu_loop(bool menu_changed) {
static int prevTab = -1;
if (menu_changed) prevTab = -1;
+ recomp::update_rml_display_refresh_rate();
Rml::ElementTabSet *tabset = (Rml::ElementTabSet *)current_document->GetElementById("config_tabset");
if (tabset == nullptr) return;
diff --git a/ultramodern/events.cpp b/ultramodern/events.cpp
index 82b62e1..e80ede5 100644
--- a/ultramodern/events.cpp
+++ b/ultramodern/events.cpp
@@ -292,6 +292,10 @@ uint32_t ultramodern::get_target_framerate(uint32_t original) {
}
}
+uint32_t ultramodern::get_display_refresh_rate() {
+ return display_refresh_rate.load();
+}
+
void gfx_thread_func(uint8_t* rdram, std::atomic_flag* thread_ready, ultramodern::WindowHandle window_handle) {
bool enabled_instant_present = false;
using namespace std::chrono_literals;
diff --git a/ultramodern/ultramodern.hpp b/ultramodern/ultramodern.hpp
index d436c58..667c8cb 100644
--- a/ultramodern/ultramodern.hpp
+++ b/ultramodern/ultramodern.hpp
@@ -96,6 +96,7 @@ std::chrono::high_resolution_clock::time_point get_start();
std::chrono::high_resolution_clock::duration time_since_start();
void get_window_size(uint32_t& width, uint32_t& height);
uint32_t get_target_framerate(uint32_t original);
+uint32_t get_display_refresh_rate();
void measure_input_latency();
void sleep_milliseconds(uint32_t millis);
void sleep_until(const std::chrono::high_resolution_clock::time_point& time_point);