Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12163) refresh_unit_mapcanvas function
Home

[Freeciv-Dev] (PR#12163) refresh_unit_mapcanvas function

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12163) refresh_unit_mapcanvas function
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 7 Feb 2005 16:22:16 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This simple patch provides a small cleanup.  A new function 
refresh_unit_mapcanvas is provided that is called for updating a unit. 
This handles the settlers citymap when necessary, and in most cases does 
less drawing that refresh_tile_mapcanvas.

It fixes a bug where when settlers are moved the overview isn't updated.

-jason

? fog
? fog.c
? fog.png
? foo
? data/isotrident/grid.png
? data/isotrident/grid.xcf
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.153
diff -u -r1.153 control.c
--- client/control.c    5 Feb 2005 07:41:53 -0000       1.153
+++ client/control.c    8 Feb 2005 00:20:15 -0000
@@ -167,7 +167,7 @@
     auto_center_on_focus_unit();
 
     punit->focus_status=FOCUS_AVAIL;
-    refresh_tile_mapcanvas(punit->tile, FALSE);
+    refresh_unit_mapcanvas(punit, punit->tile, FALSE);
 
     if (unit_has_orders(punit)) {
       /* Clear the focus unit's orders. */
@@ -183,7 +183,7 @@
   /* avoid the old focus unit disappearing: */
   if (punit_old_focus
       && (!punit || !same_pos(punit_old_focus->tile, punit->tile))) {
-    refresh_tile_mapcanvas(punit_old_focus->tile, FALSE);
+    refresh_unit_mapcanvas(punit_old_focus, punit_old_focus->tile, FALSE);
   }
 
   update_unit_info_label(punit);
@@ -412,7 +412,7 @@
       is_shown = !is_shown;
     }
     set_focus_unit_hidden_state(!is_shown);
-    refresh_tile_mapcanvas(punit->tile, TRUE);
+    refresh_unit_mapcanvas(punit, punit->tile, TRUE);
   }
 }
 
@@ -1395,21 +1395,7 @@
   if (punit->transported_by == -1) {
     /* We have to refresh the tile before moving.  This will draw
      * the tile without the unit (because it was unlinked above). */
-    if (unit_type_flag(punit->type, F_CITIES)
-       && punit->client.color != 0) {
-      /* For settlers with an overlay, redraw the entire area of the
-       * overlay. */
-      int width = get_citydlg_canvas_width();
-      int height = get_citydlg_canvas_height();
-      int canvas_x, canvas_y;
-
-      tile_to_canvas_pos(&canvas_x, &canvas_y, ptile);
-      update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
-                       canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
-                       width, height);
-    } else {
-      refresh_tile_mapcanvas(ptile, FALSE);
-    }
+    refresh_unit_mapcanvas(punit, punit->tile, FALSE);
 
     if (do_animation) {
       int dx, dy;
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.178
diff -u -r1.178 mapview_common.c
--- client/mapview_common.c     7 Feb 2005 22:26:21 -0000       1.178
+++ client/mapview_common.c     8 Feb 2005 00:20:16 -0000
@@ -84,6 +84,36 @@
 }
 
 /**************************************************************************
+ Refreshes a single unit on the map canvas.
+**************************************************************************/
+void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile,
+                           bool write_to_screen)
+{
+  if (unit_type_flag(punit->type, F_CITIES)) {
+    int width = get_citydlg_canvas_width();
+    int height = get_citydlg_canvas_height();
+    int canvas_x, canvas_y;
+
+    tile_to_canvas_pos(&canvas_x, &canvas_y, ptile);
+    update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
+                     canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
+                     width, height);
+  } else {
+    int canvas_x, canvas_y;
+
+    if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+      canvas_y += NORMAL_TILE_HEIGHT - UNIT_TILE_HEIGHT;
+      update_map_canvas(canvas_x, canvas_y,
+                       UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
+    } 
+  }
+  if (write_to_screen) {
+    flush_dirty();
+  }
+  overview_update_tile(ptile);
+}
+
+/**************************************************************************
 Returns the color the grid should have between tile (x1,y1) and
 (x2,y2).
 **************************************************************************/
@@ -1813,10 +1843,10 @@
 
     if (myrand(diff0 + diff1) < diff0) {
       punit0->hp--;
-      refresh_tile_mapcanvas(punit0->tile, FALSE);
+      refresh_unit_mapcanvas(punit0, punit0->tile, FALSE);
     } else {
       punit1->hp--;
-      refresh_tile_mapcanvas(punit1->tile, FALSE);
+      refresh_unit_mapcanvas(punit1, punit1->tile, FALSE);
     }
 
     flush_dirty();
@@ -1828,7 +1858,7 @@
   if (num_tiles_explode_unit > 0
       && tile_to_canvas_pos(&canvas_x, &canvas_y,
                           losing_unit->tile)) {
-    refresh_tile_mapcanvas(losing_unit->tile, FALSE);
+    refresh_unit_mapcanvas(losing_unit, losing_unit->tile, FALSE);
     canvas_copy(mapview_canvas.tmp_store, mapview_canvas.store,
                canvas_x, canvas_y, canvas_x, canvas_y,
                NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
@@ -1859,8 +1889,8 @@
   }
 
   set_units_in_combat(NULL, NULL);
-  refresh_tile_mapcanvas(punit0->tile, FALSE);
-  refresh_tile_mapcanvas(punit1->tile, FALSE);
+  refresh_unit_mapcanvas(punit0, punit0->tile, FALSE);
+  refresh_unit_mapcanvas(punit1, punit1->tile, FALSE);
 }
 
 /**************************************************************************
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.88
diff -u -r1.88 mapview_common.h
--- client/mapview_common.h     7 Feb 2005 22:26:21 -0000       1.88
+++ client/mapview_common.h     8 Feb 2005 00:20:16 -0000
@@ -211,6 +211,9 @@
 }
 
 void refresh_tile_mapcanvas(struct tile *ptile, bool write_to_screen);
+void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile,
+                           bool write_to_screen);
+
 enum color_std get_grid_color(const struct tile *ptile, enum direction8 dir);
 
 void map_to_gui_vector(int *gui_dx, int *gui_dy, int map_dx, int map_dy);
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.465
diff -u -r1.465 packhand.c
--- client/packhand.c   7 Feb 2005 22:26:21 -0000       1.465
+++ client/packhand.c   8 Feb 2005 00:20:16 -0000
@@ -296,8 +296,8 @@
        punit1->hp = hp1;
 
        set_units_in_combat(NULL, NULL);
-       refresh_tile_mapcanvas(punit0->tile, FALSE);
-       refresh_tile_mapcanvas(punit1->tile, FALSE);
+       refresh_unit_mapcanvas(punit0, punit0->tile, FALSE);
+       refresh_unit_mapcanvas(punit1, punit1->tile, FALSE);
       }
     }
   }
@@ -1219,18 +1219,7 @@
   }
 
   if (repaint_unit) {
-    if (unit_type_flag(punit->type, F_CITIES)) {
-      int width = get_citydlg_canvas_width();
-      int height = get_citydlg_canvas_height();
-      int canvas_x, canvas_y;
-
-      tile_to_canvas_pos(&canvas_x, &canvas_y, punit->tile);
-      update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
-                       canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
-                       width, height);
-    } else {
-      refresh_tile_mapcanvas(punit->tile, FALSE);
-    }
+    refresh_unit_mapcanvas(punit, punit->tile, FALSE);
   }
 
   if ((check_focus || get_unit_in_focus() == NULL) &&

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12163) refresh_unit_mapcanvas function, Jason Short <=