Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8627) best overview for iso-maps
Home

[Freeciv-Dev] (PR#8627) best overview for iso-maps

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8627) best overview for iso-maps
From: "Marcelo Burda" <mburda@xxxxxxxxx>
Date: Tue, 11 May 2004 13:52:22 -0700
Reply-to: rt@xxxxxxxxxxx

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

> [jdorje - Mar. Mai. 11 04:37:36 2004]:
> 
> Marcelo Burda wrote:
> > <URL: http://rt.freeciv.org/Ticket/Display.html?id=8627 >
> >
> > This is the cliped version where we cut off half tile left and right
> when no wraps,
> >  Finaly i am very happy about this option!!
> 
> 
> One final change I want.  In several places you hard code
> 
>     tile_width = topo_has_flag(TF_ISO) ? 2 : 1
> 
> can you put this into map.h as well:
> 
>    #define NATURAL_TILE_WIDTH (topo_has_flag(TF_ISO) ? 2 : 1)
>    #define NATURAL_TILE_HEIGHT 1
> 
> and use NATURAL_TILE_HEIGHT in the same places you use
> NATURAL_TILE_WIDTH.
i am done any other point as you ask me, but there i am define
 OVERVIEW_TILE_SIZE in tilespec.[ch]
and 
#define OVERVIEW_TILE_WIDTH ((topo_has_flag(TF_ISO) ? 2 :
1)*OVERVIEW_TILE_SIZE)
#define OVERVIEW_TILE_HEIGHT OVERVIEW_TILE_SIZE
in map.h
> 
> jason
> 
overview_tuning4.diff has a litle bug get this one
Marcelo

diff -ruN -Xdiff_ignore freeciv/client/mapview_common.c 
freeciv_/client/mapview_common.c
--- freeciv/client/mapview_common.c     2004-05-11 18:42:50.000000000 +0200
+++ freeciv_/client/mapview_common.c    2004-05-12 00:46:58.000000000 +0200
@@ -1940,8 +1940,8 @@
 
   {
     struct canvas *src = overview.store;
-    int x = overview.map_x0 * OVERVIEW_TILE_WIDTH;
-    int y = overview.map_y0 * OVERVIEW_TILE_HEIGHT;
+    int x = overview.map_x0 * OVERVIEW_TILE_SIZE;
+    int y = overview.map_y0 * OVERVIEW_TILE_SIZE;
     int ix = overview.width - x;
     int iy = overview.height - y;
 
@@ -1994,23 +1994,24 @@
 **************************************************************************/
 static void center_tile_overviewcanvas(int map_x, int map_y)
 {
-  /* The overview coordinates are equivalent to native coordinates. */
-  map_to_native_pos(&map_x, &map_y, map_x, map_y);
+  /* The overview coordinates are equivalent to natural coordinates. */
+  do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) {
 
-  /* NOTE: this embeds the map wrapping in the overview code.  This is
-   * basically necessary for the overview to be efficiently
-   * updated. */
-  if (topo_has_flag(TF_WRAPX)) {
-    overview.map_x0 = FC_WRAP(map_x - map.xsize / 2, map.xsize);
-  } else {
-    overview.map_x0 = 0;
-  }
-  if (topo_has_flag(TF_WRAPY)) {
-    overview.map_y0 = FC_WRAP(map_y - map.ysize / 2, map.ysize);
-  } else {
-    overview.map_y0 = 0;
-  }
-  redraw_overview();
+    /* NOTE: this embeds the map wrapping in the overview code.  This is
+     * basically necessary for the overview to be efficiently
+     * updated. */
+      if (topo_has_flag(TF_WRAPX)) {
+       overview.map_x0 = FC_WRAP(ntl_x - NATURAL_WIDTH / 2, NATURAL_WIDTH);
+      } else {
+       overview.map_x0 = 0;
+      }
+      if (topo_has_flag(TF_WRAPY)) {
+       overview.map_y0 = FC_WRAP(ntl_y - NATURAL_HEIGHT / 2, NATURAL_HEIGHT);
+      } else {
+       overview.map_y0 = 0;
+      }
+      redraw_overview();
+  } do_in_natural_pos_end;
 }
 
 /**************************************************************************
@@ -2019,23 +2020,26 @@
 void map_to_overview_pos(int *overview_x, int *overview_y,
                         int map_x, int map_y)
 {
-  int gui_x, gui_y;
-
   /* The map position may not be normal, for instance when the mapview
    * origin is not a normal position.
    *
    * NOTE: this embeds the map wrapping in the overview code. */
