Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12404) remove automated boundary drawing code
Home

[Freeciv-Dev] (PR#12404) remove automated boundary drawing code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12404) remove automated boundary drawing code
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 2 Mar 2005 13:43:56 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12404 >

This patch removes the code that draws "boundaries" (grids, borders, 
outlines, selections, frames) automatically.  Instead the grid sprites 
become manditory in the tileset.

This removes 400 lines of not very good code.  Instead we have the bit 
of code already added to do this drawing via sprites, plus of course the 
extra sprite files that are already in the tilesets.

-jason

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.64
diff -u -r1.64 citydlg_common.c
--- client/citydlg_common.c     28 Feb 2005 04:01:52 -0000      1.64
+++ client/citydlg_common.c     2 Mar 2005 21:22:54 -0000
@@ -203,10 +203,6 @@
        put_city_tile_output(pcity, city_x, city_y,
                             pcanvas, canvas_x, canvas_y);
       }
-      if (!sprites.grid.main[EDGE_NS]
-         && pcity->city_map[city_x][city_y] == C_TILE_UNAVAILABLE) {
-       put_red_frame_tile(pcanvas, canvas_x, canvas_y);
-      }
     }
   } citydlg_iterate_end;
 }
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.203
diff -u -r1.203 mapview_common.c
--- client/mapview_common.c     2 Mar 2005 19:00:33 -0000       1.203
+++ client/mapview_common.c     2 Mar 2005 21:22:54 -0000
@@ -60,10 +60,6 @@
 static void dirty_overview(void);
 static void flush_dirty_overview(void);
 
-static void tile_draw_grid(struct canvas *pcanvas, const struct tile *ptile,
-                          int canvas_x, int canvas_y,
-                          const struct city *citymode);
-
 enum update_type {
   /* Masks */
   UPDATE_NONE = 0,
@@ -941,13 +937,6 @@
                               pdrawn[i].data.sprite.sprite);
       }
       break;
