Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#2395) unification of tile_visible_and_not_on_border_ma
Home

[Freeciv-Dev] (PR#2395) unification of tile_visible_and_not_on_border_ma

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2395) unification of tile_visible_and_not_on_border_mapcanvas
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Sat, 23 Nov 2002 17:04:55 -0800
Reply-to: rt@xxxxxxxxxxxxxx

This patch moves tile_visible_and_not_on_border_mapcanvas() into 
mapview_common.

The code is quite straightforward, although it may be difficult to see 
that the logical expression is the same with all the "style" fixes that 
were necessary.

The current implementation of this function is quite poor.  I'm fairly 
certain the non-iso case has bugs even for the current topology, and it 
certainly won't generalize easily to different topologies.  But I've 
ignored all that for now.  I have added a header comment which explains 
this, and hopefully gives a hint as to a better implementation.

jason

Index: client//mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.18
diff -u -r1.18 mapview_common.c
--- client//mapview_common.c    2002/11/23 18:12:58     1.18
+++ client//mapview_common.c    2002/11/24 00:57:55
@@ -327,6 +327,55 @@
 }
 
 /**************************************************************************
+  Return TRUE iff the given map position has a tile visible within the
+  interior of the map canvas. This information is used to determine when
+  we need to recenter the map canvas.
+
+  The logic of this function is simple: if a tile is within 1.5 tiles
+  of a border of the canvas and that border is not aligned with the
+  edge of the map, then the tile is on the "border" of the map canvas.
+
+  This function is only correct for the current topology.
+**************************************************************************/
+bool tile_visible_and_not_on_border_mapcanvas(int map_x, int map_y)
+{
+  int map_view_x0, map_view_y0, map_win_width, map_win_height;
+  int map_tile_width, map_tile_height;
+
+  get_mapview_dimensions(&map_view_x0, &map_view_y0,
+                        &map_win_width, &map_win_height);
+  map_tile_width = (map_win_width - 1) / NORMAL_TILE_WIDTH + 1;
+  map_tile_height = (map_win_height - 1) / NORMAL_TILE_HEIGHT + 1;
+
+  if (is_isometric) {
+    int canvas_x, canvas_y;
+
+    /* The border consists of the half-tile on the left and top of the
+     * screen, and the 1.5-tiles on the right and bottom. */
+    return (get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y)
+           && canvas_x > NORMAL_TILE_WIDTH / 2
+           && canvas_x < map_win_width - 3 * NORMAL_TILE_WIDTH / 2
+           && canvas_y >= NORMAL_TILE_HEIGHT
+           && canvas_y < map_win_height - 3 * NORMAL_TILE_HEIGHT / 2);
+  } else {
+    /* The border consists of the two tiles on the edge of the
+     * mapview.  But we take into account the border of the map. */
+    return ((map_y >= map_view_y0 + 2 || (map_y >= map_view_y0
+                                         && map_view_y0 == 0))
+           && (map_y < map_view_y0 + map_tile_height - 2
+               || (map_y < map_view_y0 + map_tile_height
+                   && (map_view_y0 + map_tile_height
+                       - EXTRA_BOTTOM_ROW == map.ysize)))
+           && ((map_x >= map_view_x0 + 2
+                && map_x < map_view_x0 + map_tile_width - 2)
+               || (map_x + map.xsize >= map_view_x0 + 2
+                   && (map_x + map.xsize
+                       < map_view_x0 + map_tile_width - 2))));
+  }
+}
+
+
+/**************************************************************************
  Update (only) the visible part of the map
 **************************************************************************/
 void update_map_canvas_visible(void)
Index: client//mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.12
diff -u -r1.12 mapview_common.h
--- client//mapview_common.h    2002/11/23 18:12:58     1.12
+++ client//mapview_common.h    2002/11/24 00:57:55
@@ -55,6 +55,7 @@
                                int map_view_map_height);
 
 bool tile_visible_mapcanvas(int map_x, int map_y);
+bool tile_visible_and_not_on_border_mapcanvas(int map_x, int map_y);
 
 void update_map_canvas_visible(void);
                                
