Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9440) use direction lists for roadstyle 1
Home

[Freeciv-Dev] (PR#9440) use direction lists for roadstyle 1

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9440) use direction lists for roadstyle 1
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 20 Jul 2004 07:51:21 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch uses the tileset direction lists for roadstyle 1.

This is a bit ugly, since roadstyle 1 is a bit ugly.  But it will work 
well with hex since instead of a

   road_c_n0e1s0w1

you'll have something like a

   road_c_n0se1w1

meaning only 16 sprites are necessary not 32.

jason

Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.186
diff -u -r1.186 tilespec.c
--- client/tilespec.c   20 Jul 2004 14:02:38 -0000      1.186
+++ client/tilespec.c   20 Jul 2004 14:44:14 -0000
@@ -805,22 +805,21 @@
    * entirely on the tileset, not the topology.  They are also in clockwise
    * rotational ordering. */
   num_valid_tileset_dirs = num_cardinal_tileset_dirs = 0;
-  num_index_valid = num_index_cardinal = 2;
   dir = DIR8_NORTH;
   do {
     if (is_valid_tileset_dir(dir)) {
       valid_tileset_dirs[num_valid_tileset_dirs] = dir;
-      num_index_valid *= 2;
       num_valid_tileset_dirs++;
     }
     if (is_cardinal_tileset_dir(dir)) {
       cardinal_tileset_dirs[num_cardinal_tileset_dirs] = dir;
-      num_index_cardinal *= 2;
       num_cardinal_tileset_dirs++;
     }
 
     dir = dir_cw(dir);
   } while (dir != DIR8_NORTH);
+  num_index_valid = 1 << num_valid_tileset_dirs;
+  num_index_cardinal = 1 << num_cardinal_tileset_dirs;
 
   NORMAL_TILE_WIDTH = secfile_lookup_int(file, "tilespec.normal_tile_width");
   NORMAL_TILE_HEIGHT = secfile_lookup_int(file, "tilespec.normal_tile_height");
