Skip to content

Commit

Permalink
Prevent 100% CPU usage when there's a unit in focus
Browse files Browse the repository at this point in the history
The time until next frame was repeatedly divided by 1000, resulting in 0 wait
at the end.

See #782.
See #789.
  • Loading branch information
lmoureaux committed Dec 31, 2021
1 parent e5374cf commit 66fe1a6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions client/client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,14 +1095,12 @@ double real_timer_callback()

{
double blink_time = blink_turn_done_button();

time_until_next_call = MIN(time_until_next_call, blink_time) / 1000;
time_until_next_call = std::min(time_until_next_call, blink_time / 1000);
}

if (get_num_units_in_focus() > 0) {
double blink_time = blink_active_unit();

time_until_next_call = MIN(time_until_next_call, blink_time) / 1000;
time_until_next_call = std::min(time_until_next_call, blink_time / 1000);
}

/* It is possible to have current_turn_timeout() > 0 but !turndone_timer,
Expand All @@ -1113,7 +1111,7 @@ double real_timer_callback()
update_timeout_label();
}

time_until_next_call = MIN(time_until_next_call, 1.0);
time_until_next_call = std::min(time_until_next_call, 1.0);
}
if (waiting_turn_change) {
double seconds =
Expand All @@ -1136,6 +1134,7 @@ double real_timer_callback()
}
}

qCritical() << time_until_next_call;
return std::max(time_until_next_call, 0.0);
}

Expand Down

0 comments on commit 66fe1a6

Please sign in to comment.