Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12456) remove DRAWN_BG
Home

[Freeciv-Dev] (PR#12456) remove DRAWN_BG

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12456) remove DRAWN_BG
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 7 Mar 2005 15:46:22 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch simplifies the tilespec interface by removing the DRAWN_BG 
option of the drawn_sprite.  This option (along with DRAWN_GRID which 
was already removed) was basically a hack that tells the drawing 
frontend to draw a certain symbol in place of an actual sprite. 
Removing it means that the interface is simpler and the frontend only 
has to worry about how to draw sprites (and, still, about how to fog them).

The background sprites are now assembled by the backend from the color 
sprites and the tile mask (included in the tileset).  A side effect is 
that the tileset authors have control over the color selection.

Also I fixed some bugs when solid_unit_bg and !draw_terrain were both true.

(Apply the patch, and put colors.png into data/misc/.)

-jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.207
diff -u -r1.207 mapview_common.c
--- client/mapview_common.c     7 Mar 2005 22:53:53 -0000       1.207
+++ client/mapview_common.c     7 Mar 2005 23:41:04 -0000
@@ -868,51 +868,31 @@
   for (i = 0; i < count; i++) {
     int ox, oy, dx, dy;
 
-    switch (pdrawn[i].type) {
-    case DRAWN_SPRITE:
-      if (!pdrawn[i].data.sprite.sprite) {
-       /* This can happen, although it should probably be avoided. */
-       break;
-      }
-      ox = pdrawn[i].data.sprite.offset_x;
-      oy = pdrawn[i].data.sprite.offset_y;
-      if (pdrawn[i].data.sprite.style == DRAW_FULL) {
-       dx = UNIT_TILE_WIDTH - NORMAL_TILE_WIDTH;
-       dy = UNIT_TILE_HEIGHT - NORMAL_TILE_HEIGHT;
-      } else {
-       dx = dy = 0;
-      }
-      if (fog && pdrawn[i].data.sprite.foggable) {
-       canvas_put_sprite_fogged(pcanvas,
-                                canvas_x + ox - dx, canvas_y + oy - dy,
-                                pdrawn[i].data.sprite.sprite,
-                                TRUE,
-                                canvas_x, canvas_y);
-      } else {
-       /* We avoid calling canvas_put_sprite_fogged, even though it
-        * should be a valid thing to do, because gui-gtk-2.0 doesn't have
-        * a full implementation. */
-       canvas_put_sprite_full(pcanvas,
+    if (!pdrawn[i].sprite) {
+      /* This can happen, although it should probably be avoided. */
+      continue;
+    }
+    ox = pdrawn[i].offset_x;
+    oy = pdrawn[i].offset_y;
+    if (pdrawn[i].style == DRAW_FULL) {
+      dx = UNIT_TILE_WIDTH - NORMAL_TILE_WIDTH;
+      dy = UNIT_TILE_HEIGHT - NORMAL_TILE_HEIGHT;
+    } else {
+      dx = dy = 0;
+    }
+    if (fog && pdrawn[i].foggable) {
+      canvas_put_sprite_fogged(pcanvas,
                               canvas_x + ox - dx, canvas_y + oy - dy,
-                              pdrawn[i].data.sprite.sprite);
-      }
-      break;
-    case DRAWN_BG:
-      /*** Background color. ***/
-      if (tileset_is_isometric()) {
-       canvas_fill_sprite_area(pcanvas, sprites.mask.tile,
-                               pdrawn[i].data.bg.color,
-                               canvas_x, canvas_y);
-       if (fog) {
-         canvas_fog_sprite_area(pcanvas, sprites.mask.tile,
-                                canvas_x, canvas_y);
-       }
-      } else {
-       canvas_put_rectangle(pcanvas, pdrawn[i].data.bg.color,
-                            canvas_x, canvas_y,
-                            NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
-      }
-      break;
+                              pdrawn[i].sprite,
+                              TRUE,
+                              canvas_x, canvas_y);
+    } else {
+      /* We avoid calling canvas_put_sprite_fogged, even though it
+       * should be a valid thing to do, because gui-gtk-2.0 doesn't have
+       * a full implementation. */
+      canvas_put_sprite_full(pcanvas,
+                            canvas_x + ox - dx, canvas_y + oy - dy,
+                            pdrawn[i].sprite);
     }
   }
 }
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.260
diff -u -r1.260 tilespec.c
--- client/tilespec.c   7 Mar 2005 22:53:53 -0000       1.260
+++ client/tilespec.c   7 Mar 2005 23:41:05 -0000
@@ -1627,6 +1627,7 @@
     my_snprintf(buffer, sizeof(buffer), "colors.player%d", i);
     SET_SPRITE(colors.player[i], buffer);
   }
+  SET_SPRITE(colors.background, "colors.background");
   sprite_vector_init(&sprites.colors.overlays);
   for (i = 0; ; i++) {
     struct Sprite *sprite;
@@ -1663,6 +1664,16 @@
     sprites.city.unworked_tile_overlay.p[i] = unworked;
   }
 
