Author: cazfi Date: Tue Aug 4 20:40:33 2015 New Revision: 29334 URL: http://svn.gna.org/viewcvs/freeciv?rev=29334&view=rev Log: Added turn change processing ETA display to gtk-clients.
Requested by mrvn See bug #14585 Modified: branches/S2_6/client/client_main.c branches/S2_6/client/client_main.h branches/S2_6/client/clinet.c branches/S2_6/client/gui-gtk-2.0/mapview.c branches/S2_6/client/gui-gtk-3.0/mapview.c branches/S2_6/client/packhand.c branches/S2_6/client/text.c branches/S2_6/common/game.h branches/S2_6/common/packets.def branches/S2_6/fc_version branches/S2_6/server/savegame2.c branches/S2_6/server/srv_main.c Modified: branches/S2_6/client/client_main.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/client_main.c?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/client/client_main.c (original) +++ branches/S2_6/client/client_main.c Tue Aug 4 20:40:33 2015 @@ -1026,9 +1026,15 @@ static double seconds_to_turndone = 0.0; static struct timer *turndone_timer; +/* The timer tells how long since server informed us about starting + * turn-change activities. */ +static struct timer *between_turns = NULL; +static bool waiting_turn_change = FALSE; + /* This value shows what value the timeout label is currently showing for * the seconds-to-turndone. */ static int seconds_shown_to_turndone; +static int seconds_shown_to_new_turn; /************************************************************************** Reset the number of seconds to turndone from an "authentic" source. @@ -1047,6 +1053,35 @@ * seem to be necessary. */ seconds_shown_to_turndone = ceil(seconds) + 0.1; } +} + +/************************************************************************** + Are we in turn-change wait state? +**************************************************************************/ +bool is_waiting_turn_change(void) +{ + return waiting_turn_change; +} + +/************************************************************************** + Start waiting of the server turn change activities. +**************************************************************************/ +void start_turn_change_wait(void) +{ + seconds_shown_to_new_turn = ceil(game.tinfo.last_turn_change_time) + 0.1; + between_turns = timer_renew(between_turns, TIMER_USER, TIMER_ACTIVE); + timer_start(between_turns); + + waiting_turn_change = TRUE; +} + +/************************************************************************** + Server is responsive again +**************************************************************************/ +void stop_turn_change_wait(void) +{ + waiting_turn_change = FALSE; + update_timeout_label(); } /************************************************************************** @@ -1064,6 +1099,15 @@ } /************************************************************************** + Return the number of seconds until turn-done. Don't call this unless + game.info.timeout != 0. +**************************************************************************/ +int get_seconds_to_new_turn(void) +{ + return seconds_shown_to_new_turn; +} + +/************************************************************************** This function should be called at least once per second. It does various updates (idle animations and timeout updates). It returns the number of seconds until it should be called again. @@ -1108,6 +1152,15 @@ time_until_next_call = MIN(time_until_next_call, seconds - floor(seconds) + 0.001); + } + 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. */ + + if (iseconds < game.tinfo.last_turn_change_time) { + seconds_shown_to_new_turn = iseconds; + update_timeout_label(); + } } /* Make sure we wait at least 50 ms, otherwise we may not give any other Modified: branches/S2_6/client/client_main.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/client_main.h?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/client/client_main.h (original) +++ branches/S2_6/client/client_main.h Tue Aug 4 20:40:33 2015 @@ -104,6 +104,10 @@ struct player *client_player(void); void set_seconds_to_turndone(double seconds); int get_seconds_to_turndone(void); +bool is_waiting_turn_change(void); +void start_turn_change_wait(void); +void stop_turn_change_wait(void); +int get_seconds_to_new_turn(void); double real_timer_callback(void); bool can_client_control(void); bool can_client_issue_orders(void); Modified: branches/S2_6/client/clinet.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/clinet.c?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/client/clinet.c (original) +++ branches/S2_6/client/clinet.c Tue Aug 4 20:40:33 2015 @@ -294,6 +294,9 @@ const bool force = !client.conn.used; attribute_flush(); + + stop_turn_change_wait(); + /* If it's internal server - kill him * We assume that we are always connected to the internal server */ if (!force) { Modified: branches/S2_6/client/gui-gtk-2.0/mapview.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/mapview.c?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/client/gui-gtk-2.0/mapview.c (original) +++ branches/S2_6/client/gui-gtk-2.0/mapview.c Tue Aug 4 20:40:33 2015 @@ -100,9 +100,13 @@ gtk_label_set_text(GTK_LABEL(timeout_label), get_timeout_label_text()); if (current_turn_timeout() > 0) { - gtk_widget_set_tooltip_text(timeout_label, _("Time to forced turn change")); + gtk_widget_set_tooltip_text(timeout_label, + _("Time to forced turn change,\n" + "or eta to finish of turn change processing.")); } else { - gtk_widget_set_tooltip_text(timeout_label, _("Turn timeout disabled")); + gtk_widget_set_tooltip_text(timeout_label, + _("Turn timeout disabled.\nBetween turns eta to " + "finish of turn change processing.")); } } Modified: branches/S2_6/client/gui-gtk-3.0/mapview.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/mapview.c?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/client/gui-gtk-3.0/mapview.c (original) +++ branches/S2_6/client/gui-gtk-3.0/mapview.c Tue Aug 4 20:40:33 2015 @@ -102,9 +102,13 @@ gtk_label_set_text(GTK_LABEL(timeout_label), get_timeout_label_text()); if (current_turn_timeout() > 0) { - gtk_widget_set_tooltip_text(timeout_label, _("Time to forced turn change")); + gtk_widget_set_tooltip_text(timeout_label, + _("Time to forced turn change,\n" + "or eta to finish of turn change processing.")); } else { - gtk_widget_set_tooltip_text(timeout_label, _("Turn timeout disabled")); + gtk_widget_set_tooltip_text(timeout_label, + _("Turn timeout disabled.\nBetween turns eta to " + "finish of turn change processing.")); } } Modified: branches/S2_6/client/packhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/client/packhand.c (original) +++ branches/S2_6/client/packhand.c Tue Aug 4 20:40:33 2015 @@ -1257,6 +1257,8 @@ /* Possibly replace wait cursor with something else */ set_server_busy(FALSE); + + stop_turn_change_wait(); } /************************************************************************** @@ -1269,6 +1271,8 @@ /* Make sure wait cursor is in use */ set_server_busy(TRUE); + + start_turn_change_wait(); } /************************************************************************** @@ -1913,7 +1917,7 @@ /************************************************************************** Sets the remaining turn time. **************************************************************************/ -void handle_timeout_info(float seconds_to_phasedone) +void handle_timeout_info(float seconds_to_phasedone, float last_turn_change_time) { if (current_turn_timeout() != 0 && seconds_to_phasedone >= 0) { /* If this packet is received in the middle of a turn, this value @@ -1922,6 +1926,8 @@ * timer. */ set_seconds_to_turndone(seconds_to_phasedone); } + + game.tinfo.last_turn_change_time = last_turn_change_time; } /************************************************************************** Modified: branches/S2_6/client/text.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/text.c?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/client/text.c (original) +++ branches/S2_6/client/text.c Tue Aug 4 20:40:33 2015 @@ -1480,10 +1480,20 @@ astr_clear(&str); - if (current_turn_timeout() <= 0) { - astr_add(&str, "%s", Q_("?timeout:off")); - } else { - astr_add(&str, "%s", format_duration(get_seconds_to_turndone())); + if (is_waiting_turn_change()) { + double wt = get_seconds_to_new_turn(); + + if (wt < 0.01) { + astr_add(&str, "%s", Q_("?timeout:wait")); + } else { + astr_add(&str, "%s: %s", Q_("?timeout:eta"), format_duration(wt)); + } + } else { + if (current_turn_timeout() <= 0) { + astr_add(&str, "%s", Q_("?timeout:off")); + } else { + astr_add(&str, "%s", format_duration(get_seconds_to_turndone())); + } } return astr_str(&str); Modified: branches/S2_6/common/game.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.h?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/common/game.h (original) +++ branches/S2_6/common/game.h Tue Aug 4 20:40:33 2015 @@ -198,6 +198,7 @@ * take effect until the next turn. */ int phase_mode_stored; struct timer *save_timer; + float turn_change_time; char connectmsg[MAX_LEN_MSG]; char save_name[MAX_LEN_NAME]; bool scorelog; Modified: branches/S2_6/common/packets.def URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/common/packets.def (original) +++ branches/S2_6/common/packets.def Tue Aug 4 20:40:33 2015 @@ -540,6 +540,7 @@ # while has passed means a completely reset timeout. PACKET_TIMEOUT_INFO = 244; sc SFLOAT10x3 seconds_to_phasedone; + SFLOAT10x3 last_turn_change_time; end PACKET_MAP_INFO = 17; sc, lsend Modified: branches/S2_6/fc_version URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/fc_version (original) +++ branches/S2_6/fc_version Tue Aug 4 20:40:33 2015 @@ -54,7 +54,7 @@ # - Avoid adding a new mandatory capability to the development branch for # as long as possible. We want to maintain network compatibility with # the stable branch for as long as possible. -NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Jul.31" +NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Aug.04" NETWORK_CAPSTRING_OPTIONAL="" FREECIV_DISTRIBUTOR="" Modified: branches/S2_6/server/savegame2.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/server/savegame2.c (original) +++ branches/S2_6/server/savegame2.c Tue Aug 4 20:40:33 2015 @@ -2146,6 +2146,9 @@ game.info.is_new_game = !secfile_lookup_bool_default(loading->file, TRUE, "game.save_players"); + + game.server.turn_change_time + = secfile_lookup_int_default(loading->file, 0, "game.last_turn_change_time") / 100; } /**************************************************************************** @@ -2259,10 +2262,14 @@ if (!game_was_started()) { saving->save_players = FALSE; - } else if (saving->scenario) { - saving->save_players = game.scenario.players; } else { - saving->save_players = TRUE; + if (saving->scenario) { + saving->save_players = game.scenario.players; + } else { + saving->save_players = TRUE; + } + secfile_insert_int(saving->file, game.server.turn_change_time * 100, + "game.last_turn_change_time"); } secfile_insert_bool(saving->file, saving->save_players, "game.save_players"); Modified: branches/S2_6/server/srv_main.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=29334&r1=29333&r2=29334&view=diff ============================================================================== --- branches/S2_6/server/srv_main.c (original) +++ branches/S2_6/server/srv_main.c Tue Aug 4 20:40:33 2015 @@ -1045,6 +1045,7 @@ sanity_check(); + game.tinfo.last_turn_change_time = (float)game.server.turn_change_time; game.tinfo.seconds_to_phasedone = (double)current_turn_timeout(); game.server.phase_timer = timer_renew(game.server.phase_timer, TIMER_USER, TIMER_ACTIVE); @@ -2430,6 +2431,7 @@ static void srv_running(void) { struct timer *eot_timer; /* time server processing at end-of-turn */ + struct timer *between_turns = NULL; int save_counter = 0, i; bool is_new_turn = game.info.is_new_game; bool skip_mapimg = !game.info.is_new_game; /* Do not overwrite start-of-turn image */ @@ -2488,6 +2490,7 @@ } conn_list_iterate_end; need_send_pending_events = FALSE; } + is_new_turn = TRUE; force_end_of_sniff = FALSE; @@ -2534,9 +2537,18 @@ log_debug("sniffingpackets"); check_for_full_turn_done(); /* HACK: don't wait during AI phases */ + + if (between_turns != NULL) { + game.server.turn_change_time = timer_read_seconds(between_turns); + log_debug("Inresponsive between turns %g seconds", game.server.turn_change_time); + } + while (server_sniff_all_input() == S_E_OTHERWISE) { /* nothing */ } + + between_turns = timer_renew(between_turns, TIMER_USER, TIMER_ACTIVE); + timer_start(between_turns); /* After sniff, re-zero the timer: (read-out above on next loop) */ timer_clear(eot_timer); @@ -2977,6 +2989,8 @@ /* game_init() set game.server.plr_colors to NULL. So we need to * initialize the colors after. */ playercolor_init(); + + game.server.turn_change_time = 0; } /************************************************************************** _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits