Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12468) remove draw_style from the drawn_sprite struct
Home

[Freeciv-Dev] (PR#12468) remove draw_style from the drawn_sprite struct

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12468) remove draw_style from the drawn_sprite struct
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 Mar 2005 11:33:40 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch removes the DRAW_FULL/DRAW_NORMAL "style" field from the 
drawn sprite.  This simplifies the interface and the mapview_common 
code.  Instead the extra data is just added in to the offset values.

-jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.208
diff -u -r1.208 mapview_common.c
--- client/mapview_common.c     9 Mar 2005 18:12:33 -0000       1.208
+++ client/mapview_common.c     9 Mar 2005 19:05:20 -0000
@@ -866,23 +866,14 @@
   int i;
 
   for (i = 0; i < count; i++) {
-    int ox, oy, dx, dy;
-
     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,
+                              canvas_x + pdrawn[i].offset_x,
+                              canvas_y + pdrawn[i].offset_y,
                               pdrawn[i].sprite,
                               TRUE,
                               canvas_x, canvas_y);
@@ -891,7 +882,8 @@
        * 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,
+                            canvas_x + pdrawn[i].offset_x,
+                            canvas_y + pdrawn[i].offset_y,
                             pdrawn[i].sprite);
     }
   }
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.261
diff -u -r1.261 tilespec.c
--- client/tilespec.c   9 Mar 2005 18:12:34 -0000       1.261
+++ client/tilespec.c   9 Mar 2005 19:05:21 -0000
@@ -2230,16 +2230,19 @@
   return sprites.city.tile[style][city_styles[style].tiles_num+1];
 }
 
-#define ADD_SPRITE(s, draw_style, draw_fog, x_offset, y_offset)                
    \
+#define FULL_TILE_X_OFFSET ((NORMAL_TILE_WIDTH - UNIT_TILE_WIDTH) / 2)
+#define FULL_TILE_Y_OFFSET (NORMAL_TILE_HEIGHT - UNIT_TILE_HEIGHT)
+
+#define ADD_SPRITE(s, draw_fog, x_offset, y_offset)                        \
   (assert(s != NULL),                                                      \
-   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_SPRITE_SIMPLE(s) ADD_SPRITE(s, TRUE, 0, 0)
+#define ADD_SPRITE_FULL(s)                                                 \
+  ADD_SPRITE(s, TRUE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)
 
 /**************************************************************************
   Assemble some data that is used in building the tile sprite arrays.
@@ -2290,15 +2293,17 @@
 
   if (backdrop) {
     if (!solid_color_behind_units) {
-      ADD_SPRITE(get_unit_nation_flag_sprite(punit),
-                DRAW_FULL, TRUE, t->flag_offset_x, t->flag_offset_y);
+      ADD_SPRITE(get_unit_nation_flag_sprite(punit), TRUE,
+                FULL_TILE_X_OFFSET + t->flag_offset_x,
+                FULL_TILE_Y_OFFSET + t->flag_offset_y);
     } else {
       /* Taken care of in the LAYER_BACKGROUND. */
     }
   }
 
-  ADD_SPRITE(unit_type(punit)->sprite, DRAW_FULL, TRUE,
-            t->unit_offset_x, t->unit_offset_y);
+  ADD_SPRITE(unit_type(punit)->sprite, TRUE,
+            FULL_TILE_X_OFFSET + t->unit_offset_x,
+            FULL_TILE_Y_OFFSET + t->unit_offset_y);
 
   if (sprites.unit.loaded && punit->transported_by != -1) {
     ADD_SPRITE_FULL(sprites.unit.loaded);
@@ -2762,7 +2767,7 @@
        continue;
       }
 
-      ADD_SPRITE(sprites.terrain[other]->blend[dir], DRAW_NORMAL, TRUE,
+      ADD_SPRITE(sprites.terrain[other]->blend[dir], TRUE,
                 offsets[dir][0], offsets[dir][1]);
     }
   }
