Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] [PATCH] message window -- related to (PR#902)
Home

[Freeciv-Dev] [PATCH] message window -- related to (PR#902)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] message window -- related to (PR#902)
From: Francois Taiani <francois.taiani@xxxxxxxx>
Date: Sat, 25 Aug 2001 15:37:08 -0700 (PDT)

Hi,

I have a rather small screen, and I had some troubles with the message
window splashing in front of the main window each time the AI made its
turn. I'm playing with sounds (many thanks to David Weisgerber :) and
with "auto center on combat" both turned on. The message window was
hiding me what was actually going on, and I could only heard that my
units where fighting bravely. :-(

The joined patch changes this in that it delays the popup of the message
window untill the server has finished moving the AI. 

Below are further technical details.

The patch is not big, but touches several files. I can split it in 2
(PACKET_START_SNIFFING / messwin popup) if it is useful to someone, but
before I wanted to have your feedback on the new GUI behavior (which
*greatly* improve the ergonomics of the client on a small screen, I can
tell you ;-)

Francois

P.S.: The patch is againt cvs-25-Aug, but it should works on previous
cvs versions as well.

--------------------
TECHNICAL DETAILS:

Because the client has actually no ways to tell that the server has
started sniffing for packets (and hence that that the AI is done), I've
added a new packet type PACKET_START_SNIFFING (with the corresponding
functins send_packet_start_sniffing(..)
receive_packet_start_sniffing(..) lsend_packet_start_sniffing() ). In
its main loop the server now calls notify_clients_ready_sniffing(void)
just before it starts sniffing for client packets, which causes such a
packet to be sent.

The clients react to a PACKET_START_SNIFFING by calling back
handle_start_sniffing(). handle_start_sniffing() is now responsible for
the pop up of the message window, instead of handle_new_year(..).

Because I was not quite satisfied with the placement of the message
window, I also modified the way it is put on the screen. Before, the
message window could be in 2 states: Created or Destroyed (depending on
meswin_dialog_shell being null or not). Consequently, each time I would
close the window, it would "splash up" again in the middle of my map,
and prevent me from seing anything.

With the patch, the message window can be Visible (i.e. Created and
visible on the screen), Hidden or Destroyed. I've change the close
button so that it just hides the window without destroying it.
Admitedly, hiding has its memory cost, but this window keeps being
created again and again anyway. With a hidden state, it's possible to
pop up the message window at the same position it stood before the user
closed it, which give the user more controlability on its interface.

So now the behavior is that the window never pops up before the AI is
done, and when it pops up, one of the 3 following cases occurs: 

a) If the window did not exist, it is created in the same way as before,
and put in the middle of the map (well 25 %). 

b) If it was hidden, it is made visible again (same pop up effect) but
at the *same* place it had when the user closed it. 

c) If it was already visible (possibly behind another window - sic), it
is simply updated, as before. (But now F10 actully brings it in the
foreground again, which was not the case before.)
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/client/civclient.c 
./client/civclient.c
--- ../freeciv-cvs-Aug-25/client/civclient.c    Wed Apr 25 13:34:41 2001
+++ ./client/civclient.c        Sat Aug 25 23:13:37 2001
@@ -375,6 +375,10 @@
     send_packet_generic_empty(&aconnection, PACKET_CONN_PONG);
     break;
 
+  case PACKET_START_SNIFFING:
+    handle_start_sniffing();
+    break;
+
   default:
     freelog(LOG_ERROR, "Received unknown packet (type %d) from server!", type);
     /* Old clients (<= some 1.11.5-devel, capstr +1.11) used to exit()
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/client/gui-gtk/messagewin.c 
./client/gui-gtk/messagewin.c
--- ../freeciv-cvs-Aug-25/client/gui-gtk/messagewin.c   Tue Jan 30 13:59:51 2001
+++ ./client/gui-gtk/messagewin.c       Sat Aug 25 23:13:37 2001
@@ -55,6 +55,7 @@
 void meswin_list_ucallback(GtkWidget *w, gint row, gint column);
 void meswin_goto_callback(GtkWidget *w, gpointer data);
 void meswin_popcity_callback(GtkWidget *w, gpointer data);
+void meswin_hide_callback(GtkWidget *w, gpointer data);
 
 #define N_MSG_VIEW 24         /* max before scrolling happens */
 
