Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] (PR#8568) restructuring of draw_part and draw_type
Home

[Freeciv-Dev] (PR#8568) restructuring of draw_part and draw_type

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8568) restructuring of draw_part and draw_type
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 21 Apr 2004 16:10:52 -0700
Reply-to: rt@xxxxxxxxxxx

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

Currently draw_part is a bitfield comprised of the 6 different "parts" 
of an iso-view tile.

draw_type is an enumeration of the 18 possible rectangles that can be 
made from these 6 parts.  Except that 6 of the rectangles are already 
included in draw_part and so aren't duplicated, and one of the 
rectangles is unused and not included.

This makes it difficult to build up a draw_type from scratch.  For 
instance in the gui_rect_iterate I want to have code like:

   if (tile is not on the left side) {
     draw |= D_LEFT;
   }

but there is no way to do this.

This patch changes things.  draw_part is now actually a real bitfield 
comprised of the 5 different possible overlays: (left, right), (top, 
middle, and bottom).  draw_type is built on top of these masks and 
includes all 18 possible rectangles.

The users who use the bitfield properties of the draw_type are changed. 
  This generally makes them more readable.

jason

? diff
? jason game.gz
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.103
diff -u -r1.103 mapview_common.c
--- client/mapview_common.c     20 Apr 2004 19:56:16 -0000      1.103
+++ client/mapview_common.c     21 Apr 2004 22:58:09 -0000
@@ -805,28 +805,28 @@
       *end_x = W - inset;
       *start_y = inset + width;
       *end_y = H / 2 + width;
-      return (draw & D_M_R);
+      return (draw & D_M_R) == D_M_R;
     case DIR8_SOUTH:
       /* Bottom left. */
       *start_x = inset;
       *end_x = W / 2;
       *start_y = H / 2 - overlap;
       *end_y = H - inset - overlap;
-      return (draw & D_B_L) && (inset + overlap) > 0;
+      return (draw & D_B_L) == D_B_L && (inset + overlap) > 0;
     case DIR8_EAST:
       /* Bottom right. */
       *start_x = W - inset;
       *end_x = W / 2;
       *start_y = H / 2 - overlap;
       *end_y = H - inset - overlap;
-      return (draw & D_B_R) && (inset + overlap) > 0;
+      return (draw & D_B_R) == D_B_R && (inset + overlap) > 0;
     case DIR8_WEST:
       /* Top left. */
       *start_x = inset;
       *end_x = W / 2;
       *start_y = H / 2 + width;
       *end_y = inset + width;
-      return (draw & D_M_L);
+      return (draw & D_M_L) == D_M_L;
     case DIR8_NORTHEAST:
     case DIR8_SOUTHEAST:
     case DIR8_SOUTHWEST:
@@ -1197,36 +1197,36 @@
     freelog(LOG_DEBUG, "putting (%d,%d) at (%d,%d), draw %x",
            map_x, map_y, canvas_x, canvas_y, draw);
 
-    if ((draw & D_TMB_L) && (draw & D_TMB_R)) {
+    if ((draw & D_L) && (draw & D_R)) {
       width = NORMAL_TILE_WIDTH;
     } else {
       width = NORMAL_TILE_WIDTH / 2;
     }
 
-    if (draw & D_TMB_L) {
+    if (draw & D_L) {
       offset_x = 0;
     } else {
       offset_x = NORMAL_TILE_WIDTH / 2;
     }
 
     height = 0;
-    if (draw & D_M_LR) {
+    if (draw & D_M) {
       height += NORMAL_TILE_HEIGHT / 2;
     }
-    if (draw & D_B_LR) {
+    if (draw & D_B) {
       height += NORMAL_TILE_HEIGHT / 2;
     }
 
     height_unit = height;
-    if (draw & D_T_LR) {
+    if (draw & D_T) {
       height_unit += NORMAL_TILE_HEIGHT / 2;
     }
 
-    offset_y = (draw & D_M_LR) ? 0 : NORMAL_TILE_HEIGHT / 2;
+    offset_y = (draw & D_M) ? 0 : NORMAL_TILE_HEIGHT / 2;
 
-    if (draw & D_T_LR) {
+    if (draw & D_T) {
       offset_y_unit = 0;
-    } else if (draw & D_M_LR) {
+    } else if (draw & D_M) {
       offset_y_unit = NORMAL_TILE_HEIGHT / 2;
     } else {
       offset_y_unit = NORMAL_TILE_HEIGHT;
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.56
diff -u -r1.56 mapview_common.h
--- client/mapview_common.h     15 Apr 2004 19:36:00 -0000      1.56
+++ client/mapview_common.h     21 Apr 2004 22:58:09 -0000
@@ -61,22 +61,25 @@
 
 /* 
  * When drawing a tile (currently only in isometric mode), there are
- * six relevant parts we can draw.  Each of these is a rectangle of
- * size NORMAL_TILE_WIDTH/2 x NORMAL_TILE_HEIGHT/2.
+ * 5 relevant bits: top, middle, bottom, left, and right.  A drawing area
+ * is comprised of an OR-ing of these.  Note that if you must have a vertical
+ * (D_T, D_M, D_B) and horizontal (D_L, D_R) element to get any actual
+ * area.  There are therefore six parts to the tile:
  *
- *   Left    Right
+ *
+ * Left:D_L Right:D_R
  *
  * -----------------
  * |       |       |
- * | D_T_L | D_T_R |  Top, above the actual tile
+ * | D_T_L | D_T_R |  Top, above the actual tile : D_T
  * |       |       |
  * -----------------
  * |       |       |
- * | D_M_L | D_M_R |  Middle, upper half of the actual tile
+ * | D_M_L | D_M_R |  Middle, upper half of the actual tile : D_M
  * |       |       |
  * -----------------
  * |       |       |
- * | D_B_L | D_B_R |  Bottom, lower half of the actual tile
+ * | D_B_L | D_B_R |  Bottom, lower half of the actual tile : D_B
  * |       |       |
  * -----------------
  *
@@ -90,19 +93,17 @@
  * for one tile we have to draw D_M_R for the tile just down-left from
  * it, then D_T_L for the tile below it.
  *
- * This concept currently only applies to the isometric drawing code,
- * and currently the D_T_L and D_T_R rectangles are not used.  But
- * either of these could change in the future.
+ * This concept only applies to the isometric drawing code.  Non-isometric
+ * code may pass around a draw_type variable but it's generally ignored.
  *
  * These values are used as a mask; see enum draw_type.
  */
 enum draw_part {
-  D_T_L = 1,
-  D_T_R = 2,
-  D_M_L = 4,
-  D_M_R = 8,
-  D_B_L = 16,
-  D_B_R = 32
+  D_T = 1, /* Draw top. */
+  D_M = 2, /* Draw middle. */
+  D_B = 4, /* Draw bottom. */
+  D_L = 8, /* Draw left. */
+  D_R = 16 /* Draw right. */
 };
 
 /* 
@@ -115,22 +116,30 @@
  * Format (regexp): D_[TMB]+_[LR]+.
  *
  * Note that each of these sets of rectangles must itelf make up a
- * larger rectangle.  However, not all 18 possible sub-rectangles are
- * needed.
+ * larger rectangle.  There are 18 such rectangles (C(3, 1) * C(4, 2)).
+ * However not all sub-rectangles are necessarily used.
  */
 enum draw_type {
-  D_FULL = D_T_L | D_T_R | D_M_L | D_M_R | D_B_L | D_B_R,
-  D_B_LR = D_B_L | D_B_R,
-  D_MB_L = D_M_L | D_B_L,
-  D_MB_R = D_M_R | D_B_R,
-  D_TM_L = D_T_L | D_M_L,
-  D_TM_R = D_T_R | D_M_R,
-  D_T_LR = D_T_L | D_T_R,
-  D_TMB_L = D_T_L | D_M_L | D_B_L,
-  D_TMB_R = D_T_R | D_M_R | D_B_R,
-  D_M_LR = D_M_L | D_M_R,
-  D_MB_LR = D_M_L | D_M_R | D_B_L | D_B_R
+  D_T_L = D_T | D_L,
+  D_T_R = D_T | D_R,
+  D_M_L = D_M | D_L,
+  D_M_R = D_M | D_R,
+  D_B_L = D_B | D_L,
+  D_B_R = D_B | D_R,
+  D_TM_L = D_T | D_M | D_L,
+  D_TM_R = D_T | D_M | D_R,
+  D_MB_L = D_M | D_B | D_L,
+  D_MB_R = D_M | D_B | D_R,
+  D_TMB_L = D_T | D_M | D_B | D_L,
+  D_TMB_R = D_T | D_M | D_B | D_R,
+  D_T_LR = D_T | D_L | D_R,
+  D_M_LR = D_M | D_L | D_R,
+  D_B_LR = D_B | D_L | D_R,
+  D_TM_LR = D_T | D_M | D_L | D_R,
+  D_MB_LR = D_M | D_B | D_L | D_R,
+  D_TMB_LR = D_T | D_M | D_B | D_L | D_R
 };
+#define D_FULL D_TMB_LR
 
 #define BORDER_WIDTH 2
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8568) restructuring of draw_part and draw_type, Jason Short <=