<URL: http://bugs.freeciv.org/Ticket/Display.html?id=17793 >

On 12/08/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  I had to introduce new packets END_TURN and BEGIN_TURN. So this one
> is suitable for trunk only, for S2_1 version capability checks have to
> be added.

 Here is version with capability checks.

 As our capability string is getting rather long even before first
release from this stable branch, I made capability just two letter
abbreviation.

 It turns out that cursor handling has changed a lot between S2_1 and
trunk. In S2_1 this patch does only bad things without additional
support code to every client.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/civclient.c freeciv/client/civclient.c
--- freeciv/client/civclient.c	2007-07-04 14:04:27.000000000 +0300
+++ freeciv/client/civclient.c	2007-08-12 23:09:46.000000000 +0300
@@ -101,6 +101,11 @@
  */
 bool turn_done_sent = FALSE;
 
+/*
+ * TRUE between receiving PACKET_END_TURN and PACKET_BEGIN_TURN
+ */
+static bool server_busy = FALSE;
+
 /**************************************************************************
   Convert a text string from the internal to the data encoding, when it
   is written to the network.
@@ -757,3 +762,26 @@
 	  && (get_client_state() == CLIENT_GAME_RUNNING_STATE
 	      || get_client_state() == CLIENT_GAME_OVER_STATE));
 }
+
+/**************************************************************************
+  Sets if server is considered busy. Currently it is considered busy
+  between turns.
+**************************************************************************/
+void set_server_busy(bool busy)
+{
+  if (busy != server_busy) {
+    /* server_busy value will change */
+    server_busy = busy;
+
+    /* This may mean that we have to change from or to wait cursor */
+    handle_mouse_cursor(NULL);
+  }
+}
+
+/**************************************************************************
+  Returns if server is considered busy at the moment
+**************************************************************************/
+bool is_server_busy(void)
+{
+  return server_busy;
+}
diff -Nurd -X.diff_ignore freeciv/client/civclient.h freeciv/client/civclient.h
--- freeciv/client/civclient.h	2007-03-05 19:14:36.000000000 +0200
+++ freeciv/client/civclient.h	2007-08-12 23:09:46.000000000 +0300
@@ -34,6 +34,8 @@
 
 void set_client_state(enum client_states newstate);
 enum client_states get_client_state(void);
+void set_server_busy(bool busy);
+bool is_server_busy(void);
 
 void client_remove_cli_conn(struct connection *pconn);
 void client_remove_all_cli_conn(void);
diff -Nurd -X.diff_ignore freeciv/client/control.c freeciv/client/control.c
--- freeciv/client/control.c	2007-07-04 14:04:27.000000000 +0300
+++ freeciv/client/control.c	2007-08-12 23:36:14.000000000 +0300
@@ -884,6 +884,13 @@
   struct city *pcity = NULL;
   struct unit_list *active_units = get_units_in_focus();
 
+  if (is_server_busy()) {
+    /* Server will not accept any commands. */
+    action_state = CURSOR_ACTION_WAIT;
+    update_unit_info_label(active_units);
+    return;
+  }
+
   if (!ptile) {
     if (hover_tile) {
       /* hover_tile is the tile which is currently under the mouse cursor. */
diff -Nurd -X.diff_ignore freeciv/client/control.h freeciv/client/control.h
--- freeciv/client/control.h	2007-03-05 19:14:36.000000000 +0200
+++ freeciv/client/control.h	2007-08-12 23:26:14.000000000 +0300
@@ -31,7 +31,8 @@
   CURSOR_ACTION_INVALID,
   CURSOR_ACTION_ATTACK,
   CURSOR_ACTION_NUKE,
-  CURSOR_ACTION_PARATROOPER
+  CURSOR_ACTION_PARATROOPER,
+  CURSOR_ACTION_WAIT
 };
 
 /* Selecting unit from a stack without popup. */
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-08-11 12:17:15.000000000 +0300
+++ freeciv/client/packhand.c	2007-08-12 23:09:46.000000000 +0300
@@ -184,7 +184,8 @@
     aconnection.id = conn_id;
     agents_game_joined();
     update_menus();
-    
+
+    set_server_busy(FALSE);
     
     if (get_client_page() == PAGE_MAIN
 	|| get_client_page() == PAGE_NETWORK
@@ -389,8 +390,13 @@
     update_unit_info_label(NULL); 
   }
 
-  if (changed && can_client_change_view()) {
-    update_map_canvas_visible();
+  if (changed) {
+    if (can_client_change_view()) {
+      update_map_canvas_visible();
+    }
+
+    /* If turn was going to change, that is now aborted. */
+    set_server_busy(FALSE);
   }
 }
 
@@ -913,6 +919,30 @@
 }
 
 /**************************************************************************
+  Called when begin-turn packet is received. Server has finished processing
+  turn change.
+**************************************************************************/
+void handle_begin_turn(void)
+{
+  freelog(LOG_DEBUG, "handle_begin_turn()");
+
+  /* Possibly replace wait cursor with something else */
+  set_server_busy(FALSE);
+}
+
+/**************************************************************************
+  Called when end-turn packet is received. Server starts processing turn
+  change.
+**************************************************************************/
+void handle_end_turn(void)
+{
+  freelog(LOG_DEBUG, "handle_end_turn()");
+
+  /* Make sure wait cursor is in use */
+  set_server_busy(TRUE);
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void play_sound_for_event(enum event_type type)
diff -Nurd -X.diff_ignore freeciv/client/tilespec.h freeciv/client/tilespec.h
--- freeciv/client/tilespec.h	2007-08-04 00:29:09.000000000 +0300
+++ freeciv/client/tilespec.h	2007-08-12 23:21:45.000000000 +0300
@@ -154,6 +154,7 @@
   CURSOR_SELECT,
   CURSOR_INVALID,
   CURSOR_ATTACK,
+  CURSOR_WAIT,
   CURSOR_LAST,
   CURSOR_DEFAULT,
 };
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-08-11 12:17:15.000000000 +0300
+++ freeciv/common/packets.def	2007-08-12 23:12:40.000000000 +0300
@@ -242,7 +242,7 @@
   Spaceship
   Ruleset
 