@@ -2860,6 +2865,7 @@
 
   if (draw->layer[l].match_style == MATCH_NONE) {
     int count = sprite_vector_size(&draw->layer[l].base);
+    int ox = draw->layer[l].offset_x, oy = draw->layer[l].offset_y;
 
     /* Pseudo-random reproducable algorithm to pick a sprite. */
 #define LARGE_PRIME 10007
@@ -2868,9 +2874,11 @@
     assert((int)(LARGE_PRIME * MAP_INDEX_SIZE) > 0);
     count = ((ptile->index
              * LARGE_PRIME) % SMALL_PRIME) % count;
-    ADD_SPRITE(draw->layer[l].base.p[count],
-              draw->layer[l].is_tall ? DRAW_FULL : DRAW_NORMAL,
-              TRUE, draw->layer[l].offset_x, draw->layer[l].offset_y);
+    if (draw->layer[l].is_tall) {
+      ox += FULL_TILE_X_OFFSET;
+      oy += FULL_TILE_Y_OFFSET;
+    }
+    ADD_SPRITE(draw->layer[l].base.p[count], TRUE, ox, oy);
   } else {
     int match_type = draw->layer[l].match_type;
 
@@ -2879,6 +2887,8 @@
      ? sprites.terrain[ttype_near[(dir)]]->layer[l].match_type : -1)
 
     if (draw->layer[l].cell_type == CELL_SINGLE) {
+      int ox = draw->layer[l].offset_x, oy = draw->layer[l].offset_y;
+
       tileno = 0;
       assert(draw->layer[l].match_style == MATCH_BOOLEAN);
       for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
@@ -2889,9 +2899,11 @@
        }
       }
 
-      ADD_SPRITE(draw->layer[l].match[tileno],
-                draw->layer[l].is_tall ? DRAW_FULL : DRAW_NORMAL,
-                TRUE, draw->layer[l].offset_x, draw->layer[l].offset_y);
+      if (draw->layer[l].is_tall) {
+       ox += FULL_TILE_X_OFFSET;
+       oy += FULL_TILE_Y_OFFSET;
+      }
+      ADD_SPRITE(draw->layer[l].match[tileno], TRUE, ox, oy);
     } else if (draw->layer[l].cell_type == CELL_RECT) {
       /* Divide the tile up into four rectangular cells.  Now each of these
        * cells covers one corner, and each is adjacent to 3 different
@@ -2943,7 +2955,7 @@
 
        s = draw->layer[l].cells[array_index];
        if (s) {
-         ADD_SPRITE(s, DRAW_NORMAL, TRUE, x, y);
+         ADD_SPRITE(s, TRUE, x, y);
        }
       }
     }
@@ -2971,7 +2983,7 @@
        int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
 
        if (UNKNOWN(DIR4_TO_DIR8[i])) {
-         ADD_SPRITE(sprites.tx.darkness[i], DRAW_NORMAL, TRUE,
+         ADD_SPRITE(sprites.tx.darkness[i], TRUE,
                     offsets[i][0], offsets[i][1]);
        }
       }
@@ -3346,8 +3358,9 @@
     /* City.  Some city sprites are drawn later. */
     if (pcity && draw_cities) {
       if (!solid_color_behind_units) {
-       ADD_SPRITE(get_city_nation_flag_sprite(pcity),
-                  DRAW_FULL, TRUE, t->flag_offset_x, t->flag_offset_y);
+       ADD_SPRITE(get_city_nation_flag_sprite(pcity), TRUE,
+                  FULL_TILE_X_OFFSET + t->flag_offset_x,
+                  FULL_TILE_Y_OFFSET + t->flag_offset_y);
       }
       ADD_SPRITE_FULL(get_city_sprite(t, pcity));
       if (pcity->client.occupied) {
@@ -3386,11 +3399,11 @@
     /* City size.  Drawing this under fog makes it hard to read. */
     if (pcity && draw_cities) {
       if (pcity->size >= 10) {
-       ADD_SPRITE(sprites.city.size_tens[pcity->size / 10], DRAW_FULL,
-                  FALSE, 0, 0);
+       ADD_SPRITE(sprites.city.size_tens[pcity->size / 10],
+                  FALSE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET);
       }
-      ADD_SPRITE(sprites.city.size[pcity->size % 10], DRAW_FULL,
-                FALSE, 0, 0);
+      ADD_SPRITE(sprites.city.size[pcity->size % 10],
+                FALSE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET);
     }
     break;
 
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.125
diff -u -r1.125 tilespec.h
--- client/tilespec.h   9 Mar 2005 18:12:34 -0000       1.125
+++ client/tilespec.h   9 Mar 2005 19:05:21 -0000
@@ -49,12 +49,6 @@
 };
 
 struct drawn_sprite {
-  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 */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12468) remove draw_style from the drawn_sprite struct, Jason Short <=