@@ -169,7 +170,7 @@
                GTK_SIGNAL_FUNC(meswin_list_ucallback), NULL);
 
   gtk_signal_connect(GTK_OBJECT(meswin_close_command), "clicked",
-               GTK_SIGNAL_FUNC(meswin_close_callback), NULL);
+               GTK_SIGNAL_FUNC(meswin_hide_callback), NULL);
   gtk_signal_connect(GTK_OBJECT(meswin_goto_command), "clicked",
                GTK_SIGNAL_FUNC(meswin_goto_callback), NULL);
   gtk_signal_connect(GTK_OBJECT(meswin_popcity_command), "clicked",
@@ -354,6 +355,22 @@
 /**************************************************************************
 ...
 **************************************************************************/
+void popup_meswin_if_not_visible() 
+{
+   if(meswin_dialog_shell) {
+
+     /* If the meswin_dialog_shell already exists but has been
+        hidden previously by gdk_window_hide, we pop up it again.
+      */
+     if (meswin_dialog_shell->window)
+       if (!gdk_window_is_visible (meswin_dialog_shell->window))
+         gdk_window_show(meswin_dialog_shell->window) ;
+   }
+}
+
+/**************************************************************************
+...
+**************************************************************************/
 void meswin_list_callback (GtkWidget *w, gint row, gint column, GdkEvent *ev)
 {
   struct city *pcity;
@@ -412,6 +429,14 @@
 {
   gtk_widget_set_sensitive(meswin_goto_command, FALSE);
   gtk_widget_set_sensitive(meswin_popcity_command, FALSE);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void meswin_hide_callback(GtkWidget *w, gpointer data)
+{
+  gdk_window_hide(meswin_dialog_shell->window);
 }
 
 /**************************************************************************
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/client/include/messagewin_g.h 
./client/include/messagewin_g.h
--- ../freeciv-cvs-Aug-25/client/include/messagewin_g.h Tue Jul 20 13:43:20 1999
+++ ./client/include/messagewin_g.h     Sat Aug 25 23:13:37 2001
@@ -22,5 +22,6 @@
 
 void meswin_update_delay_on(void);
 void meswin_update_delay_off(void);
+void popup_meswin_if_not_visible();
      
 #endif  /* FC__MESSAGEWIN_G_H */
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/client/packhand.c 
./client/packhand.c
--- ../freeciv-cvs-Aug-25/client/packhand.c     Sat Aug 25 23:09:05 2001
+++ ./client/packhand.c Sat Aug 25 23:17:27 2001
@@ -632,9 +632,6 @@
   report_update_delay_off();
   update_report_dialogs();
 
-  meswin_update_delay_off();
-  update_meswin_dialog();
-
   update_city_descriptions();
 
   if(game.player_ptr->ai.control && !ai_manual_turn_done)
@@ -643,6 +640,17 @@
   if(sound_bell_at_new_turn &&
      (!game.player_ptr->ai.control || ai_manual_turn_done))
     sound_bell();
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void handle_start_sniffing(void)
+{
+  freelog(LOG_VERBOSE,"Handling START_SNIFFING packet.") ;
+  meswin_update_delay_off();
+  update_meswin_dialog();
+  popup_meswin_if_not_visible() ;
 }
 
 /**************************************************************************
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/client/packhand.h 
./client/packhand.h
--- ../freeciv-cvs-Aug-25/client/packhand.h     Sun Aug 27 13:29:07 2000
+++ ./client/packhand.h Sat Aug 25 23:13:37 2001
@@ -58,5 +58,6 @@
 void handle_ruleset_game(struct packet_ruleset_game *packet);
 void handle_diplomat_action(struct packet_diplomat_action *packet);
 void handle_sabotage_list(struct packet_sabotage_list *packet);
+void handle_start_sniffing(void);
 
 #endif /* FC__PACKHAND_H */
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/common/packets.c 
./common/packets.c
--- ../freeciv-cvs-Aug-25/common/packets.c      Sat Aug 25 23:09:21 2001
+++ ./common/packets.c  Sat Aug 25 23:13:37 2001
@@ -233,6 +233,7 @@
   case PACKET_CONN_PING:
   case PACKET_CONN_PONG:
   case PACKET_BEFORE_NEW_YEAR:
+  case PACKET_START_SNIFFING:
     return receive_packet_generic_empty(pc);
 
   case PACKET_NEW_YEAR:
@@ -1974,6 +1975,11 @@
   cptr=put_uint32(cptr, request->year);
   put_uint16(buffer, cptr-buffer);
   return send_connection_data(pc, buffer, cptr-buffer);
+}
+
+int send_packet_start_sniffing(struct connection *pc)
+{
+  return send_packet_generic_empty(pc, PACKET_START_SNIFFING);
 }
 
 /**************************************************************************
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/common/packets.h 
./common/packets.h
--- ../freeciv-cvs-Aug-25/common/packets.h      Sat Jun 30 13:37:56 2001
+++ ./common/packets.h  Sat Aug 25 23:13:37 2001
@@ -118,6 +118,8 @@
   PACKET_CONN_PING,
   PACKET_CONN_PONG,
   PACKET_UNIT_AIRLIFT,
+  PACKET_START_SNIFFING, /* Is sent when the server located ai has moved,
+                            so that the clients update their message window */
   PACKET_LAST  /* leave this last */
 };
 
@@ -1062,6 +1064,9 @@
                            const struct packet_goto_route *packet,
                           enum goto_route_type type);
 struct packet_goto_route *receive_packet_goto_route(struct connection *pc);