-    case DRAWN_GRID:
-      /*** Grid (map grid, borders, coastline, etc.) ***/
-      tile_draw_grid(pcanvas,
-                    pdrawn[i].data.grid.tile,
-                    canvas_x, canvas_y,
-                    pdrawn[i].data.grid.citymode);
-      break;
     case DRAWN_BG:
       /*** Background color. ***/
       if (tileset_is_isometric()) {
@@ -1148,184 +1137,6 @@
 }
 
 /****************************************************************************
-  Return the vertices of the given edge of the tile.  This will return
-  FALSE if the edge doesn't exist (or if it does exist but is part of an
-  adjacent tile).
-
-  The result is intended to be used to draw lines via canvas_put_line.
-
-  inset specifies how many pixels inward the boundary is to be inset.  This
-  is generally 0 or 1.  (Note that this doesn't work particularly well in
-  iso-view.)
-
-  width specifies the width of the boundary - generally 1 or 2.  For
-  instance if the boundary is 2 pixels wide then the right and bottom
-  positions must be translated so it's drawn in the right location.
-****************************************************************************/
-static bool get_tile_boundaries(enum direction8 dir,
-                               int inset, int width,
-                               int *start_x, int *start_y,
-                               int *end_x, int *end_y)
-{
-  const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
-  const int HW = tileset_hex_width(), HH = tileset_hex_height();
-  const int overlap = (width > 1) ? 1 : 0;
-
-  assert(inset >= 0);
-  assert(width >= 1);
-
-  width--;
-
-  /* Note that the boundary (with inset 0) may actually cover some adjacent
-   * tiles, since the left boundary for this tile is equivalent to the right
-   * boundary for the tile to our left.  The north and west boundaries will
-   * be on this tile while the south and east boundaries must be drawn as
-   * part of the adjacent tiles. */
-
-  /* "Width" and the "overlap" value: if a width of 1 is specified, then
-   * boundaries of adjacent tiles are assumed to overlap and no extra
-   * adjustment need be done.  However if width > 1 then not only do we have
-   * to account for the width in calculating the position, but we also
-   * assume that the caller does *not* want the boundaries to overlap with
-   * adjacent tiles (note that if they did then individual lines would
-   * cover multiple tiles, which would be tricky).
-   *
-   * The answer is to use two variables: width and overlap.
-   *
-   * width is the offset that must be done to account for the width of the
-   * line.  Since lines are drawn upward and to the left of their origin,
-   * we must displace the line by (width - 1) pixels in this direction.  And
-   * for national borders we must do this in a consistent way, so that
-   * adjacent borders will line up.  Thus in iso-view this displacement is
-   * done entirely in the Y dimension.
-   *
-   * overlap is a value that accountes for the non-overlapping of the
-   * boundaries.  If boundaries don't overlap then we have to pull the
-   * bottom and right boundaries off by 1 pixel.  Like the width adjustment
-   * this must be done in a consistent way in iso-view.
-   *
-   * As long as width==2 this difference is negligible, since the width
-   * adjustment and the overlap adjustment are both 1.
-   */
-
-  if (tileset_is_isometric()) {
-    switch (dir) {
-    case DIR8_NORTH:
-      /* Top right. */
-      *start_x = (W + HW) / 2;
-      *end_x = W - HW / 2 - inset;
-      *start_y = HH / 2 + inset + width;
-      *end_y = (H - HH) / 2 + width;
-      return TRUE;
-    case DIR8_SOUTH:
-      /* Bottom left. */
-      *start_x = (W - HW) / 2;
-      *end_x = HW / 2 + inset;
-      *start_y = H - HH / 2 - inset - overlap;
-      *end_y = (H + HH) / 2 - overlap;
-      return inset + overlap > 0;
-    case DIR8_EAST:
-      /* Bottom right. */
-      *start_x = W - HW / 2 - inset;
-      *end_x = (W + HW) / 2;
-      *start_y = (H + HH) / 2 - overlap;
-      *end_y = H - HH / 2 - inset - overlap;
-      return inset + overlap > 0;
-    case DIR8_WEST:
-      /* Top left. */
-      *start_x = HW / 2 + inset;
-      *end_x = (W - HW) / 2;
-      *start_y = (H - HH) / 2 + width;
-      *end_y = HH / 2 + inset + width;
-      return TRUE;
-    case DIR8_NORTHEAST:
-      *start_x = *end_x = W - HW / 2 - inset - overlap;
-      *start_y = (H - HH) / 2;
-      *end_y = (H + HH) / 2;
-      return HH > 0;
-    case DIR8_SOUTHEAST:
-      *start_x = (W + HW) / 2;
-      *end_x = (W - HW) / 2;
-      *start_y = *end_y = H - HH / 2 - inset - overlap;
-      return HW > 0;
-    case DIR8_SOUTHWEST:
-      *start_x = *end_x = HW / 2 + inset + width;
-      *start_y = (H + HH) / 2;
-      *end_y = (H - HH) / 2;
-      return HH > 0;
-    case DIR8_NORTHWEST:
-      *start_x = (W - HW) / 2;
-      *end_x = (W + HW) / 2;
-      *start_y = *end_y = HH / 2 + inset + width;
-      return HW > 0;
-    }
-  } else {
-    switch (dir) {
-    case DIR8_NORTH:
-      *start_x = inset;
-      *end_x = W - inset;
-      *start_y = *end_y = inset + width;
-      return TRUE;
-    case DIR8_SOUTH:
-      *start_x = inset;
-      *end_x = W - inset;
-      *start_y = *end_y = H - inset - overlap;
-      return inset + overlap > 0;
-    case DIR8_EAST:
-      *start_x = *end_x = W - inset - overlap;
-      *start_y = inset;
-      *end_y = H - inset;
-      return inset + overlap > 0;
-    case DIR8_WEST:
-      *start_x = *end_x = inset + width;
-      *start_y = inset;
-      *end_y = H - inset;
-      return TRUE;
-    case DIR8_NORTHEAST:
-    case DIR8_SOUTHEAST:
-    case DIR8_SOUTHWEST:
-    case DIR8_NORTHWEST:
-      return FALSE;
-    }
-  }
-
-  assert(0);
-  return FALSE;
-}
-
-
-/****************************************************************************
-  Draw a red frame around the tile.  (canvas_x, canvas_y) is the tile origin.
-****************************************************************************/
-void put_red_frame_tile(struct canvas *pcanvas,
-                       int canvas_x, int canvas_y)
-{
-  enum direction8 dir;
-
-  for (dir = 0; dir < 8; dir++) {
-    int start_x, start_y, end_x, end_y;
-
-    /* We just draw an extra red line with an inset of 1 from the tile
-     * boundary.  If the map grid is also drawn, it will be red as well
-     * giving a width-2 frame (it may not line up perfectly in iso-view).
-     * If not then the inset allows the user to distinguish which tile
-     * is unavailable.
-     *
-     * Since the frames are drawn only for the citydlg and are put on
-     * top of everything else, we don't have to worry about overlapping
-     * tiles covering them up even in iso-view.  (See comments in
-     * city_dialog_redraw_map and tile_draw_borders.) */
-    if (get_tile_boundaries(dir, 1, 1,
-                           &start_x, &start_y, &end_x, &end_y)) {
-      canvas_put_line(pcanvas, COLOR_STD_RED, LINE_NORMAL,
-                     canvas_x + start_x, canvas_y + start_y,
-                     end_x - start_x, end_y - start_y);
-
-    }
-  }
-}
-
-/****************************************************************************
   Animate the nuke explosion at map(x, y).
 ****************************************************************************/
 void put_nuke_mushroom_pixmaps(struct tile *ptile)
