allow controlling the renderer detector timeout via a config file

This commit is contained in:
otavepto 2024-03-08 13:50:25 +02:00 committed by otavepto
parent 88203b5c6f
commit 65edb7081a
5 changed files with 48 additions and 15 deletions

View File

@ -275,7 +275,8 @@ public:
//overlay
bool disable_overlay = false;
int overlay_hook_delay_sec = 3;
int overlay_hook_delay_sec = 5; // "Saints Row (2022)" needs a lot of time to initialize, otherwise detection will fail
int overlay_renderer_detector_timeout_sec = 15; // "Saints Row (2022)" takes almost ~8 sec to detect renderer (DX12)
bool disable_overlay_achievement_notification = false;
bool disable_overlay_friend_notification = false;
//warn people who use force_ settings

View File

@ -1137,7 +1137,6 @@ static void parse_overlay_hook_delay_sec(class Settings *settings_client, Settin
std::string auto_accept_list_path = Local_Storage::get_game_settings_path() + "overlay_hook_delay_sec.txt";
std::ifstream input( utf8_decode(auto_accept_list_path) );
if (input.is_open()) {
bool accept_any_invite = true;
common_helpers::consume_bom(input);
std::string line{};
std::getline( input, line );
@ -1155,6 +1154,29 @@ static void parse_overlay_hook_delay_sec(class Settings *settings_client, Settin
}
}
// overlay_renderer_detector_timeout_sec.txt
static void parse_overlay_renderer_detector_timeout_sec(class Settings *settings_client, Settings *settings_server)
{
std::string auto_accept_list_path = Local_Storage::get_game_settings_path() + "overlay_renderer_detector_timeout_sec.txt";
std::ifstream input( utf8_decode(auto_accept_list_path) );
if (input.is_open()) {
common_helpers::consume_bom(input);
std::string line{};
std::getline( input, line );
line = common_helpers::string_strip(line);
if (!line.empty()) {
try {
auto timeout_sec = std::stoi(line);
if (timeout_sec > 0) {
settings_client->overlay_renderer_detector_timeout_sec = timeout_sec;
settings_server->overlay_renderer_detector_timeout_sec = timeout_sec;
PRINT_DEBUG("Setting overlay renderer detector timeout to %i seconds\n", timeout_sec);
}
} catch (...) {}
}
}
}
uint32 create_localstorage_settings(Settings **settings_client_out, Settings **settings_server_out, Local_Storage **local_storage_out)
{
std::string program_path = Local_Storage::get_program_path();
@ -1367,6 +1389,7 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
parse_auto_accept_invite(settings_client, settings_server);
parse_ip_country(settings_client, settings_server);
parse_overlay_hook_delay_sec(settings_client, settings_server);
parse_overlay_renderer_detector_timeout_sec(settings_client, settings_server);
*settings_client_out = settings_client;
*settings_server_out = settings_server;

View File

@ -155,6 +155,7 @@ Steam_Overlay::~Steam_Overlay()
run_every_runcb->remove(&Steam_Overlay::steam_overlay_run_every_runcb, this);
}
constexpr static const int renderer_detector_polling_ms = 100;
void Steam_Overlay::renderer_hook_init_thread()
{
@ -172,9 +173,9 @@ void Steam_Overlay::renderer_hook_init_thread()
// request renderer detection
auto future_renderer = InGameOverlay::DetectRenderer();
PRINT_DEBUG("Steam_Overlay::renderer_hook_init requested renderer detector/hook\n");
int polling_time_ms = 500;
int timeout_ctr = 10 /*seconds*/ * 1000 /*milli per second*/ / polling_time_ms;
while (timeout_ctr > 0 && setup_overlay_called && future_renderer.wait_for(std::chrono::milliseconds(polling_time_ms)) != std::future_status::ready) {
int timeout_ctr = settings->overlay_renderer_detector_timeout_sec /*seconds*/ * 1000 /*milli per second*/ / renderer_detector_polling_ms;
while (timeout_ctr > 0 && setup_overlay_called && future_renderer.wait_for(std::chrono::milliseconds(renderer_detector_polling_ms)) != std::future_status::ready) {
--timeout_ctr;
}
@ -182,10 +183,12 @@ void Steam_Overlay::renderer_hook_init_thread()
InGameOverlay::StopRendererDetection();
InGameOverlay::FreeDetector();
// exit on failure
if (timeout_ctr <= 0 || !setup_overlay_called || !future_renderer.valid()) {
bool final_chance = (future_renderer.wait_for(std::chrono::milliseconds(1)) == std::future_status::ready) && future_renderer.valid();
// again check for 'setup_overlay_called' to be extra sure that the overlay wasn't deinitialized
if (!setup_overlay_called || !final_chance || timeout_ctr <= 0) {
PRINT_DEBUG(
"Steam_Overlay::renderer_hook_init failed to detect renderer, ctr=%i, overlay was set up=%i, valid hook intance-%i\n",
timeout_ctr, (int)setup_overlay_called, future_renderer.valid()
"Steam_Overlay::renderer_hook_init failed to detect renderer, ctr=%i, overlay was set up=%i, hook intance state=%i\n",
timeout_ctr, (int)setup_overlay_called, (int)final_chance
);
return;
}
@ -1225,7 +1228,7 @@ void Steam_Overlay::UnSetupOverlay()
is_ready = false;
// allow the future_renderer thread to exit if needed
std::this_thread::sleep_for(std::chrono::milliseconds(500 + 50));
std::this_thread::sleep_for(std::chrono::milliseconds((int)(renderer_detector_polling_ms * 1.3f)));
if (_renderer) {
for (auto &ach : achievements) {

View File

@ -515,18 +515,23 @@ Also, match making servers will return the info of the server from the incoming
---
## Overlay hook delay:
## Overlay hook delay and renderer detector timeout:
**Note: at the moment this feature is only enabled in the experimental builds**
---
By default the emu will wait `3 seconds` before attempting to start the overlay renderer detector, this allows some games to initialize properly, otherwise the detector may not detect the renderer (DirectX, OpenGL, etc...) and the overlay will not work (example game: `Have a Nice Death`).
You can control this delay via the configuration file `overlay_hook_delay_sec.txt`. It must contain only one line, specifying the amount of seconds to wait.
It is **NOT** recommended to remove this delay or setting it to 0, also negative values will be ignored.
By default the emu will wait `5 seconds` before attempting to start the overlay renderer detector, this allows some games to initialize properly, otherwise the detector may not detect the current renderer (DirectX, OpenGL, etc...) and the overlay will not work (example games: `Have a Nice Death`, `Saints Row (2022)`).
The renderer detector will have a `10 second` timeout after initialization (not including the delay), after that it will fail.
After that initial delay, the emu will give the detector `15 seconds` as a timeout, after that time if the detector didn't return a valid result, it will fail.
This avoids an infinite detection loop and a potential FPS drop on failure.
Check the example file in the `steam_settings` folder
You can control these timings via the configuration files:
* `overlay_hook_delay_sec.txt`: controls the amount of seconds to wait for initially before attempting the detection.
* `overlay_renderer_detector_timeout_sec.txt`: controls the timeout (in seconds) of the detection.
It is **NOT** recommended to remove these timings or setting them to 0.
Negative values will be ignored, also the renderer detector timeout cannot be 0.
Check the example files in the `steam_settings` folder
---