fix(player-db): restore old on-demand thread creation behavior. (#2167)

Fixes #2160
This commit is contained in:
Quentin 2023-09-21 20:08:23 +02:00 committed by GitHub
parent 639d776267
commit 92b6df7653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 14 deletions

View File

@ -273,15 +273,29 @@ namespace big
void player_database_service::start_update_loop()
{
// So that it doesnt immediately exit the first time.
static bool first_time = true;
if (!g.player_db.update_player_online_states)
{
first_time = false;
return;
}
g_thread_pool->push([this] {
if (first_time)
{
while (!g_running)
{
std::this_thread::yield();
}
first_time = false;
}
static auto last_update = std::chrono::high_resolution_clock::now() - 45s;
while (g_running)
{
if (g.player_db.update_player_online_states)
while (g_running && g.player_db.update_player_online_states)
{
const auto cur = std::chrono::high_resolution_clock::now();
if (cur - last_update > 45s && !updating)
@ -293,7 +307,6 @@ namespace big
last_update = std::chrono::high_resolution_clock::now();
});
}
}
std::this_thread::sleep_for(1s);
}
@ -329,6 +342,7 @@ namespace big
{
rage::rlScTaskStatus status{};
// TODO: big sized object on the stack, might be a problem in the future
rage::rlQueryPresenceAttributesContext contexts[bucket_size][9]{};
rage::rlQueryPresenceAttributesContext* contexts_per_player[bucket_size]{};

View File

@ -300,6 +300,7 @@ namespace big
{
if (components::command_checkbox<"player_db_auto_update_states">("Enable"))
g_player_database_service->start_update_loop();
ImGui::Checkbox("Notify When Online", &g.player_db.notify_when_online);
ImGui::Checkbox("Notify When Joinable", &g.player_db.notify_when_joinable);
ImGui::Checkbox("Notify When Unjoinable", &g.player_db.notify_when_unjoinable);