Index: client//gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.135
diff -u -r1.135 mapview.c
--- client//gui-gtk/mapview.c   2002/11/23 18:12:58     1.135
+++ client//gui-gtk/mapview.c   2002/11/24 00:57:56
@@ -516,33 +516,6 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-bool tile_visible_and_not_on_border_mapcanvas(int x, int y)
-{
-  if (is_isometric) {
-    int canvas_x, canvas_y;
-    int width, height;
-    gdk_window_get_size(map_canvas->window, &width, &height);
-    get_canvas_xy(x, y, &canvas_x, &canvas_y);
-
-    return canvas_x > NORMAL_TILE_WIDTH/2
-      && canvas_x < (width - 3*NORMAL_TILE_WIDTH/2)
-      && canvas_y >= NORMAL_TILE_HEIGHT
-      && canvas_y < height - 3 * NORMAL_TILE_HEIGHT/2;
-  } else {
-    return ((y>=map_view_y0+2 || (y >= map_view_y0 && map_view_y0 == 0))
-           && (y<map_view_y0+map_canvas_store_theight-2 ||
-               (y<map_view_y0+map_canvas_store_theight &&
-                map_view_y0 + map_canvas_store_theight-EXTRA_BOTTOM_ROW == 
map.ysize))
-           && ((x>=map_view_x0+2 && x<map_view_x0+map_canvas_store_twidth-2) ||
-               (x+map.xsize>=map_view_x0+2
-                && x+map.xsize<map_view_x0+map_canvas_store_twidth-2)));
-  }
-}
-
-
-/**************************************************************************
 Animates punit's "smooth" move from (x0,y0) to (x0+dx,y0+dy).
 Note: Works only for adjacent-square moves.
 (Tiles need not be square.)
Index: client//gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.23
diff -u -r1.23 mapview.c
--- client//gui-gtk-2.0/mapview.c       2002/11/23 18:12:59     1.23
+++ client//gui-gtk-2.0/mapview.c       2002/11/24 00:57:57
@@ -518,33 +518,6 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-bool tile_visible_and_not_on_border_mapcanvas(int x, int y)
-{
-  if (is_isometric) {
-    int canvas_x, canvas_y;
-    int width, height;
-    gdk_window_get_size(map_canvas->window, &width, &height);
-    get_canvas_xy(x, y, &canvas_x, &canvas_y);
-
-    return canvas_x > NORMAL_TILE_WIDTH/2
-      && canvas_x < (width - 3*NORMAL_TILE_WIDTH/2)
-      && canvas_y >= NORMAL_TILE_HEIGHT
-      && canvas_y < height - 3 * NORMAL_TILE_HEIGHT/2;
-  } else {
-    return ((y>=map_view_y0+2 || (y >= map_view_y0 && map_view_y0 == 0))
-           && (y<map_view_y0+map_canvas_store_theight-2 ||
-               (y<map_view_y0+map_canvas_store_theight &&
-                map_view_y0 + map_canvas_store_theight-EXTRA_BOTTOM_ROW == 
map.ysize))
-           && ((x>=map_view_x0+2 && x<map_view_x0+map_canvas_store_twidth-2) ||
-               (x+map.xsize>=map_view_x0+2
-                && x+map.xsize<map_view_x0+map_canvas_store_twidth-2)));
-  }
-}
-
-
-/**************************************************************************
 Animates punit's "smooth" move from (x0,y0) to (x0+dx,y0+dy).
 Note: Works only for adjacent-square moves.
 (Tiles need not be square.)
Index: client//gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.48
diff -u -r1.48 mapview.c
--- client//gui-mui/mapview.c   2002/11/23 18:12:59     1.48
+++ client//gui-mui/mapview.c   2002/11/24 00:57:57
@@ -363,39 +363,6 @@
 }
 
 /**************************************************************************
- GUI Independ (with new access functions)
-**************************************************************************/
-bool tile_visible_and_not_on_border_mapcanvas(int x, int y)
-{
-  if (is_isometric) {
-    int canvas_x, canvas_y;
-    int width, height;
-    width = _mwidth(main_map_area);
-    height = _mheight(main_map_area);
-
-    get_canvas_xy(x, y, &canvas_x, &canvas_y);
-
-    return canvas_x > NORMAL_TILE_WIDTH/2
-      && canvas_x < (width - 3*NORMAL_TILE_WIDTH/2)
-      && canvas_y >= NORMAL_TILE_HEIGHT
-      && canvas_y < height - 3 * NORMAL_TILE_HEIGHT/2;
-  } else {
-    int map_view_x0 = get_map_x_start();
-    int map_view_y0 = get_map_y_start();
-    int map_canvas_store_twidth = get_map_x_visible();
-    int map_canvas_store_theight = get_map_y_visible();
-
-    return ((y>=map_view_y0+2 || (y >= map_view_y0 && map_view_y0 == 0))
-           && (y<map_view_y0+map_canvas_store_theight-2 ||
-               (y<map_view_y0+map_canvas_store_theight &&
-                map_view_y0 + map_canvas_store_theight-EXTRA_BOTTOM_ROW == 
map.ysize))
-           && ((x>=map_view_x0+2 && x<map_view_x0+map_canvas_store_twidth-2) ||
-               (x+map.xsize>=map_view_x0+2
-                && x+map.xsize<map_view_x0+map_canvas_store_twidth-2)));
-  }
-}
-
-/**************************************************************************
 ...
 **************************************************************************/
 void move_unit_map_canvas(struct unit *punit, int x0, int y0, int dx, int dy)