-The last used packet number is 118.
+The last used packet number is 138.
 ****************************************************/
 
 
@@ -999,6 +999,14 @@
 end
 
 # Freeze reports and agents
+PACKET_BEGIN_TURN=137;sc,lsend
+end
+
+# Thaw reports and agents
+PACKET_END_TURN=138;sc,lsend
+end
+
+# Freeze reports and agents
 PACKET_FREEZE_CLIENT=135;sc,lsend
 end
 
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-08-11 21:57:28.000000000 +0300
+++ freeciv/server/srv_main.c	2007-08-12 23:18:53.000000000 +0300
@@ -116,6 +116,8 @@
 
 static void freeze_clients(void);
 static void thaw_clients(void);
+static void send_begin_turn(void);
+static void send_end_turn(void);
 
 /* this is used in strange places, and is 'extern'd where
    needed (hence, it is not 'extern'd in srv_main.h) */
@@ -679,6 +681,13 @@
   game.phase_timer = renew_timer_start(game.phase_timer,
 				       TIMER_USER, TIMER_ACTIVE);
   send_game_info(NULL);
+
+  if (game.info.num_phases == 1) {
+    /* All players in the same phase.
+     * This means that AI has been handled above, and server
+     * will be responsive again */
+    send_begin_turn();
+  }
 }
 
 /**************************************************************************
@@ -763,13 +772,15 @@
   freelog(LOG_DEBUG, "Endturn");
 
   /* Hack: because observer players never get an end-phase packet we send
-   * one here.  It would be better perhaps to have a full end-turn packet. */
+   * one here. */
   conn_list_iterate(game.est_connections, pconn) {
     if (!pconn->player) {
       send_packet_end_phase(pconn);
     }
   } conn_list_iterate_end;
 
+  send_end_turn();
+
   map_calculate_borders();
 
   freelog(LOG_DEBUG, "Season of native unrests");
@@ -1668,6 +1679,30 @@
 }
 
 /**************************************************************************
+  Send PACKET_BEGIN_TURN to all clients capable of handling it.
+**************************************************************************/
+static void send_begin_turn(void)
+{
+  conn_list_iterate(game.est_connections, pconn) {
+    if (has_capability("CF", pconn->capability)) {
+      send_packet_begin_turn(pconn);
+    }
+  } conn_list_iterate_end;
+}
+
+/**************************************************************************
+  Send PACKET_END_TURN to all clients capable of handling it.
+**************************************************************************/
+static void send_end_turn(void)
+{
+  conn_list_iterate(game.est_connections, pconn) {
+    if (has_capability("CF", pconn->capability)) {
+      send_packet_end_turn(pconn);
+    }
+  } conn_list_iterate_end;
+}
+
+/**************************************************************************
 Play the game! Returns when server_state == GAME_OVER_STATE.
 **************************************************************************/
 static void main_loop(void)
@@ -1698,6 +1733,14 @@
      * movement and AI diplomacy). */
     begin_turn(is_new_turn);
 
+    if (game.info.num_phases != 1) {
+      /* We allow everyone to begin adjusting cities and such
+       * from the beginning of the turn.
+       * With simultaneous movement we send begin_turn packet in
+       * begin_phase() only after AI players have finished their actions. */
+      send_begin_turn();
+    }
+
     for (; game.info.phase < game.info.num_phases; game.info.phase++) {
       freelog(LOG_DEBUG, "Starting phase %d/%d.", game.info.phase,
 	      game.info.num_phases);
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in	2007-08-11 12:17:15.000000000 +0300
+++ freeciv/version.in	2007-08-12 23:15:06.000000000 +0300
@@ -26,6 +26,9 @@
 # "ReportFreezeFix" allows clients to correctly freeze reports and agents
 #                   over turn change.
 #
+# "CF"              CursorFix makes sure that wait cursor is in use between
+#                   turns and only between turns.
+#
 #
 #   - No new manditory capabilities can be added to the release branch; doing
 #     so would break network capability of supposedly "compatible" releases.
@@ -33,4 +36,4 @@
 #   - Avoid adding a new manditory 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.
-FREECIV_NETWORK_CAPSTRING(["+2.1c, CitywallFix, PreferedTileset, ReportFreezeFix"])
+FREECIV_NETWORK_CAPSTRING(["+2.1c, CitywallFix, PreferedTileset, ReportFreezeFix CF"])
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to