Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] (PR#7497) new function fill_terrain_sprite_array
Home

[Freeciv-Dev] (PR#7497) new function fill_terrain_sprite_array

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7497) new function fill_terrain_sprite_array
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 Feb 2004 15:42:02 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch introduces a new function fill_terrain_sprite_array, to be 
called by both fill_tile_sprite_array and fill_tile_sprite_array_iso.

The overall goal is to unify both of these functions.  This patch helps 
in that regard, although it doesn't get rid of much code.

As a side effect the spec-tile sprite drawing method (used for denmark 
in earth scenarios) will work in iso-view.

jason

? coasts.diff
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.143
diff -u -r1.143 tilespec.c
--- client/tilespec.c   2004/02/23 05:31:19     1.143
+++ client/tilespec.c   2004/02/23 23:15:46
@@ -1873,6 +1873,111 @@
   return sprs - saved_sprs;
 }
 
+/****************************************************************************
+  Add sprites for the base terrain to the sprite list.  This doesn't
+  include specials or rivers.
+****************************************************************************/
+static int fill_terrain_sprite_array(struct drawn_sprite *sprs,
+                                    struct tile *ptile,
+                                    enum tile_terrain_type *ttype_near,
+                                    int *dither_count)
+{
+  struct drawn_sprite *saved_sprs = sprs;
+  struct Sprite *sprite;
+  enum tile_terrain_type ttype = ptile->terrain;
+
+  if (!draw_terrain) {
+    *dither_count = 0;
+    return 0;
+  }
+
+  if (ptile->spec_sprite && (sprite = load_sprite(ptile->spec_sprite))) {
+    /* Skip dithering. */
+    ADD_SPRITE_SIMPLE(sprite);
+    return 1;
+  }
+
+  if (is_isometric && is_ocean(ttype)) {
+    /* painted via coasts. */
+    const enum direction8 dirs[4] = {
+      DIR8_NORTHWEST, /* up */
+      DIR8_SOUTHEAST, /* down */
+      DIR8_SOUTHWEST, /* left */
+      DIR8_NORTHEAST /* right */
+    };
+    const int offsets[4][2] = {
+      {NORMAL_TILE_WIDTH / 4, 0},
+      {NORMAL_TILE_WIDTH / 4, NORMAL_TILE_HEIGHT / 2},
+      {0, NORMAL_TILE_HEIGHT / 4},
+      {NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 4},
+    };
+    int i;
+
+    *dither_count = 4;
+
+    /* put coasts */
+    for (i = 0; i < 4; i++) {
+      int array_index = ((!is_ocean(ttype_near[dir_ccw(dirs[i])]) ? 1 : 0)
+                        + (!is_ocean(ttype_near[dirs[i]]) ? 2 : 0)
+                        + (!is_ocean(ttype_near[dir_cw(dirs[i])])
+                           ? 4 : 0));
+
+      ADD_SPRITE(sprites.tx.coast_cape_iso[array_index][i],
+                offsets[i][0], offsets[i][1]);
+    }
+  } else {
+    *dither_count = 1;
+
+    if (
+sprites.terrain[ttype]->match_type == 0
+       || sprites.terrain[ttype]->is_layered) {
+      ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->base);
+    }
+
+    if (sprites.terrain[ttype]->match_type != 0) {
+      int match_type = sprites.terrain[ttype]->match_type;
+#define MATCH(dir) (sprites.terrain[ttype_near[(dir)]]->match_type)
+      int tileno = INDEX_NSEW(MATCH(DIR8_NORTH) == match_type,
+                             MATCH(DIR8_SOUTH) == match_type,
+                             MATCH(DIR8_EAST) == match_type,
+                             MATCH(DIR8_WEST) == match_type);
+#undef MATCH
+
+      ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->blend[tileno]);
+    }
+
+    /* Short-cut past dithering if all adjacent tiles are the same. */
+    if (ttype_near[DIR8_NORTH] == ttype
+       && ttype_near[DIR8_SOUTH] == ttype
+       && ttype_near[DIR8_EAST] == ttype
+       && ttype_near[DIR8_WEST] == ttype) {
+      *dither_count = 0;
+    }
+  }
+
+  /* Extra "capes" added on in non-iso view. */
+  if (is_ocean(ttype) && !is_isometric) {
+    int tileno = INDEX_NSEW((is_ocean(ttype_near[DIR8_NORTH])
+                            && is_ocean(ttype_near[DIR8_EAST])
+                            && !is_ocean(ttype_near[DIR8_NORTHEAST])),
+                           (is_ocean(ttype_near[DIR8_SOUTH])
+                            && is_ocean(ttype_near[DIR8_WEST])
+                            && !is_ocean(ttype_near[DIR8_SOUTHWEST])),
+                           (is_ocean(ttype_near[DIR8_EAST])
+                            && is_ocean(ttype_near[DIR8_SOUTH])
+                            && !is_ocean(ttype_near[DIR8_SOUTHEAST])),
+                           (is_ocean(ttype_near[DIR8_NORTH])
+                            && is_ocean(ttype_near[DIR8_WEST])
+                            && !is_ocean(ttype_near[DIR8_NORTHWEST])));
+    if (tileno != 0) {
+      ADD_SPRITE_SIMPLE(sprites.tx.coast_cape[tileno]);
+    }
+  }
+
+  return sprs - saved_sprs;
+}
+
+
 /**********************************************************************
 Fill in the sprite array for the tile at position (abs_x0,abs_y0).
 Does not fill in the city or unit; that have to be done seperatly in
@@ -1893,126 +1998,61 @@
 {
   enum tile_terrain_type ttype, ttype_near[8];
   enum tile_special_type tspecial, tspecial_near[8];
-  int tileno, dir, i;
-  struct city *pcity;
+  int tileno, dir;
+  struct tile *ptile = map_get_tile(x, y);
+  struct city *pcity = ptile->city;
   struct drawn_sprite *save_sprs = sprs;
 
   *solid_bg = FALSE;
+  *dither_count = 0;
 
   if (tile_get_known(x, y) == TILE_UNKNOWN)
     return -1;
 
-  pcity = map_get_city(x, y);
-
   build_tile_data(x, y, &ttype, &tspecial, ttype_near, tspecial_near);
 
-  if (draw_terrain) {
-    if (is_ocean(ttype)) {
-      /* painted via coasts. */
-      const enum direction8 dirs[4] = {
-       DIR8_NORTHWEST, /* up */
-       DIR8_SOUTHEAST, /* down */
-       DIR8_SOUTHWEST, /* left */
-       DIR8_NORTHEAST /* right */
-      };
-      const int offsets[4][2] = {
-       {NORMAL_TILE_WIDTH / 4, 0},
-       {NORMAL_TILE_WIDTH / 4, NORMAL_TILE_HEIGHT / 2},
-       {0, NORMAL_TILE_HEIGHT / 4},
-       {NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 4},
-      };
-
-      *dither_count = 4;
-
-      /* put coasts */
-      for (i = 0; i < 4; i++) {
-       int array_index = ((!is_ocean(ttype_near[dir_ccw(dirs[i])]) ? 1 : 0)
-                          + (!is_ocean(ttype_near[dirs[i]]) ? 2 : 0)
-                          + (!is_ocean(ttype_near[dir_cw(dirs[i])])
-                             ? 4 : 0));
-
-       ADD_SPRITE(sprites.tx.coast_cape_iso[array_index][i],
-                  offsets[i][0], offsets[i][1]);
-      }
-
-      for (dir = 0; dir < 4; dir++) {
-       if (contains_special(tspecial_near[DIR4_TO_DIR8[dir]], S_RIVER)) {
-         ADD_SPRITE_SIMPLE(sprites.tx.river_outlet[dir]);
-       }
-      }
+  sprs += fill_terrain_sprite_array(sprs, ptile, ttype_near, dither_count);
 