@@ -1360,228 +1171,6 @@
 }
 
 /**************************************************************************
-   Draw the borders of the given map tile at the given canvas position.
-**************************************************************************/
-static void tile_draw_borders(struct canvas *pcanvas,
-                             const struct tile *ptile,
-                             int canvas_x, int canvas_y)
-{
-  struct player *this_owner = map_get_owner(ptile), *adjc_owner;
-  int start_x, start_y, end_x, end_y;
-
-  if (!draw_borders || game.borders == 0) {
-    return;
-  }
-
-  if (tileset_is_isometric()) {
-    /* Isometric must be done differently or the borders will get overwritten
-     * by other terrain graphics.  (This is because the tileset sprites'
-     * edges don't line up exactly with the mathematical calculation of the
-     * edges of the tiles.)  Of course this means the borders may
-     * themselves overwrite units and cities.  The only real solution is
-     * to do the drawing in layers rather than per-tile.  In the meantime
-     * we use this hack. */
-    adjc_dir_iterate(ptile, adjc_tile, dir) {
-      if ((dir == DIR8_WEST || dir == DIR8_NORTHWEST
-          || dir == DIR8_NORTH || dir == DIR8_SOUTHWEST)
-         && get_tile_boundaries(dir, 0, BORDER_WIDTH,
-                                 &start_x, &start_y, &end_x, &end_y)
-         && tile_get_known(adjc_tile) != TILE_UNKNOWN
-         && this_owner != (adjc_owner = map_get_owner(adjc_tile))) {
-       if (this_owner) {
-         canvas_put_line(pcanvas, player_color(this_owner), LINE_BORDER,
-                         canvas_x + start_x, canvas_y + start_y,
-                         end_x - start_x, end_y - start_y);
-       }
-       if (adjc_owner) {
-         canvas_put_line(pcanvas, player_color(adjc_owner), LINE_BORDER,
-                         canvas_x + start_x,
-                         canvas_y + start_y - BORDER_WIDTH,
-                         end_x - start_x, end_y - start_y);
-       }
-      }
-    } adjc_dir_iterate_end;
-  } else {
-    if (!this_owner) {
-      return;
-    }
-    adjc_dir_iterate(ptile, adjc_tile, dir) {
-      if (get_tile_boundaries(dir, 0, BORDER_WIDTH,
-                             &start_x, &start_y, &end_x, &end_y)
-         && tile_get_known(adjc_tile) != TILE_UNKNOWN
-         && this_owner != (adjc_owner = map_get_owner(adjc_tile))) {
-       canvas_put_line(pcanvas, player_color(this_owner), LINE_BORDER,
-                       canvas_x + start_x, canvas_y + start_y,
-                       end_x - start_x, end_y - start_y);
-      }
-    } adjc_dir_iterate_end;
-  }
-}
-
-/****************************************************************************
-  Return TRUE if the tile is within the city radius of one of the player's
-  cities, and can be worked by the player.
-****************************************************************************/
-static bool player_workable_and_in_city_radius(const struct player *pplayer,
-                                              const struct tile *ptile)
-{
-  struct player *powner = map_get_owner(ptile);
-
-  /* Borders are considered but not units.  This function is intended to be
-   * used by the drawing code not the backend. */
-  if (powner && powner != pplayer) {
-    return FALSE;
-  }
-  return player_in_city_radius(pplayer, ptile);
-}
-
-/****************************************************************************
-   Draw the map grid around the given map tile at the given canvas position.
-****************************************************************************/
-static void tile_draw_map_grid(struct canvas *pcanvas,
-                              const struct tile *ptile,
-                              int canvas_x, int canvas_y)
-{
-  enum direction8 dir;
-
-  if (draw_map_grid) {
-    for (dir = 0; dir < 8; dir++) {
-      int start_x, start_y, end_x, end_y;
-
-      /* Draw the grid.  Every edge gets one line; we just have to
-       * check what color. */
-      if (get_tile_boundaries(dir, 0, 1,
-                             &start_x, &start_y, &end_x, &end_y)) {
-       canvas_put_line(pcanvas,
-                       get_grid_color(ptile, dir),
-                       LINE_NORMAL,
-                       canvas_x + start_x, canvas_y + start_y,
-                       end_x - start_x, end_y - start_y);
-      }
-    }
-  } else if (draw_city_outlines) {
-    /* Draw only the outlines of cities and setter citymap areas.
-     * Here we have to check if each edge presents the boundary of
-     * a citymap and non-citymap area.  City areas are edged in white,
-     * settler citymap areas in red and underneath.  We also consider
-     * any tile in enemy territory not to be part of the citys'
-     * citymaps (though they are counted for settler citymaps). */
-    for (dir = 0; dir < 8; dir++) {
-      int start_x, start_y, end_x, end_y, dummy_x, dummy_y;
-      struct tile *tile2 = mapstep(ptile, dir);
-      struct unit *pfocus;
-      enum color_std color = COLOR_STD_LAST;
-
-      if (tile2
-         && get_tile_boundaries(dir, 0, 1,
-                                &start_x, &start_y, &end_x, &end_y)) {
-       if (XOR(player_workable_and_in_city_radius(game.player_ptr, ptile),
-               player_workable_and_in_city_radius(game.player_ptr, tile2))) {
-         color = COLOR_STD_WHITE;
-       } else if ((pfocus = get_unit_in_focus())
-                  && unit_flag(pfocus, F_CITIES)
-                  && city_can_be_built_here(pfocus->tile, pfocus)
-                  && XOR(base_map_to_city_map(&dummy_x, &dummy_y,
-                                              pfocus->tile, ptile),
-                         base_map_to_city_map(&dummy_x, &dummy_y,
-                                              pfocus->tile, tile2))) {
-         color = COLOR_STD_RED;
-       }
-       if (color != COLOR_STD_LAST) {
-         canvas_put_line(pcanvas, color, LINE_NORMAL,
-                         canvas_x + start_x, canvas_y + start_y,
-                         end_x - start_x, end_y - start_y);
-       }
-      }
-    }
-  }
-}
-
-/****************************************************************************
-  Draw the coastline of the given map tile at the given canvas position.
-
-  If the map grid is drawn this will cover it up.
-****************************************************************************/
-static void tile_draw_coastline(struct canvas *pcanvas,
-                               const struct tile *ptile,
-                               int canvas_x, int canvas_y)
-{
-  Terrain_type_id t1 = map_get_terrain(ptile), t2;
-
-  if (!draw_coastline || draw_terrain || t1 == T_UNKNOWN) {
-    return;
-  }
-
-  adjc_dir_iterate(ptile, adjc_tile, dir) {
-    int start_x, start_y, end_x, end_y;
-
-    if (get_tile_boundaries(dir, 0, 1,
-                           &start_x, &start_y, &end_x, &end_y)) {
-      t2 = map_get_terrain(adjc_tile);
-      if (t2 != T_UNKNOWN && (is_ocean(t1) ^ is_ocean(t2))) {
-       canvas_put_line(pcanvas, COLOR_STD_OCEAN, LINE_NORMAL,
-                       canvas_x + start_x, canvas_y + start_y,
-                       end_x - start_x, end_y - start_y);
-      }
-    }
-  } adjc_dir_iterate_end;
-}
-
-/****************************************************************************
-   Draw the selection rectangle the given map tile at the given canvas
-   position.
-****************************************************************************/
-static void tile_draw_selection(struct canvas *pcanvas,
-                               const struct tile *ptile,
-                               int canvas_x, int canvas_y, bool citymode)
-{
-  const int inset = (tileset_is_isometric() ? 0 : 1);
-  enum direction8 dir;
-
-  if (citymode) {
-    return;
-  }
-
-  for (dir = 0; dir < 8; dir++) {
-    int start_x, start_y, end_x, end_y;
-    struct tile *adjc_tile;
-
-    /* In non-iso view we draw the rectangle with an inset of 1.  This makes
-     * it easy to distinguish from the map grid.
-     *
-     * In iso-view the inset doesn't work perfectly (see comments about
-     * this elsewhere) so we draw without an inset.  This may cover up the
-     * map grid if it is drawn. */
-    if (get_tile_boundaries(dir, inset, 1,
-                           &start_x, &start_y, &end_x, &end_y)) {
-      if (map_deco[ptile->index].hilite == HILITE_CITY
-         || (tileset_is_isometric()
-             && (adjc_tile = mapstep(ptile, dir))
-             && map_deco[adjc_tile->index].hilite == HILITE_CITY)) {
-       canvas_put_line(pcanvas, COLOR_STD_YELLOW, LINE_NORMAL,
-                       canvas_x + start_x, canvas_y + start_y,
-                       end_x - start_x, end_y - start_y);
-      }
-    }
-  }
-}
-
-
-/****************************************************************************
-   Draw the grid lines of the given map tile at the given canvas position
-   in isometric view.  (This include the map grid, borders, and coastline).
-****************************************************************************/
-static void tile_draw_grid(struct canvas *pcanvas, const struct tile *ptile,
-                          int canvas_x, int canvas_y,
-                          const struct city *citymode)
-{
-  tile_draw_map_grid(pcanvas, ptile, canvas_x, canvas_y);
-  tile_draw_borders(pcanvas, ptile, canvas_x, canvas_y);
-  tile_draw_coastline(pcanvas, ptile, canvas_x, canvas_y);
-  tile_draw_selection(pcanvas, ptile, canvas_x, canvas_y, citymode);
-}
-
-/**************************************************************************
   Draw some or all of a tile onto the canvas.
 **************************************************************************/
 static void put_one_tile(struct canvas *pcanvas, enum mapview_layer layer,
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.101
diff -u -r1.101 mapview_common.h
--- client/mapview_common.h     28 Feb 2005 20:24:38 -0000      1.101
+++ client/mapview_common.h     2 Mar 2005 21:22:54 -0000
@@ -262,8 +262,6 @@
                            int canvas_x, int canvas_y);
 void toggle_city_color(struct city *pcity);
 void toggle_unit_color(struct unit *punit);
