Author: cazfi
Date: Tue Aug  4 20:40:25 2015
New Revision: 29333

URL: http://svn.gna.org/viewcvs/freeciv?rev=29333&view=rev
Log:
Added turn change processing ETA display to gtk-clients.

Requested by mrvn

See bug #14585

Modified:
    trunk/client/client_main.c
    trunk/client/client_main.h
    trunk/client/clinet.c
    trunk/client/gui-gtk-2.0/mapview.c
    trunk/client/gui-gtk-3.0/mapview.c
    trunk/client/packhand.c
    trunk/client/text.c
    trunk/common/game.h
    trunk/common/packets.def
    trunk/fc_version
    trunk/server/savegame2.c
    trunk/server/savegame3.c
    trunk/server/srv_main.c

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Tue Aug  4 20:40:25 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
+  current_turn_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: trunk/client/client_main.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.h?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/client/client_main.h  (original)
+++ trunk/client/client_main.h  Tue Aug  4 20:40:25 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: trunk/client/clinet.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/clinet.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/client/clinet.c       (original)
+++ trunk/client/clinet.c       Tue Aug  4 20:40:25 2015
@@ -298,6 +298,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: trunk/client/gui-gtk-2.0/mapview.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/mapview.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/mapview.c  (original)
+++ trunk/client/gui-gtk-2.0/mapview.c  Tue Aug  4 20:40:25 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: trunk/client/gui-gtk-3.0/mapview.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/mapview.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/mapview.c  (original)
+++ trunk/client/gui-gtk-3.0/mapview.c  Tue Aug  4 20:40:25 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: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Tue Aug  4 20:40:25 2015
@@ -1288,6 +1288,8 @@
 
   /* Possibly replace wait cursor with something else */
   set_server_busy(FALSE);
+
+  stop_turn_change_wait();
 }
 
 /**************************************************************************
@@ -1300,6 +1302,8 @@
 
   /* Make sure wait cursor is in use */
   set_server_busy(TRUE);
+
+  start_turn_change_wait();
 }
 
 /**************************************************************************
@@ -1945,7 +1949,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
@@ -1954,6 +1958,8 @@
      * timer. */
     set_seconds_to_turndone(seconds_to_phasedone);
   }
+
+  game.tinfo.last_turn_change_time = last_turn_change_time;
 }
 
 /**************************************************************************

Modified: trunk/client/text.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/text.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/client/text.c (original)
+++ trunk/client/text.c Tue Aug  4 20:40:25 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: trunk/common/game.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/game.h?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/common/game.h (original)
+++ trunk/common/game.h Tue Aug  4 20:40:25 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: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Tue Aug  4 20:40:25 2015
@@ -541,6 +541,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: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Tue Aug  4 20:40:25 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-3.0-2015.Aug.03"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Aug.04"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Tue Aug  4 20:40:25 2015
@@ -1482,6 +1482,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;
 }
 
 /* =======================================================================

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Tue Aug  4 20:40:25 2015
@@ -1881,6 +1881,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;
 }
 
 /****************************************************************************
@@ -1994,10 +1997,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: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=29333&r1=29332&r2=29333&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Tue Aug  4 20:40:25 2015
@@ -1049,6 +1049,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);
@@ -2464,6 +2465,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 */
@@ -2522,6 +2524,7 @@
         } conn_list_iterate_end;
         need_send_pending_events = FALSE;
       }
+
       is_new_turn = TRUE;
 
       force_end_of_sniff = FALSE;
@@ -2568,9 +2571,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);
@@ -3011,6 +3023,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

Reply via email to