-      if (draw_specials) {
-       if (contains_special(tspecial, S_SPECIAL_1)) {
-         ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->special[0]);
-       } else if (contains_special(tspecial, S_SPECIAL_2)) {
-         ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->special[1]);
-       }
-      }
-    } else {
-      *dither_count = 1;
-
-      if (sprites.terrain[ttype]->match_type == 0
-         || sprites.terrain[ttype]->is_layered) {
-       ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->base);
-      }
-
-      if (sprites.terrain[ttype]->match_type != 0) {
-       int match_type = sprites.terrain[ttype]->match_type;
-
-#define MATCH(dir) (sprites.terrain[ttype_near[(dir)]]->match_type)
-       tileno = INDEX_NSEW(MATCH(DIR8_NORTH) == match_type,
-                           MATCH(DIR8_SOUTH) == match_type,
-                           MATCH(DIR8_EAST) == match_type,
-                           MATCH(DIR8_WEST) == match_type);
-       ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->blend[tileno]);
-#undef MATCH
+  if (is_ocean(ttype)) {
+    for (dir = 0; dir < 4; dir++) {
+      if (contains_special(tspecial_near[DIR4_TO_DIR8[dir]], S_RIVER)) {
+       ADD_SPRITE_SIMPLE(sprites.tx.river_outlet[dir]);
       }
+    }
+  }
 