-void put_red_frame_tile(struct canvas *pcanvas,
-                       int canvas_x, int canvas_y);
 
 void put_nuke_mushroom_pixmaps(struct tile *ptile);
 
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.253
diff -u -r1.253 tilespec.c
--- client/tilespec.c   2 Mar 2005 19:00:33 -0000       1.253
+++ client/tilespec.c   2 Mar 2005 21:22:55 -0000
@@ -1593,7 +1593,7 @@
     sprites.city.unworked_tile_overlay.p[i] = unworked;
   }
 
-  if (load_sprite("grid.main.ns")) {
+  {
     SET_SPRITE(grid.unavailable, "grid.unavailable");
 
     for (i = 0; i < EDGE_COUNT; i++) {
@@ -2926,12 +2926,7 @@
 {
   struct drawn_sprite *saved_sprs = sprs;
 
-  if (!sprites.grid.main[EDGE_NS]) {
-    if (ptile && tile_get_known(ptile) != TILE_UNKNOWN) {
-      /* Add grid.  In classic view this is done later. */
-      ADD_GRID(ptile, citymode);
-    }
-  } else if (pedge) {
+  if (pedge) {
     bool known[NUM_EDGE_TILES], city[NUM_EDGE_TILES];
     bool unit[NUM_EDGE_TILES], worked[NUM_EDGE_TILES];
     int i;
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.116
diff -u -r1.116 tilespec.h
--- client/tilespec.h   2 Mar 2005 19:00:34 -0000       1.116
+++ client/tilespec.h   2 Mar 2005 21:22:55 -0000
@@ -50,7 +50,6 @@
 struct drawn_sprite {
   enum {
     DRAWN_SPRITE,      /* Draw a sprite. */
-    DRAWN_GRID,                /* Draw the map grid now. */
     DRAWN_BG            /* Draw a solid BG. */
   } type;
 
@@ -68,11 +67,6 @@
     } sprite;
 
     struct {
-      const struct tile *tile;
-      const struct city *citymode;
-    } grid;
-
-    struct {
       enum color_std color;
     } bg;
   } data;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12404) remove automated boundary drawing code, Jason Short <=