+
+int     send_packet_start_sniffing (struct connection *pc);
+void receive_packet_start_sniffing (struct connection *pc);
 
 int send_packet_generic_empty(struct connection *pc, int type);
 struct packet_generic_empty *
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/common/packets_lsend.c 
./common/packets_lsend.c
--- ../freeciv-cvs-Aug-25/common/packets_lsend.c        Tue Feb 20 13:35:34 2001
+++ ./common/packets_lsend.c    Sat Aug 25 23:13:37 2001
@@ -105,6 +105,13 @@
   conn_list_iterate_end;
 }
 
+void lsend_packet_start_sniffing(struct conn_list *dest)
+{
+  conn_list_iterate(*dest, pconn)
+    send_packet_start_sniffing(pconn);
+  conn_list_iterate_end;
+}
+
 void lsend_packet_move_unit(struct conn_list *dest, 
                          const struct packet_move_unit *request)
 {
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/common/packets_lsend.h 
./common/packets_lsend.h
--- ../freeciv-cvs-Aug-25/common/packets_lsend.h        Tue Feb 20 13:35:34 2001
+++ ./common/packets_lsend.h    Sat Aug 25 23:13:37 2001
@@ -101,4 +101,7 @@
 void lsend_packet_goto_route(struct conn_list *dest,
                            const struct packet_goto_route *packet,
                           enum goto_route_type type);
+
+void lsend_packet_start_sniffing(struct conn_list *dest);
+
 void lsend_packet_generic_empty(struct conn_list *dest, int type);
diff -ruBwX diff_ignore ../freeciv-cvs-Aug-25/server/srv_main.c 
./server/srv_main.c
--- ../freeciv-cvs-Aug-25/server/srv_main.c     Thu Aug 23 14:01:45 2001
+++ ./server/srv_main.c Sat Aug 25 23:13:37 2001
@@ -114,6 +114,7 @@
 static void handle_turn_done(struct player *pplayer);
 static void send_select_nation(struct player *pplayer);
 static int check_for_full_turn_done(void);
+static void notify_clients_ready_sniffing(void);
 
 
 /* this is used in strange places, and is 'extern'd where
@@ -367,6 +368,17 @@
 }
 
 /**************************************************************************
+Notifies clients that the server is now ready to sniffing, so they'll
+be able to play. This may useful to only pop up windows at that
+very moment, and not earlier.
+**************************************************************************/
+static void notify_clients_ready_sniffing(void) 
+{
+  lsend_packet_start_sniffing(&game.est_connections);
+}
+
+
+/**************************************************************************
 Handle the beginning of each turn.
 Note: This does not give "time" to any player;
       it is solely for updating turn-dependent data.
@@ -1693,6 +1705,7 @@
     save_counter++;
     
     freelog(LOG_DEBUG, "sniffingpackets");
+    notify_clients_ready_sniffing();
     while(sniff_packets()==1);
 
     /* After sniff, re-zero the timer: (read-out above on next loop) */

[Prev in Thread] Current Thread [Next in Thread]