Skip to content

Commit

Permalink
Debounce dynamic info sending
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed May 22, 2022
1 parent 1ce50ea commit 395052b
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ class Game {
Server *server = nullptr;

ClientDynamicInfo client_display_info{};
float dynamic_info_send_timer = 0;

IWritableTextureSource *texture_src = nullptr;
IWritableShaderSource *shader_src = nullptr;
Expand Down Expand Up @@ -1093,13 +1094,25 @@ void Game::run()
&& !(*kill || g_gamecallback->shutdown_requested
|| (server && server->isShutdownRequested()))) {

const auto current_display_info = getCurrentDynamicInfo();
if (!current_display_info.equal(client_display_info)) {
client_display_info = current_display_info;
client->sendUpdateClientInfo(current_display_info);
// Calculate dtime =
// m_rendering_engine->run() from this iteration
// + Sleep time until the wanted FPS are reached
draw_times.limit(device, &dtime);

const auto current_dynamic_info = getCurrentDynamicInfo();
if (!current_dynamic_info.equal(client_display_info)) {
client_display_info = current_dynamic_info;
dynamic_info_send_timer = 0.2f;
}

const auto &current_screen_size = current_display_info.render_target_size;
if (dynamic_info_send_timer > 0) {
dynamic_info_send_timer -= dtime;
if (dynamic_info_send_timer <= 0) {
client->sendUpdateClientInfo(current_dynamic_info);
}
}

const auto &current_screen_size = current_dynamic_info.render_target_size;

// Verify if window size has changed and save it if it's the case
// Ensure evaluating settings->getBool after verifying screensize
Expand All @@ -1112,11 +1125,6 @@ void Game::run()
previous_screen_size = current_screen_size;
}

// Calculate dtime =
// m_rendering_engine->run() from this iteration
// + Sleep time until the wanted FPS are reached
draw_times.limit(device, &dtime);

// Prepare render data for next iteration

updateStats(&stats, draw_times, dtime);
Expand Down

0 comments on commit 395052b

Please sign in to comment.