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: Thu, 6 May 2004 13:09:30 -0700
Reply-to: rt@xxxxxxxxxxx

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

Le jeu 06/05/2004 à 18:56, Jason Short a écrit :
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8627 >
> 
> I'm still not convinced that this is the way to do it (although I agree
> the current method is bad; this may be a good temporary way to improve it).
> 
> However there are still some problems:
> 
> - Your patch is out of date.
> - What is the purpose of the packhand.c changes?  I don't think those
> should be in there.
i move this in best place! bad placed original code too
> - There are problems with iso-maps that don't have TF_WRAPX (topos 4 and
> 6).  The problems come because the left and right side of the map are
> actually zig-zags on the overview.  However obviously the overview can't
> draw it like that.  The result is that the left side is drawn zig-zag
> with some colors uninitialized.  The right side is OVERVIEW_TILE_WIDTH /
> 2 pixels too small (the overview width isn't enough, it should be
> map.xsize * OVERVIEW_TILE_WIDTH + OVERVIEW_TILE_WIDTH / 2) and so the
> zig-zag is clipped off.
this was related ot the hard wraps code, (this code update a half tile
left side)
> 
> jason
-- 
 . /  .     '    ,    .      (*)   '        `     '      `    .    
  |    ,  |   `     ,     .      ,   '  Marcelo Julián Burda      .
 /  '     \     `     \@_     '      .        '      `        '    
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

diff -ruN -Xdiff_ignore freeciv/client/mapview_common.c 
freeciv_/client/mapview_common.c
--- freeciv/client/mapview_common.c     2004-05-01 01:48:36.000000000 +0200
+++ freeciv_/client/mapview_common.c    2004-05-06 23:57:43.000000000 +0200
@@ -2019,23 +2019,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_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;
+    
+    if( topo_has_flag(TF_ISO) && (gui_y & 1) == 1 ) {
+      overview_x +=  OVERVIEW_TILE_WIDTH / 2;
+    }
+  } do_in_native_pos_end;
 }
 
 /**************************************************************************
@@ -2044,8 +2047,12 @@
 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 nat_x, nat_y = overview_y / OVERVIEW_TILE_HEIGHT + overview.map_y0;
+
+  if( topo_has_flag(TF_ISO) && (nat_y & 1) == 1 ) {
+    overview_x -=  OVERVIEW_TILE_WIDTH / 2;
+  }
+  nat_x = overview_x / OVERVIEW_TILE_WIDTH + overview.map_x0;
 
   native_to_map_pos(map_x, map_y, nat_x, nat_y);
   if (!normalize_map_pos(map_x, map_y)) {
@@ -2133,18 +2140,31 @@
 **************************************************************************/
 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_native_pos(base_x, base_y, map_x, map_y) {
+    
+    if( topo_has_flag(TF_ISO) && (base_y & 1) == 1 ) { /* shift half tile */
+      base_y *= OVERVIEW_TILE_HEIGHT;
+      if ((base_x == map.xsize - 1) && topo_has_flag(TF_WRAPX)) {
+         /* ups we need update half tile at 0 */
+       canvas_put_rectangle(overview.store,
+                            overview_tile_color(map_x, map_y), 0, base_y,
+                            OVERVIEW_TILE_WIDTH / 2, OVERVIEW_TILE_HEIGHT); 
+      }
+      base_x =base_x * OVERVIEW_TILE_WIDTH + OVERVIEW_TILE_WIDTH / 2;
+    
+    } else {
+       base_y *= OVERVIEW_TILE_HEIGHT;
+       base_x *= OVERVIEW_TILE_WIDTH;
+    }
+    
+    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_native_pos_end;
 }
 
 /**************************************************************************
@@ -2152,7 +2172,21 @@
 **************************************************************************/
 void set_overview_dimensions(int width, int height)
 {
-  overview.width = OVERVIEW_TILE_WIDTH * width;
+  /* 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 / width) + 1;
+  OVERVIEW_TILE_HEIGHT = OVERVIEW_TILE_WIDTH;
+
+  if(topo_has_flag(TF_ISO)) {
+    OVERVIEW_TILE_HEIGHT = MAX(120 / width, 1);
+    OVERVIEW_TILE_WIDTH = 2 * OVERVIEW_TILE_HEIGHT;
+  }
+ 
+  overview.width = OVERVIEW_TILE_WIDTH * width 
+      + (topo_has_flag(TF_ISO) && !topo_has_flag(TF_WRAPX)
+      ? OVERVIEW_TILE_WIDTH / 2 : 0);
   overview.height = OVERVIEW_TILE_HEIGHT * height;
 
   if (overview.store) {
diff -ruN -Xdiff_ignore freeciv/client/packhand.c freeciv_/client/packhand.c
--- freeciv/client/packhand.c   2004-05-01 01:48:36.000000000 +0200
+++ freeciv_/client/packhand.c  2004-05-06 23:50:55.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/common/map.h freeciv_/common/map.h
--- freeciv/common/map.h        2004-05-01 01:48:36.000000000 +0200
+++ freeciv_/common/map.h       2004-05-06 23:34:19.000000000 +0200
@@ -207,6 +207,22 @@
       *(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) & 1)) / 2)          \
    : (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
 
+/* Provide a block to convert from map to native coordinates.  
+
+ * Note that changing the value of the native coordinates won't change the map
+ * coordinates.
+ */
+
+#define do_in_native_pos(nat_x, nat_y, map_x, map_y)                        \
+{                                                                           \
+  int nat_x, nat_y;                                                         \
+  map_to_native_pos(&nat_x, &nat_y, map_x, map_y);                          \
+  {                                                                         \
+
+#define do_in_native_pos_end                                                \
+  }                                                                         \
+}
+
 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]