-  map_to_native_pos(&gui_x, &gui_y, map_x, map_y);
-  gui_x -= overview.map_x0;
-  gui_y -= overview.map_y0;
-  if (topo_has_flag(TF_WRAPX)) {
-    gui_x = FC_WRAP(gui_x, map.xsize);
-  }
-  if (topo_has_flag(TF_WRAPY)) {
-    gui_y = FC_WRAP(gui_y, map.ysize);
-  }
-  *overview_x = OVERVIEW_TILE_WIDTH * gui_x;
-  *overview_y = OVERVIEW_TILE_HEIGHT * gui_y;
+  do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) {
+    int ovr_x = ntl_x - overview.map_x0,
+       ovr_y = ntl_y - overview.map_y0;
+    const int natural_width = NATURAL_WIDTH; /* optimizing speed*/
+
+    if (topo_has_flag(TF_WRAPX)) {
+      ovr_x = FC_WRAP(ovr_x, natural_width);
+    } else {
+      if( topo_has_flag(TF_ISO)) { ovr_x--; }; /* clip half tile */
+    }
+    if (topo_has_flag(TF_WRAPY)) {
+      ovr_y = FC_WRAP(ovr_y, NATURAL_HEIGHT);
+    }
+    *overview_x = OVERVIEW_TILE_SIZE * ovr_x;
+    *overview_y = OVERVIEW_TILE_SIZE * ovr_y;
+  } do_in_natural_pos_end;
 }
 
 /**************************************************************************
@@ -2044,10 +2048,16 @@
 void overview_to_map_pos(int *map_x, int *map_y,
                         int overview_x, int overview_y)
 {
-  int nat_x = overview_x / OVERVIEW_TILE_WIDTH + overview.map_x0;
-  int nat_y = overview_y / OVERVIEW_TILE_HEIGHT + overview.map_y0;
+    int ntl_x = overview_x / OVERVIEW_TILE_SIZE + overview.map_x0,
+       ntl_y = overview_y / OVERVIEW_TILE_SIZE + overview.map_y0;
+
+  /* clip half tile left and right */
+  if(topo_has_flag(TF_ISO) && !topo_has_flag(TF_WRAPX)) {
+    ntl_x++;
+  }
 