+  /* Chop up and build the background graphics. */
+  sprites.backgrounds.background
+    = crop_sprite(sprites.colors.background, 0, 0, W, H,
+                 sprites.mask.tile, 0, 0);
+  for (i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
+    sprites.backgrounds.player[i]
+      = crop_sprite(sprites.colors.player[i], 0, 0, W, H,
+                   sprites.mask.tile, 0, 0);
+  }
+
   {
     SET_SPRITE(grid.unavailable, "grid.unavailable");
 
@@ -2221,27 +2232,15 @@
 
 #define ADD_SPRITE(s, draw_style, draw_fog, x_offset, y_offset)                
    \
   (assert(s != NULL),                                                      \
-   sprs->type = DRAWN_SPRITE,                                              \
-   sprs->data.sprite.style = draw_style,                                   \
-   sprs->data.sprite.sprite = s,                                           \
-   sprs->data.sprite.foggable = (draw_fog && t->fogstyle == FOG_AUTO),     \
-   sprs->data.sprite.offset_x = x_offset,                                  \
-   sprs->data.sprite.offset_y = y_offset,                                  \
+   sprs->style = draw_style,                                               \
+   sprs->sprite = s,                                                       \
+   sprs->foggable = (draw_fog && t->fogstyle == FOG_AUTO),                 \
+   sprs->offset_x = x_offset,                                              \
+   sprs->offset_y = y_offset,                                              \
    sprs++)
 #define ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, DRAW_NORMAL, TRUE, 0, 0)
 #define ADD_SPRITE_FULL(s) ADD_SPRITE(s, DRAW_FULL, TRUE, 0, 0)
 
-#define ADD_GRID(ptile, mode)                                              \
-  (sprs->type = DRAWN_GRID,                                                \
-   sprs->data.grid.tile = (ptile),                                         \
-   sprs->data.grid.citymode = (mode),                                      \
-   sprs++)
-
-#define ADD_BG(bg_color)                                                   \
-  (sprs->type = DRAWN_BG,                                                  \
-   sprs->data.bg.color = (bg_color),                                       \
-   sprs++)
-
 /**************************************************************************
   Assemble some data that is used in building the tile sprite arrays.
     (map_x, map_y) : the (normalized) map position
@@ -3200,6 +3199,7 @@
   int tileno, dir;
   struct unit *pfocus = get_unit_in_focus();
   struct drawn_sprite *save_sprs = sprs;
+  struct player *owner = NULL;
 
   /* Unit drawing is disabled if the view options is turned off, but only
    * if we're drawing on the mapview. */
@@ -3244,20 +3244,18 @@
 
   switch (layer) {
   case LAYER_BACKGROUND:
-    if (ptile && tile_get_known(ptile) == TILE_UNKNOWN) {
-      ADD_BG(COLOR_STD_BLACK);
-      return sprs - save_sprs;
-    }
-
     /* Set up background color. */
     if (solid_color_behind_units) {
       if (do_draw_unit) {
-       ADD_BG(player_color(unit_owner(punit)));
+       owner = unit_owner(punit);
       } else if (pcity && draw_cities) {
-       ADD_BG(player_color(city_owner(pcity)));
+       owner = city_owner(pcity);
       }
+    }
+    if (owner) {
+      ADD_SPRITE_SIMPLE(sprites.backgrounds.player[owner->player_no]);
     } else if (ptile && !draw_terrain) {
-      ADD_BG(COLOR_STD_BACKGROUND);
+      ADD_SPRITE_SIMPLE(sprites.backgrounds.background);
     }
     break;
 
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.123
diff -u -r1.123 tilespec.h
--- client/tilespec.h   7 Mar 2005 22:53:53 -0000       1.123
+++ client/tilespec.h   7 Mar 2005 23:41:05 -0000
@@ -49,27 +49,14 @@
 
 struct drawn_sprite {
   enum {
-    DRAWN_SPRITE,      /* Draw a sprite. */
-    DRAWN_BG            /* Draw a solid BG. */
-  } type;
-
-  union {
-    struct {
-      enum {
-       /* Only applicable in iso-view.  "Full" sprites overlap into the top
-        * half-tile of UNIT_TILE_HEIGHT. */
-       DRAW_NORMAL,
-       DRAW_FULL
-      } style;
-      bool foggable;   /* Set to FALSE for sprites that are never fogged. */
-      struct Sprite *sprite;
-      int offset_x, offset_y;  /* offset from tile origin */
-    } sprite;
-
-    struct {
-      enum color_std color;
-    } bg;
-  } data;
+    /* Only applicable in iso-view.  "Full" sprites overlap into the top
+     * half-tile of UNIT_TILE_HEIGHT. */
+    DRAW_NORMAL,
+    DRAW_FULL
+  } style;
+  bool foggable;       /* Set to FALSE for sprites that are never fogged. */
+  struct Sprite *sprite;
+  int offset_x, offset_y;      /* offset from tile origin */
 };
 
 /* Items on the mapview are drawn in layers.  Each entry below represents
@@ -359,8 +346,12 @@
       *player_borders[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS][EDGE_COUNT][2];
   } grid;
   struct {
+    struct Sprite *player[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
+    struct Sprite *background; /* Generic background */
+  } backgrounds;
+  struct {
     struct sprite_vector overlays;
-
+    struct Sprite *background; /* Generic background color */
     struct Sprite *player[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
   } colors;
 
Index: data/misc/colors.png
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/misc/colors.png,v
retrieving revision 1.1
diff -u -r1.1 colors.png
Binary files /tmp/cvs3JLYi8 and colors.png differ
Index: data/misc/colors.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/misc/colors.spec,v
retrieving revision 1.1
diff -u -r1.1 colors.spec
--- data/misc/colors.spec       25 Feb 2005 17:31:50 -0000      1.1
+++ data/misc/colors.spec       7 Mar 2005 23:41:05 -0000
@@ -57,4 +57,6 @@
   0, 1, "colors.player29"
   0, 2, "colors.player30"
   0, 3, "colors.player31"
+
+  3, 2, "colors.background"
 }

PNG image


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12456) remove DRAWN_BG, Jason Short <=