[Freeciv-Dev] (PR#9489) Patch: use direction lists for roadstyle 2
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#9489) Patch: use direction lists for roadstyle 2 |
From: |
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> |
Date: |
Fri, 23 Jul 2004 13:28:34 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9489 >
This patch causes roadstyle 2 to use direction lists. This is less
error-prone and works better for hex.
jason
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.188
diff -u -r1.188 tilespec.c
--- client/tilespec.c 23 Jul 2004 19:33:35 -0000 1.188
+++ client/tilespec.c 23 Jul 2004 20:25:17 -0000
@@ -1111,19 +1111,22 @@
}
/****************************************************************************
- Do the same thing as nsew_str, except including all the cardinal and
- diagonal directions.
+ Do the same thing as cardinal_str, except including all valid directions.
The returned string is a pointer to static memory.
****************************************************************************/
-static char *cw_str(int idx)
+static char *valid_index_str(int idx)
{
- static char c[21]; /* strlen(<this next string>) + 1 == 21 */
+ static char c[64];
+ int i;
+
+ c[0] = '\0';
+ for (i = 0; i < num_valid_tileset_dirs; i++) {
+ int value = (idx >> i) & 1;
+
+ snprintf(c + strlen(c), sizeof(c) - strlen(c), "%s%d",
+ dir_get_tileset_name(valid_tileset_dirs[i]), value);
+ }
- sprintf(c, "n%dne%de%dse%ds%dsw%dw%dnw%d",
- BOOL_VAL(idx & CW_NORTH), BOOL_VAL(idx & CW_NORTHEAST),
- BOOL_VAL(idx & CW_EAST), BOOL_VAL(idx & CW_SOUTHEAST),
- BOOL_VAL(idx & CW_SOUTH), BOOL_VAL(idx & CW_SOUTHWEST),
- BOOL_VAL(idx & CW_WEST), BOOL_VAL(idx & CW_NORTHWEST));
return c;
}
@@ -1311,11 +1314,11 @@
} else {
/* Roadstyle 2 includes 256 sprites, one for every possibility.
* Just go around clockwise, with all combinations. */
- for (i = 0; i < NUM_DIRECTION_CW; i++) {
- my_snprintf(buffer, sizeof(buffer), "r.road_%s", cw_str(i));
+ for (i = 0; i < num_index_valid; i++) {
+ my_snprintf(buffer, sizeof(buffer), "r.road_%s", valid_index_str(i));
SET_SPRITE(road.total[i], buffer);
- my_snprintf(buffer, sizeof(buffer), "r.rail_%s", cw_str(i));
+ my_snprintf(buffer, sizeof(buffer), "r.rail_%s", valid_index_str(i));
SET_SPRITE(rail.total[i], buffer);
}
}
@@ -2286,14 +2289,15 @@
/* Draw roads first */
if (road) {
- int road_tileno = INDEX_CW(draw_road[DIR8_NORTH],
- draw_road[DIR8_NORTHEAST],
- draw_road[DIR8_EAST],
- draw_road[DIR8_SOUTHEAST],
- draw_road[DIR8_SOUTH],
- draw_road[DIR8_SOUTHWEST],
- draw_road[DIR8_WEST],
- draw_road[DIR8_NORTHWEST]);
+ int road_tileno = 0, i;
+
+ for (i = 0; i < num_valid_tileset_dirs; i++) {
+ enum direction8 dir = valid_tileset_dirs[i];
+
+ if (draw_road[dir]) {
+ road_tileno |= 1 << i;
+ }
+ }
if (road_tileno != 0 || draw_single_road) {
ADD_SPRITE_SIMPLE(sprites.road.total[road_tileno]);
@@ -2302,14 +2306,15 @@
/* Then draw rails over roads. */
if (rail) {
- int rail_tileno = INDEX_CW(draw_rail[DIR8_NORTH],
- draw_rail[DIR8_NORTHEAST],
- draw_rail[DIR8_EAST],
- draw_rail[DIR8_SOUTHEAST],
- draw_rail[DIR8_SOUTH],
- draw_rail[DIR8_SOUTHWEST],
- draw_rail[DIR8_WEST],
- draw_rail[DIR8_NORTHWEST]);
+ int rail_tileno = 0, i;
+
+ for (i = 0; i < num_valid_tileset_dirs; i++) {
+ enum direction8 dir = valid_tileset_dirs[i];
+
+ if (draw_rail[dir]) {
+ rail_tileno |= 1 << i;
+ }
+ }
if (rail_tileno != 0 || draw_single_rail) {
ADD_SPRITE_SIMPLE(sprites.rail.total[rail_tileno]);
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.79
diff -u -r1.79 tilespec.h
--- client/tilespec.h 22 Jul 2004 02:53:31 -0000 1.79
+++ client/tilespec.h 23 Jul 2004 20:25:17 -0000
@@ -84,7 +84,7 @@
#define NUM_DIRECTION_NSEW 16
#define MAX_INDEX_CARDINAL 64
#define MAX_INDEX_HALF 16
-#define NUM_DIRECTION_CW 256
+#define MAX_INDEX_VALID 256
#define BIT_NORTH (0x01)
#define BIT_SOUTH (0x02)
@@ -96,24 +96,6 @@
((e) ? BIT_EAST : 0) | \
((w) ? BIT_WEST : 0))
-#define CW_NORTH (0x01)
-#define CW_NORTHEAST (0x02)
-#define CW_EAST (0x04)
-#define CW_SOUTHEAST (0x08)
-#define CW_SOUTH (0x10)
-#define CW_SOUTHWEST (0x20)
-#define CW_WEST (0x40)
-#define CW_NORTHWEST (0x80)
-
-#define INDEX_CW(n, ne, e, se, s, sw, w, nw) (((n) ? CW_NORTH : 0)
\
- | ((ne) ? CW_NORTHEAST : 0) \
- | ((e) ? CW_EAST : 0) \
- | ((se) ? CW_SOUTHEAST : 0) \
- | ((s) ? CW_SOUTH : 0) \
- | ((sw) ? CW_SOUTHWEST : 0) \
- | ((w) ? CW_WEST : 0) \
- | ((nw) ? CW_NORTHWEST : 0))
-
#define NUM_TILES_PROGRESS 8
#define NUM_TILES_CITIZEN CITIZEN_LAST
#define NUM_TILES_HP_BAR 11
@@ -200,7 +182,7 @@
/* for roadstyle 0 and 1 */
*isolated,
*corner[NUM_DIRECTION_NSEW], /* only diagonal directions used */
- *total[NUM_DIRECTION_CW]; /* includes all possibilities */
+ *total[MAX_INDEX_VALID]; /* includes all possibilities */
} road, rail;
struct {
struct Sprite **unit;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#9489) Patch: use direction lists for roadstyle 2,
Jason Short <=
|
|