-      sprs += fill_irrigation_sprite_array(sprs, tspecial, tspecial_near,
+  sprs += fill_irrigation_sprite_array(sprs, tspecial, tspecial_near,
                                           pcity);
- 
-      if (contains_special(tspecial, S_RIVER)) {
-       tileno = INDEX_NSEW(contains_special(tspecial_near[DIR8_NORTH], S_RIVER)
-                           || is_ocean(ttype_near[DIR8_NORTH]),
-                           contains_special(tspecial_near[DIR8_SOUTH], S_RIVER)
-                           || is_ocean(ttype_near[DIR8_SOUTH]),
-                           contains_special(tspecial_near[DIR8_EAST], S_RIVER)
-                           || is_ocean(ttype_near[DIR8_EAST]),
-                           contains_special(tspecial_near[DIR8_WEST], S_RIVER)
-                           || is_ocean(ttype_near[DIR8_WEST]));
-       ADD_SPRITE_SIMPLE(sprites.tx.spec_river[tileno]);
-      }
-    }
 
-    /* Short-cut past dithering if all adjacent tiles are the same. */
-    if (ttype_near[DIR8_NORTH] == ttype
-       && ttype_near[DIR8_SOUTH] == ttype
-       && ttype_near[DIR8_EAST] == ttype
-       && ttype_near[DIR8_WEST] == ttype) {
-      *dither_count = 0;
+  if (draw_terrain) {
+    /* Draw rivers on top of irrigation. */
+    if (contains_special(tspecial, S_RIVER)) {
+      tileno = INDEX_NSEW(contains_special(tspecial_near[DIR8_NORTH], S_RIVER)
+                         || is_ocean(ttype_near[DIR8_NORTH]),
+                         contains_special(tspecial_near[DIR8_SOUTH], S_RIVER)
+                         || is_ocean(ttype_near[DIR8_SOUTH]),
+                         contains_special(tspecial_near[DIR8_EAST], S_RIVER)
+                         || is_ocean(ttype_near[DIR8_EAST]),
+                         contains_special(tspecial_near[DIR8_WEST], S_RIVER)
+                         || is_ocean(ttype_near[DIR8_WEST]));
+      ADD_SPRITE_SIMPLE(sprites.tx.spec_river[tileno]);
     }
   } else {
     *solid_bg = TRUE;
-    *dither_count = 0;
-
-    /* This call is duplicated because it is normally
-     * drawn underneath rivers. */
-    sprs += fill_irrigation_sprite_array(sprs, tspecial, tspecial_near,
-                                        pcity);
   }
   
-  if (!is_ocean(ttype)) {
-    sprs += fill_road_rail_sprite_array(sprs,
-                                       tspecial, tspecial_near, pcity);
+  sprs += fill_road_rail_sprite_array(sprs,
+                                     tspecial, tspecial_near, pcity);
 
-    if (draw_specials) {
-      if (contains_special(tspecial, S_SPECIAL_1)) {
-       ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->special[0]);
-      } else if (contains_special(tspecial, S_SPECIAL_2)) {
-       ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->special[1]);
-      }
+  if (draw_specials) {
+    if (contains_special(tspecial, S_SPECIAL_1)) {
+      ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->special[0]);
+    } else if (contains_special(tspecial, S_SPECIAL_2)) {
+      ADD_SPRITE_SIMPLE(sprites.terrain[ttype]->special[1]);
     }
-  
+  }
+
+  if (!is_ocean(ttype)) {
     if (contains_special(tspecial, S_FORTRESS) && draw_fortress_airbase) {
       ADD_SPRITE_SIMPLE(sprites.tx.fortress_back);
     }
@@ -2080,11 +2120,8 @@
 {
   enum tile_terrain_type ttype, ttype_near[8];
   enum tile_special_type tspecial, tspecial_near[8];
-
-  int dir;
-  int tileno;
+  int dir, tileno, dither_count;
   struct tile *ptile;
-  struct Sprite *mysprite;
   struct city *pcity;
   struct unit *pfocus;
   struct unit *punit;
@@ -2124,56 +2161,19 @@
   build_tile_data(abs_x0, abs_y0, 
                  &ttype, &tspecial, ttype_near, tspecial_near);
 
-  if (ptile->spec_sprite && (mysprite = load_sprite(ptile->spec_sprite))) {
-    freelog(LOG_DEBUG, "Using spec_sprite %s for %d,%d",
-           ptile->spec_sprite, abs_x0, abs_y0);
-  } else {
-    /* FIXME: doesn't support is_layered. */
-    if (sprites.terrain[ttype]->match_type == 0) {
-      mysprite = sprites.terrain[ttype]->base;
-    } else {
-      int match_type = sprites.terrain[ttype]->match_type;
+  sprs += fill_terrain_sprite_array(sprs, ptile, ttype_near, &dither_count);
 
-#define MATCH(dir) (sprites.terrain[ttype_near[(dir)]]->match_type)
-      tileno = INDEX_NSEW(MATCH(DIR8_NORTH) == match_type,
-                         MATCH(DIR8_SOUTH) == match_type,
-                         MATCH(DIR8_EAST) == match_type,
-                         MATCH(DIR8_WEST) == match_type);
-      mysprite = sprites.terrain[ttype]->blend[tileno];
-#undef MATCH
-    }
-  }
-
-  if (draw_terrain)
-    ADD_SPRITE_SIMPLE(mysprite);
-  else
+  if (!draw_terrain) {
     *solid_bg = TRUE;
-
-  if(is_ocean(ttype) && draw_terrain) {
-    int dir;
-
-    tileno = INDEX_NSEW(is_ocean(ttype_near[DIR8_NORTH])
-                       && is_ocean(ttype_near[DIR8_EAST])
-                       && !is_ocean(ttype_near[DIR8_NORTHEAST]),
-                       is_ocean(ttype_near[DIR8_SOUTH])
-                       && is_ocean(ttype_near[DIR8_WEST])
-                       && !is_ocean(ttype_near[DIR8_SOUTHWEST]),
-                       is_ocean(ttype_near[DIR8_EAST])
-                       && is_ocean(ttype_near[DIR8_SOUTH])
-                       && !is_ocean(ttype_near[DIR8_SOUTHEAST]),
-                       is_ocean(ttype_near[DIR8_NORTH])
-                       && is_ocean(ttype_near[DIR8_WEST])
-                       && !is_ocean(ttype_near[DIR8_NORTHWEST]));
-    if(tileno!=0)
-      ADD_SPRITE_SIMPLE(sprites.tx.coast_cape[tileno]);
+  }
 
+  if (is_ocean(ttype) && draw_terrain) {
     for (dir = 0; dir < 4; dir++) {
       if (contains_special(tspecial_near[DIR4_TO_DIR8[dir]], S_RIVER)) {
        ADD_SPRITE_SIMPLE(sprites.tx.river_outlet[dir]);
       }
     }
   }
-
   if (contains_special(tspecial, S_RIVER) && draw_terrain) {
     tileno = INDEX_NSEW(contains_special(tspecial_near[DIR8_NORTH], S_RIVER)
                        || is_ocean(ttype_near[DIR8_NORTH]),

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7497) new function fill_terrain_sprite_array, Jason Short <=