Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8756) new function update_city_description
Home

[Freeciv-Dev] (PR#8756) new function update_city_description

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8756) new function update_city_description
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 17 May 2004 01:03:57 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8756 >

This patch adds a new function, update_city_description().  This updates 
a single description for a single city.

This wasn't possible in the past because we didn't know what area needed 
to be updated, nor was there a means of updating just that area. 
However now this function can simply be a wrapper for update_map_canvas.

I moved the two calls to update_city_description into 
handle_city_packet_common.  This is obvious enough.  Also I removed the 
check for visible tiles, which shouldn't apply here.  If the area isn't 
visible nothing will be drawn and very little time will be used.

However city_packet_common function has some duplicated drawing.  It 
redraws the city, redraws the city area (sometimes), and also redraws 
the city description.  Merging these redraws may be a little tricky.

There's also another potential problem case.  Because the city 
description dimensions are calculated on demand, if the text overflows 
this bounds the extra area may not be updated properly.  This won't be 
corrected until the next redraw (after which it won't recur because the 
dimensions will have been increased).  This could be solved by doing an 
extra redraw when the city dimensions increase.

jason

? eff
? flags
? data/flags
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.117
diff -u -r1.117 mapview_common.c
--- client/mapview_common.c     17 May 2004 07:16:42 -0000      1.117
+++ client/mapview_common.c     17 May 2004 07:58:15 -0000
@@ -1364,13 +1364,37 @@
   update_map_canvas(0, 0, mapview_canvas.width, mapview_canvas.height);
 }
 
+/* The maximum city description width and height.  This gives the dimensions
+ * of a rectangle centered directly beneath the tile a city is on, that
+ * contains the city description.
+ *
+ * These values are increased when drawing is done.  This may mean that
+ * the change (from increasing the value) won't take place until the
+ * next redraw. */
+static int max_desc_width = 0, max_desc_height = 0;
+
+/**************************************************************************
+  Update the city description for the given city.
+**************************************************************************/
+void update_city_description(struct city *pcity)
+{
+  int canvas_x, canvas_y;
+
+  /* We update the entire map canvas area that this city description
+   * might be covering.  This may, for instance, redraw other city
+   * descriptions that overlap with this one. */
+  (void) map_to_canvas_pos(&canvas_x, &canvas_y, pcity->x, pcity->y);
+  update_map_canvas(canvas_x - (max_desc_width - NORMAL_TILE_WIDTH) / 2,
+                   canvas_y + NORMAL_TILE_HEIGHT,
+                   max_desc_width, max_desc_height);
+}
+
 /**************************************************************************
   Show descriptions for all cities visible on the map canvas.
 **************************************************************************/
 void show_city_descriptions(int canvas_x, int canvas_y,
                            int width, int height)
 {
-  static int max_desc_width = 0, max_desc_height = 0;
   const int dx = max_desc_width - NORMAL_TILE_WIDTH, dy = max_desc_height;
 
   if (!draw_city_names && !draw_city_productions) {
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.62
diff -u -r1.62 mapview_common.h
--- client/mapview_common.h     14 May 2004 02:23:42 -0000      1.62
+++ client/mapview_common.h     17 May 2004 07:58:16 -0000
@@ -270,6 +270,7 @@
 
 void update_map_canvas(int canvas_x, int canvas_y, int width, int height);
 void update_map_canvas_visible(void);
+void update_city_description(struct city *pcity);
 
 void show_city_descriptions(int canvas_x, int canvas_y,
                            int width, int height);
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.365
diff -u -r1.365 packhand.c
--- client/packhand.c   15 May 2004 16:33:42 -0000      1.365
+++ client/packhand.c   17 May 2004 07:58:16 -0000
@@ -422,14 +422,6 @@
     assert(pcity->id == packet->id);
   }
   
-  /* Update the descriptions if necessary.  We only draw the description
-   * if the *city* is visible on the mapview, which is a bit inaccurate -
-   * it's possible the city is off the mapview but the description is
-   * visible.  See all show_city_descriptions(). */
-  if (update_descriptions && tile_visible_mapcanvas(packet->x, packet->y)) {
-    queue_mapview_update(UPDATE_CITY_DESCRIPTIONS);
-  }
-
   pcity->owner=packet->owner;
   pcity->x=packet->x;
   pcity->y=packet->y;
@@ -627,6 +619,12 @@
   }
 
   reset_move_costs(pcity->x, pcity->y);
+
+  /* update the descriptions if necessary */
+  /* TODO: this should be merged with the updates done above. */
+  if (update_descriptions) {
+    update_city_description(pcity);
+  }
 }
 
 /**************************************************************************
@@ -751,11 +749,6 @@
 
   handle_city_packet_common(pcity, city_is_new, FALSE, FALSE);
 
-  /* update the descriptions if necessary */
-  if (update_descriptions && tile_visible_mapcanvas(pcity->x,pcity->y)) {
-    queue_mapview_update(UPDATE_CITY_DESCRIPTIONS);
-  }
-
   try_update_effects(need_effect_update);
 }
 

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