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

[Freeciv-Dev] Re: (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] Re: (PR#8627) best overview for iso-maps
From: "Marcelo Burda" <mburda@xxxxxxxxx>
Date: Fri, 21 May 2004 09:16:30 -0700
Reply-to: rt@xxxxxxxxxxx

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

Le jeu 20/05/2004 à 04:09, Jason Short a écrit :
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8627 >
> 
> 1.  I don't like the changes you make in get_mapview_corners just to
> avoid recomputing the size.  A few extra *2 calculations in the client
> won't hurt anything.  Can you remove these changes?
> 
> You do it in overview_update_tile too, but that's not as bad (I'd still
> rather have it removed though).
Ok
> 
> 2....
> 3.  The #definition of OVERVIEW_TILE_WIDTH and OVERVIEW_TILE_HEIGHT
> should go right underneath OVERVIEW_TILE_SIZE, not in climap.h.
> 
Ok
> jason
Done
-- 
 . /  .     '    ,    .      (*)   '        `     '      `    .    
  |    ,  |   `     ,     .      ,   '  Marcelo Julián Burda      .
 /  '     \     `     \@_     '      .        '      `        '    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

diff -ruN -Xfreeciv/diff_ignore freeciv/client/mapview_common.c 
freeciv_/client/mapview_common.c
--- freeciv/client/mapview_common.c     2004-05-21 10:53:59.000000000 +0200
+++ freeciv_/client/mapview_common.c    2004-05-21 17:52:53.000000000 +0200
@@ -1979,8 +1979,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;
 
@@ -2033,23 +2033,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;
 }
 
 /**************************************************************************
@@ -2058,23 +2059,25 @@
 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;
+
+    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;
 }
 
 /**************************************************************************
@@ -2083,10 +2086,15 @@
 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);
@@ -2105,7 +2113,8 @@
   map_to_overview_pos(&x[0], &y[0], map_x0, map_y0);
 
   /* Note: these calculations operate on overview coordinates as if they
-   * are native. */
+   * are natural. but corners can be off by 1 */
+
   if (is_isometric && !topo_has_flag(TF_ISO)) {
     /* We start with the west corner. */
 
@@ -2172,18 +2181,34 @@
 **************************************************************************/
 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;
+
+    if (topo_has_flag(TF_ISO)) {
+      if(topo_has_flag(TF_WRAPX)) {
+       if(overview_x > overview.width - OVERVIEW_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,
+                              OVERVIEW_TILE_WIDTH , OVERVIEW_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,
+                        OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
+
+    dirty_overview();
+  } do_in_natural_pos_end;
 }
 
 /**************************************************************************
@@ -2191,8 +2216,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 -Xfreeciv/diff_ignore freeciv/client/packhand.c 
freeciv_/client/packhand.c
--- freeciv/client/packhand.c   2004-05-21 10:53:59.000000000 +0200
+++ freeciv_/client/packhand.c  2004-05-21 10:57:48.000000000 +0200
@@ -1309,12 +1309,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 -Xfreeciv/diff_ignore freeciv/client/tilespec.c 
freeciv_/client/tilespec.c
--- freeciv/client/tilespec.c   2004-05-05 22:39:15.000000000 +0200
+++ freeciv_/client/tilespec.c  2004-05-21 10:57:48.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 -Xfreeciv/diff_ignore freeciv/client/tilespec.h 
freeciv_/client/tilespec.h
--- freeciv/client/tilespec.h   2004-04-29 17:11:32.000000000 +0200
+++ freeciv_/client/tilespec.h  2004-05-21 17:48:27.000000000 +0200
@@ -278,8 +278,10 @@
 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;
+#define    OVERVIEW_TILE_WIDTH \
+        ((topo_has_flag(TF_ISO) ? 2 : 1) * OVERVIEW_TILE_SIZE)
+#define    OVERVIEW_TILE_HEIGHT OVERVIEW_TILE_SIZE
 
 extern bool is_isometric;
 extern int hex_width, hex_height;
diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.h freeciv_/common/map.h
--- freeciv/common/map.h        2004-05-21 10:54:00.000000000 +0200
+++ freeciv_/common/map.h       2004-05-21 10:57:48.000000000 +0200
@@ -261,6 +261,27 @@
 #define NATURAL_WIDTH (topo_has_flag(TF_ISO) ? 2 * map.xsize : map.xsize)
 #define NATURAL_HEIGHT map.ysize
 
+/* 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
+
 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]