-  native_to_map_pos(map_x, map_y, nat_x, nat_y);
+  natural_to_map_pos(map_x, map_y, ntl_x, ntl_y);
+ 
   if (!normalize_map_pos(map_x, map_y)) {
     /* All positions on the overview should be valid. */
     assert(FALSE);
@@ -2061,52 +2071,56 @@
 static void get_mapview_corners(int x[4], int y[4])
 {
   int map_x0, map_y0;
-
+  const int TILE_WIDTH = OVERVIEW_TILE_WIDTH,
+         TILE_HEIGHT = OVERVIEW_TILE_HEIGHT;
   canvas_to_map_pos(&map_x0, &map_y0, 0, 0);
   map_to_overview_pos(&x[0], &y[0], map_x0, map_y0);
 
   /* Note: these calculations operate on overview coordinates as if they
    * are native. */
+  /* TILE_WIDTH is there to correct it to natural, but corners can are off 
+     by 1 */
+
   if (is_isometric && !topo_has_flag(TF_ISO)) {
     /* We start with the west corner. */
 
     /* North */
-    x[1] = x[0] + OVERVIEW_TILE_WIDTH * mapview_canvas.tile_width;
-    y[1] = y[0] - OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_width;
+    x[1] = x[0] + TILE_WIDTH * mapview_canvas.tile_width;
+    y[1] = y[0] - TILE_HEIGHT * mapview_canvas.tile_width;
 
     /* East */
-    x[2] = x[1] + OVERVIEW_TILE_WIDTH * mapview_canvas.tile_height;
-    y[2] = y[1] + OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_height;
+    x[2] = x[1] + TILE_WIDTH * mapview_canvas.tile_height;
+    y[2] = y[1] + TILE_HEIGHT * mapview_canvas.tile_height;
 
     /* South */
-    x[3] = x[0] + OVERVIEW_TILE_WIDTH * mapview_canvas.tile_height;
-    y[3] = y[0] + OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_height;
+    x[3] = x[0] + TILE_WIDTH * mapview_canvas.tile_height;
+    y[3] = y[0] + TILE_HEIGHT * mapview_canvas.tile_height;
   } else if (!is_isometric && topo_has_flag(TF_ISO)) {
     /* We start with the west corner.  Note the X scale is smaller. */
 
     /* North */
-    x[1] = x[0] + OVERVIEW_TILE_WIDTH * mapview_canvas.tile_width / 2;
-    y[1] = y[0] + OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_width;
+    x[1] = x[0] + TILE_WIDTH * mapview_canvas.tile_width / 2;
+    y[1] = y[0] + TILE_HEIGHT * mapview_canvas.tile_width;
 
     /* East */
-    x[2] = x[1] - OVERVIEW_TILE_WIDTH * mapview_canvas.tile_height / 2;
-    y[2] = y[1] + OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_height;
+    x[2] = x[1] - TILE_WIDTH * mapview_canvas.tile_height / 2;
+    y[2] = y[1] + TILE_HEIGHT * mapview_canvas.tile_height;
 
     /* South */
-    x[3] = x[2] - OVERVIEW_TILE_WIDTH * mapview_canvas.tile_width / 2;
-    y[3] = y[2] - OVERVIEW_TILE_HEIGHT * mapview_canvas.tile_width;
+    x[3] = x[2] - TILE_WIDTH * mapview_canvas.tile_width / 2;
+    y[3] = y[2] - TILE_HEIGHT * mapview_canvas.tile_width;
   } else {
     /* We start with the northwest corner. */
     int screen_width = mapview_canvas.tile_width;
     int screen_height = mapview_canvas.tile_height * (is_isometric ? 2 : 1);
 
     /* Northeast */
-    x[1] = x[0] + OVERVIEW_TILE_WIDTH * screen_width - 1;
+    x[1] = x[0] + TILE_WIDTH * screen_width - 1;
     y[1] = y[0];
 
     /* Southeast */
     x[2] = x[1];
-    y[2] = y[0] + OVERVIEW_TILE_HEIGHT * screen_height - 1;
+    y[2] = y[0] + TILE_HEIGHT * screen_height - 1;
 
     /* Southwest */
     x[3] = x[0];
@@ -2133,18 +2147,36 @@
 **************************************************************************/
 void overview_update_tile(int map_x, int map_y)
 {
-  int base_x, base_y;
-
-  /* Base overview positions are just like native positions, but scaled to
+  /* Base overview positions are just like natural positions, but scaled to
    * the overview tile dimensions. */
-  map_to_native_pos(&base_x, &base_y, map_x, map_y);
-  base_x *= OVERVIEW_TILE_WIDTH;
-  base_y *= OVERVIEW_TILE_HEIGHT;
-
-  canvas_put_rectangle(overview.store,
-                      overview_tile_color(map_x, map_y), base_x, base_y,
-                      OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
-  dirty_overview();
+    do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) {
+      int overview_y =ntl_y * OVERVIEW_TILE_SIZE,
+         overview_x =ntl_x * OVERVIEW_TILE_SIZE;
+      const int TILE_WIDTH = OVERVIEW_TILE_WIDTH,
+         TILE_HEIGHT = OVERVIEW_TILE_HEIGHT;
+
+      if (topo_has_flag(TF_ISO)) {
+       if(topo_has_flag(TF_WRAPX)) {
+         if(overview_x > overview.width - TILE_WIDTH) {
+           /* Oops! we need update half tile at 0 */
+           canvas_put_rectangle(overview.store, 
+                                overview_tile_color(map_x, map_y),
+                                overview_x - overview.width, overview_y,
+                                TILE_WIDTH , TILE_HEIGHT); 
+         }     
+       } else {
+         /* clip half tile */
+         overview_x -= OVERVIEW_TILE_SIZE;
+       }
+      } 
+
+    canvas_put_rectangle(overview.store,
+                        overview_tile_color(map_x, map_y),
+                        overview_x, overview_y,
+                        TILE_WIDTH, TILE_HEIGHT);
+
+    dirty_overview();
+  } do_in_natural_pos_end;
 }
 
 /**************************************************************************
@@ -2152,8 +2184,20 @@
 **************************************************************************/
 void set_overview_dimensions(int width, int height)
 {
-  overview.width = OVERVIEW_TILE_WIDTH * width;
+  int shift = 0; /* used to calculate shift in iso view */
+  /* Set the scale of the overview map.  Note, since only the width is
+   * used to calculate the overview scale you can end up with a really
+   * tall or short overview if your map is unusually sized. */
+
+  OVERVIEW_TILE_SIZE = (120 / width) + 1;
+  if(topo_has_flag(TF_ISO)) {
+    OVERVIEW_TILE_SIZE = MAX(120 / width, 1);
+    /* clip half tile left and right*/ 
+    shift =   (!topo_has_flag(TF_WRAPX) ? -OVERVIEW_TILE_SIZE : 0);
+  }
+
   overview.height = OVERVIEW_TILE_HEIGHT * height;
+  overview.width = OVERVIEW_TILE_WIDTH * width + shift; 
 
   if (overview.store) {
     canvas_free(overview.store);
diff -ruN -Xdiff_ignore freeciv/client/packhand.c freeciv_/client/packhand.c
--- freeciv/client/packhand.c   2004-05-11 18:42:50.000000000 +0200
+++ freeciv_/client/packhand.c  2004-05-12 00:40:46.000000000 +0200
@@ -1310,12 +1310,6 @@
   map_allocate();
   init_client_goto();
 
-  /* Set the scale of the overview map.  Note, since only the width is
-   * used to calculate the overview scale you can end up with a really
-   * tall or short overview if your map is unusually sized. */
-  OVERVIEW_TILE_WIDTH = (120 / map.xsize) + 1;
-  OVERVIEW_TILE_HEIGHT = OVERVIEW_TILE_WIDTH;
-
   set_overview_dimensions(map.xsize, map.ysize);
 }
 
diff -ruN -Xdiff_ignore freeciv/client/tilespec.c freeciv_/client/tilespec.c
--- freeciv/client/tilespec.c   2004-05-08 17:21:05.000000000 +0200
+++ freeciv_/client/tilespec.c  2004-05-12 00:40:46.000000000 +0200
@@ -72,8 +72,7 @@
 int SMALL_TILE_WIDTH;
 int SMALL_TILE_HEIGHT;
 
-int OVERVIEW_TILE_WIDTH = 2;
-int OVERVIEW_TILE_HEIGHT = 2;
+int OVERVIEW_TILE_SIZE = 2;
 
 bool is_isometric;
 int hex_width, hex_height;
diff -ruN -Xdiff_ignore freeciv/client/tilespec.h freeciv_/client/tilespec.h
--- freeciv/client/tilespec.h   2004-04-30 00:49:10.000000000 +0200
+++ freeciv_/client/tilespec.h  2004-05-12 00:40:46.000000000 +0200
@@ -278,8 +278,7 @@
 extern int SMALL_TILE_WIDTH;
 extern int SMALL_TILE_HEIGHT;
 
-extern int OVERVIEW_TILE_WIDTH;
-extern int OVERVIEW_TILE_HEIGHT;
+extern int OVERVIEW_TILE_SIZE;
 
 extern bool is_isometric;
 extern int hex_width, hex_height;
diff -ruN -Xdiff_ignore freeciv/common/map.h freeciv_/common/map.h
--- freeciv/common/map.h        2004-05-11 18:42:50.000000000 +0200
+++ freeciv_/common/map.h       2004-05-12 00:40:46.000000000 +0200
@@ -207,9 +207,22 @@
       *(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) & 1)) / 2)          \
    : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
 
+#define natural_to_map_pos(pmap_x, pmap_y, nat_x, nat_y)                    \
+  (topo_has_flag(TF_ISO)                                                    \
+   ? (*(pmap_x) = ((nat_y) + (nat_x)) / 2,                                  \
+      *(pmap_y) = (nat_y) - *(pmap_x) + map.xsize)                          \
+   : (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
+
+#define map_to_natural_pos(pnat_x, pnat_y, map_x, map_y)                    \
+  (topo_has_flag(TF_ISO)                                                    \
+   ? (*(pnat_y) = (map_x) + (map_y) - map.xsize,                            \
+      *(pnat_x) = 2 * (map_x) - *(pnat_y))                                  \
+   : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
+
+
 /* Provide a block to convert from map to native coordinates.  This allows
  * you to use a native version of the map position within the block.  Note
- * that any changes to the native position won't affect the map position. */
+ * that native position are declare as const. */
 #define do_in_native_pos(nat_x, nat_y, map_x, map_y)                        \
 {                                                                           \
   int _nat_x, _nat_y;                                                       \
@@ -221,6 +234,33 @@
   }                                                                         \
 }
 
+/* Provide a block to convert from map to natural coordinates. This allows
+ * you to use a natural version of the map position within the block.
+ * natural version vars are const and can't be changed inside the block */
+
+#define do_in_natural_pos(ntl_x, ntl_y, map_x, map_y)                        \
+{                                                                           \
+  int _ntl_x, _ntl_y;                                                       \
+  map_to_natural_pos(&_ntl_x, &_ntl_y, map_x, map_y);                      \
+  {                                                                         \
+    const int ntl_x = _ntl_x, ntl_y = _ntl_y;
+
+#define do_in_natural_pos_end                                                \
+  }                                                                         \
+}
+
+#define NATIVE_WIDTH map.xsize
+#define NATIVE_HEIGHT map.ysize
+
+#define NATURAL_WIDTH (topo_has_flag(TF_ISO) ? 2 * map.xsize : map.xsize)
+#define NATURAL_HEIGHT map.ysize
+
+/* these factors are used by overview code */
+
+#define OVERVIEW_TILE_WIDTH \
+        ((topo_has_flag(TF_ISO) ? 2 : 1) * OVERVIEW_TILE_SIZE)
+#define OVERVIEW_TILE_HEIGHT OVERVIEW_TILE_SIZE
+
 static inline int map_pos_to_index(int map_x, int map_y);
 
 /* index_to_map_pos(int *, int *, int) inverts map_pos_to_index */

[Prev in Thread] Current Thread [Next in Thread]