Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] Re: (PR#8477) tilespec.c no_backdrop variable does nothing
Home

[Freeciv-Dev] Re: (PR#8477) tilespec.c no_backdrop variable does nothing

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8477) tilespec.c no_backdrop variable does nothing
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 9 Apr 2004 21:24:15 -0700
Reply-to: rt@xxxxxxxxxxx

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

Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8477 >
> 
> The no_backdrop variable in tilespec.c is entirely useless.
> 
> Perhaps it did something at some point in the past.  But I have no idea 
> what.

OK, I take it back.  This value used to do something but was later 
broken.  The intent is that when you draw a unit on _top_ of a city, you 
shouldn't redraw the background.  This background is either the flag or 
(in non-iso view with the solid background option set) a solid background.

However it is misused.  It is only set for units in non-iso tilesets, 
but it is checked for cities and iso tilesets as well.  (There's also a 
bug causing it not to work for non-iso tilesets; easily fixed.)

This patch fixes both the logic and the behavior.

Logic:

- The global no_backdrop value is removed.  Backdrops are always drawn 
for cities (as they were anyway).

- Now the backdrop value is given as a parameter to fill_unit_sprite_array.

- One user, put_unit, must also take "stack" and "backdrop" parameters.

- The stack parameter is only used for stacks.  Occupied ships are 
checked independently within fill_unit_sprite_array.  This is a subtle 
difference but it makes things simpler.

Behavior: now when a unit is drawn on top of a city:

- The background isn't drawn over the city.  This means you'll still see 
the city and the flag behind it rather than the flag in front of the city.

- The stack icon is drawn for stacks in cities (this was always done in 
non-iso view but not in iso-view for some reason).

As a side note, I don't know why the veteran icon isn't drawn for a 
stacked unit.  This seems quite wrong.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.98
diff -u -r1.98 mapview_common.c
--- client/mapview_common.c     29 Mar 2004 19:17:06 -0000      1.98
+++ client/mapview_common.c     10 Apr 2004 04:20:28 -0000
@@ -622,14 +622,16 @@
   in iso-view to draw only part of the tile.  Non-iso view should use
   put_unit_full instead.
 **************************************************************************/
-void put_unit(struct unit *punit, struct canvas *pcanvas,
+void put_unit(struct unit *punit, bool stacked, bool backdrop,
+             struct canvas *pcanvas,
              int canvas_x, int canvas_y,
              int unit_offset_x, int unit_offset_y,
              int unit_width, int unit_height)
 {
   struct drawn_sprite drawn_sprites[40];
   bool solid_bg;
-  int count = fill_unit_sprite_array(drawn_sprites, punit, &solid_bg, FALSE);
+  int count = fill_unit_sprite_array(drawn_sprites, punit, &solid_bg,
+                                    stacked, backdrop);
   int i;
 
   if (!is_isometric && solid_bg) {
@@ -663,7 +665,7 @@
 void put_unit_full(struct unit *punit, struct canvas *pcanvas,
                   int canvas_x, int canvas_y)
 {
-  put_unit(punit, pcanvas, canvas_x, canvas_y,
+  put_unit(punit, FALSE, TRUE, pcanvas, canvas_x, canvas_y,
           0, 0, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
 }
 
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.53
diff -u -r1.53 mapview_common.h
--- client/mapview_common.h     29 Mar 2004 19:17:06 -0000      1.53
+++ client/mapview_common.h     10 Apr 2004 04:20:28 -0000
@@ -159,7 +159,8 @@
 bool tile_visible_mapcanvas(int map_x, int map_y);
 bool tile_visible_and_not_on_border_mapcanvas(int map_x, int map_y);
 
-void put_unit(struct unit *punit, struct canvas *pcanvas,
+void put_unit(struct unit *punit, bool stacked, bool backdrop,
+             struct canvas *pcanvas,
              int canvas_x, int canvas_y,
              int unit_offset_x, int unit_offset_y,
              int unit_width, int unit_height);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.156
diff -u -r1.156 tilespec.c
--- client/tilespec.c   1 Apr 2004 23:11:23 -0000       1.156
+++ client/tilespec.c   10 Apr 2004 04:20:28 -0000
@@ -186,11 +186,6 @@
 */
 static bool focus_unit_hidden = FALSE;
 
-/*
-  If no_backdrop is true, then no color/flag is drawn behind the city/unit.
-*/
-static bool no_backdrop = FALSE;
-
 /**********************************************************************
   Returns a static list of tilesets available on the system by
   searching all data directories for files matching TILESPEC_SUFFIX.
@@ -1456,13 +1451,12 @@
   struct drawn_sprite *save_sprs = sprs;
 
   *solid_bg = FALSE;
-  if (!no_backdrop) {
-    if(!solid_color_behind_units) {
-      ADD_SPRITE(get_city_nation_flag_sprite(pcity),
-                flag_offset_x, flag_offset_y);
-    } else {
-      *solid_bg = TRUE;
-    }
+
+  if (!solid_color_behind_units) {
+    ADD_SPRITE(get_city_nation_flag_sprite(pcity),
+              flag_offset_x, flag_offset_y);
+  } else {
+    *solid_bg = TRUE;
   }
 
   if (pcity->client.occupied) {
@@ -1512,10 +1506,8 @@
 {
   struct drawn_sprite *save_sprs = sprs;
 
-  if (!no_backdrop) {
-    ADD_SPRITE(get_city_nation_flag_sprite(pcity),
-              flag_offset_x, flag_offset_y);
-  }
+  ADD_SPRITE(get_city_nation_flag_sprite(pcity),
+            flag_offset_x, flag_offset_y);
 
   if (pcity->client.occupied) {
     ADD_SPRITE_SIMPLE(get_city_occupied_sprite(pcity));
@@ -1571,19 +1563,19 @@
   Fill in the sprite array for the unit
 ***********************************************************************/
 int fill_unit_sprite_array(struct drawn_sprite *sprs, struct unit *punit,
-                          bool *solid_bg, bool stack)
+                          bool *solid_bg, bool stack, bool backdrop)
 {
   struct drawn_sprite *save_sprs = sprs;
   int ihp;
   *solid_bg = FALSE;
 
   if (is_isometric) {
-    if (!no_backdrop) {
+    if (backdrop) {
       ADD_SPRITE(get_unit_nation_flag_sprite(punit),
                 flag_offset_x, flag_offset_y);
     }
   } else {
-    if (!no_backdrop) {
+    if (backdrop) {
       if (!solid_color_behind_units) {
        ADD_SPRITE(get_unit_nation_flag_sprite(punit),
                   flag_offset_x, flag_offset_y);
@@ -1668,7 +1660,7 @@
     }
   }
 
-  if (stack) {
+  if (stack || punit->occupy) {
     ADD_SPRITE_SIMPLE(sprites.unit.stack);
   } else {
     ADD_SPRITE_SIMPLE(sprites.unit.vet_lev[punit->veteran]);
@@ -2303,12 +2295,11 @@
   if (solid_color_behind_units) {
     punit = get_drawable_unit(abs_x0, abs_y0, citymode);
     if (punit && (draw_units || (draw_focus_unit && pfocus == punit))) {
-      if (unit_list_size(&ptile->units) > 1
-         || unit_list_get(&ptile->units, 0)->occupy) {
-        sprs += fill_unit_sprite_array(sprs, punit, solid_bg, TRUE);
-      } else {
-        sprs += fill_unit_sprite_array(sprs, punit, solid_bg, FALSE);
-      }
+      bool stacked = (unit_list_size(&ptile->units) > 1);
+
+      sprs += fill_unit_sprite_array(sprs, punit, solid_bg,
+                                    stacked, TRUE);
+
       *pplayer = unit_owner(punit);
       return sprs - save_sprs;
     }
@@ -2396,15 +2387,11 @@
          (draw_units || (draw_focus_unit && !focus_unit_hidden
                          && punit == pfocus))) {
        bool dummy;
+       bool stacked = (unit_list_size(&ptile->units) > 1);
+       bool backdrop = !pcity;
 
-       no_backdrop = (pcity != NULL);
-       no_backdrop = FALSE;
-       if (unit_list_size(&ptile->units) > 1
-           || unit_list_get(&ptile->units, 0)->occupy) {
-          sprs += fill_unit_sprite_array(sprs, punit, &dummy, TRUE);
-       } else {
-          sprs += fill_unit_sprite_array(sprs, punit, &dummy, FALSE);
-        }
+       sprs += fill_unit_sprite_array(sprs, punit, &dummy,
+                                      stacked, backdrop);
       }
     }
   }
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.59
diff -u -r1.59 tilespec.h
--- client/tilespec.h   30 Mar 2004 19:07:32 -0000      1.59
+++ client/tilespec.h   10 Apr 2004 04:20:28 -0000
@@ -57,8 +57,8 @@
 int fill_tile_sprite_array(struct drawn_sprite *sprs, int abs_x0, int abs_y0,
                           bool citymode, bool *solid_bg,
                           struct player **pplayer);
-int fill_unit_sprite_array(struct drawn_sprite *sprs,
-                          struct unit *punit, bool *solid_bg, bool stack);
+int fill_unit_sprite_array(struct drawn_sprite *sprs, struct unit *punit,
+                          bool *solid_bg, bool stack, bool backdrop);
 int fill_city_sprite_array_iso(struct drawn_sprite *sprs,
                               struct city *pcity);
 
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.211
diff -u -r1.211 mapview.c
--- client/gui-gtk/mapview.c    30 Mar 2004 02:01:27 -0000      1.211
+++ client/gui-gtk/mapview.c    10 Apr 2004 04:20:28 -0000
@@ -1185,16 +1185,13 @@
 
   /*** Unit ***/
   if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
-    put_unit(punit, &canvas_store,
+    bool stacked = (unit_list_size(&map_get_tile(x, y)->units) > 1);
+    bool backdrop = !pcity;
+
+    put_unit(punit, stacked, backdrop, &canvas_store,
             canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
             offset_x, offset_y_unit,
             width, height_unit);
-    if (!pcity && unit_list_size(&map_get_tile(x, y)->units) > 1)
-      pixmap_put_overlay_tile_draw(pm,
-                                  canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                  sprites.unit.stack,
-                                  offset_x, offset_y_unit,
-                                  width, height_unit, fog);
   }
 
   if (contains_special(special, S_FORTRESS) && draw_fortress_airbase)
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.115
diff -u -r1.115 mapview.c
--- client/gui-gtk-2.0/mapview.c        4 Apr 2004 14:22:12 -0000       1.115
+++ client/gui-gtk-2.0/mapview.c        10 Apr 2004 04:20:28 -0000
@@ -1297,16 +1297,13 @@
 
   /*** Unit ***/
   if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
+    bool stacked = (unit_list_size(&map_get_tile(x, y)->units) > 1);
+    bool backdrop = !pcity;
+
     put_unit(punit, &canvas_store,
             canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
             offset_x, offset_y_unit,
             width, height_unit);
-    if (!pcity && unit_list_size(&map_get_tile(x, y)->units) > 1)
-      pixmap_put_overlay_tile_draw(pm,
-                                  canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                  sprites.unit.stack,
-                                  offset_x, offset_y_unit,
-                                  width, height_unit, fog);
   }
 
   if (contains_special(special, S_FORTRESS) && draw_fortress_airbase)
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.107
diff -u -r1.107 mapview.c
--- client/gui-win32/mapview.c  25 Mar 2004 23:29:08 -0000      1.107
+++ client/gui-win32/mapview.c  10 Apr 2004 04:20:28 -0000
@@ -1090,16 +1090,13 @@
 
     /*** Unit ***/
   if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
+    bool stacked = (unit_list_size(&map_get_tile(x, y)->units) > 1);
+    bool backdrop = !pcity;
+
     put_unit(punit, &canvas_store,
              canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
              offset_x, offset_y_unit,
              width, height_unit);
-    if (!pcity && unit_list_size(&map_get_tile(x, y)->units) > 1)
-      pixmap_put_overlay_tile_draw(hdc,
-                                   canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                   sprites.unit.stack,
-                                   offset_x, offset_y_unit,
-                                   width, height_unit, fog);
   }
   
   if (contains_special(special, S_FORTRESS) && draw_fortress_airbase)

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