Index: client//gui-stub/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapview.c,v
retrieving revision 1.18
diff -u -r1.18 mapview.c
--- client//gui-stub/mapview.c  2002/11/23 18:12:59     1.18
+++ client//gui-stub/mapview.c  2002/11/24 00:57:57
@@ -22,12 +22,6 @@
   *map_view_pixel_height = canvas_height;
 }
 
-bool tile_visible_and_not_on_border_mapcanvas(int x, int y)
-{
-       /* PORTME */
-       return 0;
-}
-
 void
 update_info_label(void)
 {
Index: client//gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.37
diff -u -r1.37 mapview.c
--- client//gui-win32/mapview.c 2002/11/23 18:12:59     1.37
+++ client//gui-win32/mapview.c 2002/11/24 00:57:58
@@ -457,32 +457,6 @@
 /**************************************************************************
 
 **************************************************************************/
-bool tile_visible_and_not_on_border_mapcanvas(int x, int y)
-{
-  if (is_isometric) {
-    int canvas_x, canvas_y;
-       
-    get_canvas_xy(x, y, &canvas_x, &canvas_y);
-
-    return canvas_x > NORMAL_TILE_WIDTH/2
-      && canvas_x < (map_win_width - 3*NORMAL_TILE_WIDTH/2)
-      && canvas_y >= NORMAL_TILE_HEIGHT
-      && canvas_y < map_win_height - 3 * NORMAL_TILE_HEIGHT/2;
-
-  } else {
-    return ((y>=map_view_y+2 || (y >= map_view_y && map_view_y == 0))
-           && (y<map_view_y+map_view_height-2 ||
-               (y<map_view_y+map_view_height &&
-                map_view_y + map_view_height-EXTRA_BOTTOM_ROW == map.ysize))
-           && ((x>=map_view_x+2 && x<map_view_x+map_view_width-2) ||
-               (x+map.xsize>=map_view_x+2
-                && x+map.xsize<map_view_x+map_view_width-2)));
-  }
-}
-
-/**************************************************************************
-
-**************************************************************************/
 static void draw_rates(HDC hdc)
 {
   int d;
Index: client//gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.108
diff -u -r1.108 mapview.c
--- client//gui-xaw/mapview.c   2002/11/23 18:12:59     1.108
+++ client//gui-xaw/mapview.c   2002/11/24 00:57:58
@@ -343,20 +343,6 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-bool tile_visible_and_not_on_border_mapcanvas(int x, int y)
-{
-  return ((y>=map_view_y0+2 || (y >= map_view_y0 && map_view_y0 == 0))
-         && (y<map_view_y0+map_canvas_store_theight-2 ||
-             (y<map_view_y0+map_canvas_store_theight &&
-              map_view_y0 + map_canvas_store_theight-EXTRA_BOTTOM_ROW == 
map.ysize))
-         && ((x>=map_view_x0+2 && x<map_view_x0+map_canvas_store_twidth-2) ||
-             (x+map.xsize>=map_view_x0+2
-              && x+map.xsize<map_view_x0+map_canvas_store_twidth-2)));
-}
-
-/**************************************************************************
 Animates punit's "smooth" move from (x0,y0) to (x0+dx,y0+dy).
 Note: Works only for adjacent-square moves.
 (Tiles need not be square.)
Index: client//include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.24
diff -u -r1.24 mapview_g.h
--- client//include/mapview_g.h 2002/11/23 18:12:59     1.24
+++ client//include/mapview_g.h 2002/11/24 00:57:59
@@ -24,8 +24,6 @@
                            int *map_view_pixel_width,
                            int *map_view_pixel_height);
 
-bool tile_visible_and_not_on_border_mapcanvas(int x, int y);
-
 void update_info_label(void);
 void update_unit_info_label(struct unit *punit);
 void update_timeout_label(void);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2395) unification of tile_visible_and_not_on_border_mapcanvas, Jason Short via RT <=