From fa4c20f571c33e12467a5d77fde9aec7f18856cb Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 17 Feb 2023 20:44:48 +0200 Subject: [PATCH 28/28] Client: Fix float/integer handling trouble with the timeout - Add 0.1 second marginal to the float passed to ceil(), not to the integer that it returns - Treat get_seconds_to_new_turn() return value as an int which it is Reported anonymously See osdn #44902 Signed-off-by: Marko Lindqvist --- client/client_main.c | 12 ++++++------ client/text.c | 7 ++++--- client/text.h | 3 +-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index 5e969c6fdc..6c5425e82e 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -1111,7 +1111,7 @@ void set_seconds_to_turndone(double seconds) /* Maybe we should do an update_timeout_label here, but it doesn't * seem to be necessary. */ - seconds_shown_to_turndone = ceil(seconds) + 0.1; + seconds_shown_to_turndone = ceil(seconds + 0.1); } } @@ -1128,7 +1128,7 @@ bool is_waiting_turn_change(void) **************************************************************************/ void start_turn_change_wait(void) { - seconds_shown_to_new_turn = ceil(game.tinfo.last_turn_change_time) + 0.1; + seconds_shown_to_new_turn = ceil(game.tinfo.last_turn_change_time + 0.1); between_turns = timer_renew(between_turns, TIMER_USER, TIMER_ACTIVE, between_turns != NULL ? NULL : "between turns"); timer_start(between_turns); @@ -1160,7 +1160,7 @@ int get_seconds_to_turndone(void) } /**********************************************************************//** - Return the number of seconds until turn-done. Don't call this unless + Return the number of seconds until turn-done. Don't call this unless current_turn_timeout() != 0. **************************************************************************/ int get_seconds_to_new_turn(void) @@ -1204,9 +1204,9 @@ double real_timer_callback(void) /* It is possible to have current_turn_timeout() > 0 but !turndone_timer, * in the first moments after the timeout is set. */ - if (current_turn_timeout() > 0 && turndone_timer) { + if (current_turn_timeout() > 0 && turndone_timer != NULL) { double seconds = seconds_to_turndone - timer_read_seconds(turndone_timer); - int iseconds = ceil(seconds) + 0.1; /* Turn should end right on 0. */ + int iseconds = ceil(seconds + 0.1); /* Turn should end right on 0. */ if (iseconds < seconds_shown_to_turndone) { seconds_shown_to_turndone = iseconds; @@ -1218,7 +1218,7 @@ double real_timer_callback(void) } if (waiting_turn_change) { double seconds = game.tinfo.last_turn_change_time - timer_read_seconds(between_turns); - int iseconds = ceil(seconds) + 0.1; /* Turn should end right on 0. */ + int iseconds = ceil(seconds + 0.1); /* Turn should end right on 0. */ if (iseconds < game.tinfo.last_turn_change_time) { seconds_shown_to_new_turn = iseconds; diff --git a/client/text.c b/client/text.c index 8210c7b5bb..2d79784fe4 100644 --- a/client/text.c +++ b/client/text.c @@ -53,6 +53,7 @@ static int get_bulbs_per_turn(int *pours, bool *pteam, int *ptheirs); +static const char *format_duration(int duration); /************************************************************************//** Return a (static) string with a tile's food/prod/trade @@ -1560,9 +1561,9 @@ const char *get_timeout_label_text(void) astr_clear(&str); if (is_waiting_turn_change() && game.tinfo.last_turn_change_time >= 1.5) { - double wt = get_seconds_to_new_turn(); + int wt = get_seconds_to_new_turn(); - if (wt < 0.01) { + if (wt <= 0) { astr_add(&str, "%s", Q_("?timeout:wait")); } else { astr_add(&str, "%s: %s", Q_("?timeout:eta"), format_duration(wt)); @@ -1586,7 +1587,7 @@ const char *get_timeout_label_text(void) Not re-entrant ****************************************************************************/ -const char *format_duration(int duration) +static const char *format_duration(int duration) { static struct astring str = ASTRING_INIT; diff --git a/client/text.h b/client/text.h index 9cab7046c6..ab4fae1953 100644 --- a/client/text.h +++ b/client/text.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 2004 - The Freeciv Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,7 +49,6 @@ bool get_units_disband_info(char *buf, size_t bufsz, struct unit_list *punits); const char *get_spaceship_descr(struct player_spaceship *pship); const char *get_timeout_label_text(void); -const char *format_duration(int duration); const char *get_ping_time_text(const struct player *pplayer); const char *get_score_text(const struct player *pplayer); const char *get_report_title(const char *report_name); -- 2.39.1