@@ -1281,23 +1280,37 @@
       SET_SPRITE(rail.dir[i], buffer);
     }
   } else if (roadstyle == 1) {
+    int num_index = 1 << (num_valid_tileset_dirs / 2), j;
+
     /* Roadstyle 1 has 32 additional sprites for both road and rail:
      * 16 each for cardinal and diagonal directions.  Each set
      * of 16 provides a NSEW-indexed sprite to provide connectors for
      * all rails in the cardinal/diagonal directions.  The 0 entry is
      * unused (the "isolated" sprite is used instead). */
-    for(i=1; i<NUM_DIRECTION_NSEW; i++) {
-      my_snprintf(buffer, sizeof(buffer), "r.c_road_%s", nsew_str(i));
-      SET_SPRITE(road.cardinal[i], buffer);
 
-      my_snprintf(buffer, sizeof(buffer), "r.d_road_%s", nsew_str(i));
-      SET_SPRITE(road.diagonal[i], buffer);
+    for (i = 1; i < num_index; i++) {
+      char c[64] = "", d[64] = "";
+
+      for (j = 0; j < num_valid_tileset_dirs / 2; j++) {
+       int value = (i >> j) & 1;
+
+       snprintf(c + strlen(c), sizeof(c) - strlen(c), "%s%d",
+                dir_get_tileset_name(valid_tileset_dirs[2 * j]), value);
+       snprintf(d + strlen(d), sizeof(d) - strlen(d), "%s%d",
+                dir_get_tileset_name(valid_tileset_dirs[2 * j + 1]), value);
+      }
+
+      my_snprintf(buffer, sizeof(buffer), "r.c_road_%s", c);
+      SET_SPRITE(road.even[i], buffer);
+
+      my_snprintf(buffer, sizeof(buffer), "r.d_road_%s", d);
+      SET_SPRITE(road.odd[i], buffer);
 
-      my_snprintf(buffer, sizeof(buffer), "r.c_rail_%s", nsew_str(i));
-      SET_SPRITE(rail.cardinal[i], buffer);
+      my_snprintf(buffer, sizeof(buffer), "r.c_rail_%s", c);
+      SET_SPRITE(rail.even[i], buffer);
 
-      my_snprintf(buffer, sizeof(buffer), "r.d_rail_%s", nsew_str(i));
-      SET_SPRITE(rail.diagonal[i], buffer);
+      my_snprintf(buffer, sizeof(buffer), "r.d_rail_%s", d);
+      SET_SPRITE(rail.odd[i], buffer);
     }
   } else {
     /* Roadstyle 2 includes 256 sprites, one for every possibility.
@@ -2222,41 +2235,51 @@
 
     /* First draw roads under rails. */
     if (road) {
-      int road_cardinal_tileno = INDEX_NSEW(draw_road[DIR8_NORTH],
-                                           draw_road[DIR8_SOUTH],
-                                           draw_road[DIR8_EAST],
-                                           draw_road[DIR8_WEST]);
-      int road_diagonal_tileno = INDEX_NSEW(draw_road[DIR8_NORTHEAST],
-                                           draw_road[DIR8_SOUTHWEST],
-                                           draw_road[DIR8_SOUTHEAST],
-                                           draw_road[DIR8_NORTHWEST]);
-
-      /* Draw the cardinal roads first. */
-      if (road_cardinal_tileno != 0) {
-       ADD_SPRITE_SIMPLE(sprites.road.cardinal[road_cardinal_tileno]);
+      int road_even_tileno = 0, road_odd_tileno = 0, i;
+
+      for (i = 0; i < num_valid_tileset_dirs / 2; i++) {
+       enum direction8 even = valid_tileset_dirs[2 * i];
+       enum direction8 odd = valid_tileset_dirs[2 * i + 1];
+
+       if (draw_road[even]) {
+         road_even_tileno |= 1 << i;
+       }
+       if (draw_road[odd]) {
+         road_odd_tileno |= 1 << i;
+       }
+      }
+
+      /* Draw the cardinal/even roads first. */
+      if (road_even_tileno != 0) {
+       ADD_SPRITE_SIMPLE(sprites.road.even[road_even_tileno]);
       }
-      if (road_diagonal_tileno != 0) {
-       ADD_SPRITE_SIMPLE(sprites.road.diagonal[road_diagonal_tileno]);
+      if (road_odd_tileno != 0) {
+       ADD_SPRITE_SIMPLE(sprites.road.odd[road_odd_tileno]);
       }
     }
 
     /* Then draw rails over roads. */
     if (rail) {
-      int rail_cardinal_tileno = INDEX_NSEW(draw_rail[DIR8_NORTH],
-                                           draw_rail[DIR8_SOUTH],
-                                           draw_rail[DIR8_EAST],
-                                           draw_rail[DIR8_WEST]);
-      int rail_diagonal_tileno = INDEX_NSEW(draw_rail[DIR8_NORTHEAST],
-                                           draw_rail[DIR8_SOUTHWEST],
-                                           draw_rail[DIR8_SOUTHEAST],
-                                           draw_rail[DIR8_NORTHWEST]);
-
-      /* Draw the cardinal rails first. */
-      if (rail_cardinal_tileno != 0) {
-       ADD_SPRITE_SIMPLE(sprites.rail.cardinal[rail_cardinal_tileno]);
+      int rail_even_tileno = 0, rail_odd_tileno = 0, i;
+
+      for (i = 0; i < num_valid_tileset_dirs / 2; i++) {
+       enum direction8 even = valid_tileset_dirs[2 * i];
+       enum direction8 odd = valid_tileset_dirs[2 * i + 1];
+
+       if (draw_rail[even]) {
+         rail_even_tileno |= 1 << i;
+       }
+       if (draw_rail[odd]) {
+         rail_odd_tileno |= 1 << i;
+       }
+      }
+
+      /* Draw the cardinal/even rails first. */
+      if (rail_even_tileno != 0) {
+       ADD_SPRITE_SIMPLE(sprites.rail.even[rail_even_tileno]);
       }
-      if (rail_diagonal_tileno != 0) {
-       ADD_SPRITE_SIMPLE(sprites.rail.diagonal[rail_diagonal_tileno]);
+      if (rail_odd_tileno != 0) {
+       ADD_SPRITE_SIMPLE(sprites.rail.odd[rail_odd_tileno]);
       }
     }
   } else {
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.78
diff -u -r1.78 tilespec.h
--- client/tilespec.h   20 Jul 2004 14:02:38 -0000      1.78
+++ client/tilespec.h   20 Jul 2004 14:44:14 -0000
@@ -83,6 +83,7 @@
 /* This the way directional indices are now encoded: */
 #define NUM_DIRECTION_NSEW             16
 #define MAX_INDEX_CARDINAL             64
+#define MAX_INDEX_HALF                  16
 #define NUM_DIRECTION_CW               256
 
 #define BIT_NORTH (0x01)
@@ -194,8 +195,8 @@
       /* for roadstyle 0 */
       *dir[8],     /* all entries used */
       /* for roadstyle 1 */
-      *cardinal[NUM_DIRECTION_NSEW],     /* first unused */
-      *diagonal[NUM_DIRECTION_NSEW],     /* first unused */
+      *even[MAX_INDEX_HALF],    /* first unused */
+      *odd[MAX_INDEX_HALF],     /* first unused */
       /* for roadstyle 0 and 1 */
       *isolated,
       *corner[NUM_DIRECTION_NSEW], /* only diagonal directions used */
Index: data/trident/roads.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident/roads.spec,v
retrieving revision 1.3
diff -u -r1.3 roads.spec
--- data/trident/roads.spec     18 Dec 2002 06:43:44 -0000      1.3
+++ data/trident/roads.spec     20 Jul 2004 14:44:15 -0000
@@ -27,39 +27,39 @@
 
 ; Cardinal roads, connections north, south, east, west:
 
-  0,  1, "r.c_road_n1s0e0w0"
-  0,  2, "r.c_road_n0s0e1w0"
-  0,  3, "r.c_road_n1s0e1w0"
-  0,  4, "r.c_road_n0s1e0w0"
-  0,  5, "r.c_road_n1s1e0w0"
-  0,  6, "r.c_road_n0s1e1w0"
-  0,  7, "r.c_road_n1s1e1w0"
-  0,  8, "r.c_road_n0s0e0w1"
-  0,  9, "r.c_road_n1s0e0w1"
-  0, 10, "r.c_road_n0s0e1w1"
-  0, 11, "r.c_road_n1s0e1w1"
-  0, 12, "r.c_road_n0s1e0w1"
-  0, 13, "r.c_road_n1s1e0w1"
-  0, 14, "r.c_road_n0s1e1w1"
-  0, 15, "r.c_road_n1s1e1w1"
+  0,  1, "r.c_road_n1e0s0w0"
+  0,  2, "r.c_road_n0e1s0w0"
+  0,  3, "r.c_road_n1e1s0w0"
+  0,  4, "r.c_road_n0e0s1w0"
+  0,  5, "r.c_road_n1e0s1w0"
+  0,  6, "r.c_road_n0e1s1w0"
+  0,  7, "r.c_road_n1e1s1w0"
+  0,  8, "r.c_road_n0e0s0w1"
+  0,  9, "r.c_road_n1e0s0w1"
+  0, 10, "r.c_road_n0e1s0w1"
+  0, 11, "r.c_road_n1e1s0w1"
+  0, 12, "r.c_road_n0e0s1w1"
+  0, 13, "r.c_road_n1e0s1w1"
+  0, 14, "r.c_road_n0e1s1w1"
+  0, 15, "r.c_road_n1e1s1w1"
 
 ; Diagonal roads, connections same, rotated 45 degrees clockwise:
 
-  1,  1, "r.d_road_n1s0e0w0"
-  1,  2, "r.d_road_n0s0e1w0"
-  1,  3, "r.d_road_n1s0e1w0"
-  1,  4, "r.d_road_n0s1e0w0"
-  1,  5, "r.d_road_n1s1e0w0"
-  1,  6, "r.d_road_n0s1e1w0"
-  1,  7, "r.d_road_n1s1e1w0"
-  1,  8, "r.d_road_n0s0e0w1"
-  1,  9, "r.d_road_n1s0e0w1"
-  1, 10, "r.d_road_n0s0e1w1"
-  1, 11, "r.d_road_n1s0e1w1"
-  1, 12, "r.d_road_n0s1e0w1"
-  1, 13, "r.d_road_n1s1e0w1"
-  1, 14, "r.d_road_n0s1e1w1"
-  1, 15, "r.d_road_n1s1e1w1"
+  1,  1, "r.d_road_ne1se0sw0nw0"
+  1,  2, "r.d_road_ne0se1sw0nw0"
+  1,  3, "r.d_road_ne1se1sw0nw0"
+  1,  4, "r.d_road_ne0se0sw1nw0"
+  1,  5, "r.d_road_ne1se0sw1nw0"
+  1,  6, "r.d_road_ne0se1sw1nw0"
+  1,  7, "r.d_road_ne1se1sw1nw0"
+  1,  8, "r.d_road_ne0se0sw0nw1"
+  1,  9, "r.d_road_ne1se0sw0nw1"
+  1, 10, "r.d_road_ne0se1sw0nw1"
+  1, 11, "r.d_road_ne1se1sw0nw1"
+  1, 12, "r.d_road_ne0se0sw1nw1"
+  1, 13, "r.d_road_ne1se0sw1nw1"
+  1, 14, "r.d_road_ne0se1sw1nw1"
+  1, 15, "r.d_road_ne1se1sw1nw1"
 }
 
 [grid_rails]
@@ -75,39 +75,39 @@
 
 ; Cardinal rails, connections north, south, east, west:
 
-  2,  1, "r.c_rail_n1s0e0w0"
-  2,  2, "r.c_rail_n0s0e1w0"
-  2,  3, "r.c_rail_n1s0e1w0"
-  2,  4, "r.c_rail_n0s1e0w0"
-  2,  5, "r.c_rail_n1s1e0w0"
-  2,  6, "r.c_rail_n0s1e1w0"
-  2,  7, "r.c_rail_n1s1e1w0"
-  2,  8, "r.c_rail_n0s0e0w1"
-  2,  9, "r.c_rail_n1s0e0w1"
-  2, 10, "r.c_rail_n0s0e1w1"
-  2, 11, "r.c_rail_n1s0e1w1"
-  2, 12, "r.c_rail_n0s1e0w1"
-  2, 13, "r.c_rail_n1s1e0w1"
-  2, 14, "r.c_rail_n0s1e1w1"
-  2, 15, "r.c_rail_n1s1e1w1"
+  2,  1, "r.c_rail_n1e0s0w0"
+  2,  2, "r.c_rail_n0e1s0w0"
+  2,  3, "r.c_rail_n1e1s0w0"
+  2,  4, "r.c_rail_n0e0s1w0"
+  2,  5, "r.c_rail_n1e0s1w0"
+  2,  6, "r.c_rail_n0e1s1w0"
+  2,  7, "r.c_rail_n1e1s1w0"
+  2,  8, "r.c_rail_n0e0s0w1"
+  2,  9, "r.c_rail_n1e0s0w1"
+  2, 10, "r.c_rail_n0e1s0w1"
+  2, 11, "r.c_rail_n1e1s0w1"
+  2, 12, "r.c_rail_n0e0s1w1"
+  2, 13, "r.c_rail_n1e0s1w1"
+  2, 14, "r.c_rail_n0e1s1w1"
+  2, 15, "r.c_rail_n1e1s1w1"
 
 ; Diagonal rails, connections same, rotated 45 degrees clockwise:
 
-  3,  1, "r.d_rail_n1s0e0w0"
-  3,  2, "r.d_rail_n0s0e1w0"
-  3,  3, "r.d_rail_n1s0e1w0"
-  3,  4, "r.d_rail_n0s1e0w0"
-  3,  5, "r.d_rail_n1s1e0w0"
-  3,  6, "r.d_rail_n0s1e1w0"
-  3,  7, "r.d_rail_n1s1e1w0"
-  3,  8, "r.d_rail_n0s0e0w1"
-  3,  9, "r.d_rail_n1s0e0w1"
-  3, 10, "r.d_rail_n0s0e1w1"
-  3, 11, "r.d_rail_n1s0e1w1"
-  3, 12, "r.d_rail_n0s1e0w1"
-  3, 13, "r.d_rail_n1s1e0w1"
-  3, 14, "r.d_rail_n0s1e1w1"
-  3, 15, "r.d_rail_n1s1e1w1"
+  3,  1, "r.d_rail_ne1se0sw0nw0"
+  3,  2, "r.d_rail_ne0se1sw0nw0"
+  3,  3, "r.d_rail_ne1se1sw0nw0"
+  3,  4, "r.d_rail_ne0se0sw1nw0"
+  3,  5, "r.d_rail_ne1se0sw1nw0"
+  3,  6, "r.d_rail_ne0se1sw1nw0"
+  3,  7, "r.d_rail_ne1se1sw1nw0"
+  3,  8, "r.d_rail_ne0se0sw0nw1"
+  3,  9, "r.d_rail_ne1se0sw0nw1"
+  3, 10, "r.d_rail_ne0se1sw0nw1"
+  3, 11, "r.d_rail_ne1se1sw0nw1"
+  3, 12, "r.d_rail_ne0se0sw1nw1"
+  3, 13, "r.d_rail_ne1se0sw1nw1"
+  3, 14, "r.d_rail_ne0se1sw1nw1"
+  3, 15, "r.d_rail_ne1se1sw1nw1"
 
 ; Rail corners
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9440) use direction lists for roadstyle 1, Jason Short <=