Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] Re: (PR#8487) RFC: hex tilesets
Home

[Freeciv-Dev] Re: (PR#8487) RFC: hex tilesets

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8487) RFC: hex tilesets
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Apr 2004 12:43:08 -0700
Reply-to: rt@xxxxxxxxxxx

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

Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=8487 >
> 
>>[rwetmore@xxxxxxxxxxxx - Tue Apr 13 14:04:13 2004]:
> 
> 
>>[...]
>>
>>>A good way to test this would be to get the code running.  Then you
>>>could edit the top-level tilespec values and see how the hexagon
>>
>>looked
>>
>>>(in the map grid) without actually making any new tiles.
>>
>>Yes.
> 
> This patch should do it.

And an updated version, now much simpler.

I think this is ready to be applied.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.101
diff -u -r1.101 mapview_common.c
--- client/mapview_common.c     15 Apr 2004 19:36:00 -0000      1.101
+++ client/mapview_common.c     15 Apr 2004 19:40:57 -0000
@@ -758,6 +758,7 @@
                                int *end_x, int *end_y)
 {
   const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
+  const int HW = hex_width, HH = hex_height;
   const int overlap = (width > 1) ? 1 : 0;
 
   assert(inset >= 0);
@@ -801,37 +802,52 @@
     switch (dir) {
     case DIR8_NORTH:
       /* Top right. */
-      *start_x = W / 2;
-      *end_x = W - inset;
-      *start_y = inset + width;
-      *end_y = H / 2 + width;
+      *start_x = (W + HW) / 2;
+      *end_x = W - HW / 2 - inset;
+      *start_y = HH / 2 + inset + width;
+      *end_y = (H - HH) / 2 + width;
       return (draw & D_M_R);
     case DIR8_SOUTH:
       /* Bottom left. */
-      *start_x = inset;
-      *end_x = W / 2;
-      *start_y = H / 2 - overlap;
-      *end_y = H - inset - overlap;
+      *start_x = (W - HW) / 2;
+      *end_x = HW / 2 + inset;
+      *start_y = H - HH / 2 - inset - overlap;
+      *end_y = (H + HH) / 2 - overlap;
       return (draw & D_B_L) && (inset + overlap) > 0;
     case DIR8_EAST:
       /* Bottom right. */
-      *start_x = W - inset;
-      *end_x = W / 2;
-      *start_y = H / 2 - overlap;
-      *end_y = H - inset - overlap;
+      *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 (draw & D_B_R) && (inset + overlap) > 0;
     case DIR8_WEST:
       /* Top left. */
-      *start_x = inset;
-      *end_x = W / 2;
-      *start_y = H / 2 + width;
-      *end_y = inset + width;
+      *start_x = HW / 2 + inset;
+      *end_x = (W - HW) / 2;
+      *start_y = (H - HH) / 2 + width;
+      *end_y = HH / 2 + inset + width;
       return (draw & D_M_L);
     case DIR8_NORTHEAST:
+      *start_x = *end_x = W - HW / 2 - inset - overlap;
+      *start_y = (draw & D_M_R) ? ((H - HH) / 2) : H / 2;
+      *end_y = (draw & D_B_R) ? ((H + HH) / 2) : H / 2;
+      return HH > 0 && (draw & D_MB_R);
     case DIR8_SOUTHEAST:
+      *start_x = (draw & D_B_R) ? ((W + HW) / 2) : W / 2;
+      *end_x = (draw & D_B_L) ? ((W - HW) / 2) : W / 2;
+      *start_y = *end_y = H - HH / 2 - inset - overlap;
+      return HW > 0 && (draw & D_B_LR);
     case DIR8_SOUTHWEST:
+      *start_x = *end_x = HW / 2 + inset + width;
+      *start_y = (draw & D_B_L) ? ((H + HH) / 2) : H / 2;
+      *end_y = (draw & D_M_L) ? ((H - HH) / 2) : H / 2;
+      return HH > 0 && (draw & D_MB_L);
     case DIR8_NORTHWEST:
-      return FALSE;
+      *start_x = (draw & D_M_L) ? ((W - HW) / 2) : W / 2;
+      *end_x = (draw & D_M_R) ? ((W + HW) / 2) : W / 2;
+      *start_y = *end_y = HH / 2 + inset + width;
+      return HW > 0 && (draw & D_M_LR);
     }
   } else {
     switch (dir) {
@@ -945,14 +961,13 @@
 
   if (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
+     * by other terrain graphics.  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(map_x, map_y, adjc_x, adjc_y, dir) {
-      if (dir < 4
+      if ((dir == DIR8_NORTH || dir == DIR8_WEST
+          || dir == DIR8_NORTHWEST || dir == DIR8_SOUTHWEST)
          && get_tile_boundaries(dir, 0, BORDER_WIDTH, draw,
                                  &start_x, &start_y, &end_x, &end_y)
          && tile_get_known(adjc_x, adjc_y)
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.157
diff -u -r1.157 tilespec.c
--- client/tilespec.c   12 Apr 2004 17:15:06 -0000      1.157
+++ client/tilespec.c   15 Apr 2004 19:40:57 -0000
@@ -76,6 +76,7 @@
 int OVERVIEW_TILE_HEIGHT = 2;
 
 bool is_isometric;
+int hex_width, hex_height;
 
 char *city_names_font;
 char *city_productions_font_name;
@@ -635,10 +636,10 @@
   struct section_file the_file, *file = &the_file;
   char *fname, *c;
   int i;
-  int num_spec_files, num_terrains;
+  int num_spec_files, num_terrains, hex_side;
   char **spec_filenames, **terrains;
   char *file_capstr;
-  bool duplicates_ok;
+  bool duplicates_ok, is_hex;
 
   fname = tilespec_fullname(tileset_name);
   freelog(LOG_VERBOSE, "tilespec file is %s", fname);
@@ -659,6 +660,20 @@
   (void) section_file_lookup(file, "tilespec.name"); /* currently unused */
 
   is_isometric = secfile_lookup_bool_default(file, FALSE, 
"tilespec.is_isometric");
+
+  /* Read hex-tileset information. */
+  is_hex = secfile_lookup_bool_default(file, FALSE, "tilespec.is_hex");
+  hex_side = secfile_lookup_int_default(file, 0, "tilespec.hex_side");
+  hex_width = hex_height = 0;
+  if (is_hex) {
+    if (is_isometric) {
+      hex_height = hex_side;
+    } else {
+      hex_width = hex_side;
+    }
+    is_isometric = TRUE; /* Hex tilesets are drawn the same as isometric. */
+  }
+
   if (is_isometric && !isometric_view_supported()) {
     freelog(LOG_ERROR, _("Client does not support isometric tilesets."
            " Using default tileset instead."));
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.60
diff -u -r1.60 tilespec.h
--- client/tilespec.h   12 Apr 2004 17:15:06 -0000      1.60
+++ client/tilespec.h   15 Apr 2004 19:40:57 -0000
@@ -270,6 +270,7 @@
 extern int OVERVIEW_TILE_HEIGHT;
 
 extern bool is_isometric;
+extern int hex_width, hex_height;
 
 /* name of font to use to draw city names on main map */
 

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