Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] (PR#8628) changing cell drawing code
Home

[Freeciv-Dev] (PR#8628) changing cell drawing code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8628) changing cell drawing code
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 30 Apr 2004 19:57:43 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch changes the cell drawing code (used for drawing of oceans in 
iso-view) in a few subtle ways.

- The directions used internally now match the direction4 direction 
ordering.  This reduces one level of complexity, making it easier to 
make changes without breaking things.

- The tileset lists the sprite's match value via a binary integer rather 
than a decimal/octal one.  This should make things much easier for 
tileset authors to understand.

I also added documentation.

jason

? tests/check-output
? tests/header_guard.sh
? tests/va_list.sh
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.165
diff -u -r1.165 tilespec.c
--- client/tilespec.c   29 Apr 2004 15:11:32 -0000      1.165
+++ client/tilespec.c   1 May 2004 02:52:44 -0000
@@ -1320,12 +1320,13 @@
        draw->layer[l].base = draw->layer[l].match[0];
        break;
       case CELL_RECT:
-       for (i = 0; i < 4; i++) {
+       for (i = 0; i < 4; i++) { /* enum direction4 */
          for (j = 0; j < 8; j++) {
-           char *dir2 = "udlr";
+           const char dirs[4] = "udrl"; /* Matches direction4 ordering */
 
-           my_snprintf(buffer1, sizeof(buffer1), "t.%s_cell_%c%d",
-                       draw->name, dir2[i], j);
+           my_snprintf(buffer1, sizeof(buffer1), "t.%s_cell_%c%d%d%d",
+                       draw->name, dirs[i],
+                       (j >> 2) & 1, (j >> 1) & 1, j & 1);
            draw->layer[l].cells[j][i]
              = lookup_sprite_tag_alt(buffer1, "", TRUE, "tile_type",
                                      tt->terrain_name);
@@ -2008,24 +2009,24 @@
         * cells covers one corner, and each is adjacent to 3 different
         * tiles.  For each cell we pixk a sprite based upon the adjacent
         * terrains at each of those tiles.  Thus we have 8 different sprites
-        * for each of the 4 cells (32 sprites total). */
+        * for each of the 4 cells (32 sprites total).
+        *
+        * These arrays correspond to the direction4 ordering. */
        const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
-       const enum direction8 dirs[4] = {
-         DIR8_NORTHWEST, DIR8_SOUTHEAST, DIR8_SOUTHWEST, DIR8_NORTHEAST
-       };
        const int iso_offsets[4][2] = {
-         {W / 4, 0}, {W / 4, H / 2}, {0, H / 4}, {W / 2, H / 4},
+         {W / 4, 0}, {W / 4, H / 2}, {W / 2, H / 4}, {0, H / 4}
        };
        const int noniso_offsets[4][2] = {
-         {0, 0}, {W / 2, H / 2}, {0, H / 2}, {W / 2, 0}
+         {0, 0}, {W / 2, H / 2}, {W / 2, 0}, {0, H / 2}
        };
        int i;
 
        /* put coasts */
        for (i = 0; i < 4; i++) {
-         int array_index = ((!MATCH(dir_ccw(dirs[i])) ? 1 : 0)
-                            + (!MATCH(dirs[i]) ? 2 : 0)
-                            + (!MATCH(dir_cw(dirs[i])) ? 4 : 0));
+         enum direction8 dir = dir_ccw(DIR4_TO_DIR8[i]);
+         int array_index = ((!MATCH(dir_ccw(dir)) ? 4 : 0)
+                            + (!MATCH(dir) ? 2 : 0)
+                            + (!MATCH(dir_cw(dir)) ? 1 : 0));
          int x = (is_isometric ? iso_offsets[i][0] : noniso_offsets[i][0]);
          int y = (is_isometric ? iso_offsets[i][1] : noniso_offsets[i][1]);
 
Index: data/isotrident/terrain2.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident/terrain2.spec,v
retrieving revision 1.3
diff -u -r1.3 terrain2.spec
--- data/isotrident/terrain2.spec       27 Feb 2004 18:31:39 -0000      1.3
+++ data/isotrident/terrain2.spec       1 May 2004 02:52:44 -0000
@@ -137,39 +137,41 @@
 is_pixel_border = 1
 
 tiles = { "row", "column","tag"
- 0, 0,  "t.ocean_cell_u0"
- 0, 2,  "t.ocean_cell_u1"
- 0, 4,  "t.ocean_cell_u2"
- 0, 6,  "t.ocean_cell_u3"
- 0, 8,  "t.ocean_cell_u4"
- 0, 10, "t.ocean_cell_u5"
- 0, 12, "t.ocean_cell_u6"
- 0, 14, "t.ocean_cell_u7"
+
+; ocean cell sprites.  See doc/README.graphics
+ 0, 0,  "t.ocean_cell_u000"
+ 0, 2,  "t.ocean_cell_u100"
+ 0, 4,  "t.ocean_cell_u010"
+ 0, 6,  "t.ocean_cell_u110"
+ 0, 8,  "t.ocean_cell_u001"
+ 0, 10, "t.ocean_cell_u101"
+ 0, 12, "t.ocean_cell_u011"
+ 0, 14, "t.ocean_cell_u111"
  
- 1, 0,  "t.ocean_cell_d0"
- 1, 2,  "t.ocean_cell_d1"
- 1, 4,  "t.ocean_cell_d2"
- 1, 6,  "t.ocean_cell_d3"
- 1, 8,  "t.ocean_cell_d4"
- 1, 10, "t.ocean_cell_d5"
- 1, 12, "t.ocean_cell_d6"
- 1, 14, "t.ocean_cell_d7"
+ 1, 0,  "t.ocean_cell_d000"
+ 1, 2,  "t.ocean_cell_d100"
+ 1, 4,  "t.ocean_cell_d010"
+ 1, 6,  "t.ocean_cell_d110"
+ 1, 8,  "t.ocean_cell_d001"
+ 1, 10, "t.ocean_cell_d101"
+ 1, 12, "t.ocean_cell_d011"
+ 1, 14, "t.ocean_cell_d111"
 
- 2, 0,  "t.ocean_cell_l0"
- 2, 2,  "t.ocean_cell_l1"
- 2, 4,  "t.ocean_cell_l2"
- 2, 6,  "t.ocean_cell_l3"
- 2, 8,  "t.ocean_cell_l4"
- 2, 10, "t.ocean_cell_l5"
- 2, 12, "t.ocean_cell_l6"
- 2, 14, "t.ocean_cell_l7"
+ 2, 0,  "t.ocean_cell_l000"
+ 2, 2,  "t.ocean_cell_l100"
+ 2, 4,  "t.ocean_cell_l010"
+ 2, 6,  "t.ocean_cell_l110"
+ 2, 8,  "t.ocean_cell_l001"
+ 2, 10, "t.ocean_cell_l101"
+ 2, 12, "t.ocean_cell_l011"
+ 2, 14, "t.ocean_cell_l111"
 
- 2, 1,  "t.ocean_cell_r0"
- 2, 3,  "t.ocean_cell_r1"
- 2, 5,  "t.ocean_cell_r2"
- 2, 7,  "t.ocean_cell_r3"
- 2, 9,  "t.ocean_cell_r4"
- 2, 11, "t.ocean_cell_r5"
- 2, 13, "t.ocean_cell_r6"
- 2, 15, "t.ocean_cell_r7"
+ 2, 1,  "t.ocean_cell_r000"
+ 2, 3,  "t.ocean_cell_r100"
+ 2, 5,  "t.ocean_cell_r010"
+ 2, 7,  "t.ocean_cell_r110"
+ 2, 9,  "t.ocean_cell_r001"
+ 2, 11, "t.ocean_cell_r101"
+ 2, 13, "t.ocean_cell_r011"
+ 2, 15, "t.ocean_cell_r111"
 }
Index: doc/README.graphics
===================================================================
RCS file: /home/freeciv/CVS/freeciv/doc/README.graphics,v
retrieving revision 1.11
diff -u -r1.11 README.graphics
--- doc/README.graphics 1 Apr 2004 23:11:23 -0000       1.11
+++ doc/README.graphics 1 May 2004 02:52:44 -0000
@@ -183,9 +183,22 @@
                           32 different sprites are needed.  Each sprite is
                           a rectangle corresponding to one cell, and there are
                           8 different sprites per cell.  Each sprite has
-                          a name like "t.ocean_cell_u5" where "ocean" is the
+                          a name like "t.ocean_cell_u110" where "ocean" is the
                           terrain, "u" means up (north on the map) and
-                          5 indicates which of the adjacent tiles are matched.
+                          110 indicates which of the adjacent tiles are
+                         mismatched.  For instance u110 means
+
+                                   /\
+                                  /B \
+                                 /\ 1/\
+                                / A\/C \
+                                \1 /\ 0/
+                                 \/D \/
+                                  \  /
+                                   \/
+
+                         a matching terrain exists at C but not at A or B.  In
+                          this case D is the current tile.
 
 Examples:
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8628) changing cell drawing code, Jason Short <=