Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9338) RFC: using tileset direction lists
Home

[Freeciv-Dev] (PR#9338) RFC: using tileset direction lists

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9338) RFC: using tileset direction lists
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 11 Jul 2004 10:55:21 -0700
Reply-to: rt@xxxxxxxxxxx

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

Currently the tileset assumes the NSEW directions are cardinal and the 
other four directions are diagonal.

However in most cases this doesn't make sense with hex tilesets.  For 
one thing there are only six directions total.  And they are all cardinal.

In this case cardinal means that an edge (not just a vertex) is shared 
with the adjacent tile in that direction.  For instance rivers need to 
be drawn to all adjacent tiles (this is actually a significant problem). 
  Mountains/forests/hills/jungles, if matched, must match all adjacent 
tiles (giving 64 graphics instead of 16).  Darkness sprites and blending 
sprites must exist for all cardinal directions.  Right now none of this 
is true, and someone making a hex tileset has to try to hack around it 
or not use those features.

The 6 valid directions are a small problem in a few cases.  For instance 
with roadstyle 3 the hex author must include 256 road and rail graphics 
even though only 64 should be needed.

IMO the tileset can ignore the underlying topology.  Rivers only 
actually connect on hex lines if the topology is hex, but a hex tileset 
should draw them that way regardless.  Anyone using a tileset with the 
wrong topology shouldn't be - and in single-player this is easy to 
enforce by setting the topology when the client launches the server.

Attached is a patch that creates the direction lists.  This is basically 
identical to the topology lists created in init_topology.  Using these 
lists, though, is quite a bit harder.  Code like INDEX_NSEW or nsew_str 
(in which "nsew" basically means "cardinal") is not easy to convert into 
an array form.

jason

Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.182
diff -u -r1.182 tilespec.c
--- client/tilespec.c   10 Jul 2004 18:48:17 -0000      1.182
+++ client/tilespec.c   11 Jul 2004 17:49:18 -0000
@@ -88,6 +88,9 @@
 #define NUM_CORNER_DIRS 4
 #define TILES_PER_CORNER 4
 
+static int num_valid_tileset_dirs, num_cardinal_tileset_dirs;
+static enum direction8 valid_tileset_dirs[8], cardinal_tileset_dirs[8];
+
 static struct {
   enum match_style match_style;
   int count;
@@ -197,6 +200,35 @@
                                            bool required, const char *what,
                                            const char *name);
 
+/****************************************************************************
+  Return TRUE iff the dir is valid in this tileset.
+****************************************************************************/
+static bool is_valid_tileset_dir(enum direction8 dir)
+{
+  if (hex_width > 0) {
+    return dir != DIR8_NORTHEAST && dir != DIR8_SOUTHWEST;
+  } else if (hex_height > 0) {
+    return dir != DIR8_NORTHWEST && dir != DIR8_SOUTHEAST;
+  } else {
+    return TRUE;
+  }
+}
+
+/****************************************************************************
+  Return TRUE iff the dir is cardinal in this tileset.
+
+  "Cardinal", in this sense, means that a tile will share a border with
+  another tile in the direction rather than sharing just a single vertex.
+****************************************************************************/
+static bool is_cardinal_tileset_dir(enum direction8 dir)
+{
+  if (hex_width > 0 || hex_height > 0) {
+    return is_valid_tileset_dir(dir);
+  } else {
+    return DIR_IS_CARDINAL(dir);
+  }
+}
+
 /**********************************************************************
   Returns a static list of tilesets available on the system by
   searching all data directories for files matching TILESPEC_SUFFIX.
@@ -687,6 +719,7 @@
   char **spec_filenames, **terrains;
   char *file_capstr;
   bool duplicates_ok, is_hex;
+  enum direction8 dir;
 
   fname = tilespec_fullname(tileset_name);
   freelog(LOG_VERBOSE, "tilespec file is %s", fname);
@@ -738,6 +771,24 @@
     return tilespec_read_toplevel(NULL);
   }
 
+  /* Create arrays of valid and cardinal tileset dirs.  These depend
+   * entirely on the tileset, not the topology.  They are also in clockwise
+   * rotational ordering. */
+  num_valid_tileset_dirs = num_cardinal_tileset_dirs = 0;
+  dir = DIR8_NORTH;
+  do {
+    if (is_valid_tileset_dir(dir)) {
+      valid_tileset_dirs[num_valid_tileset_dirs] = dir;
+      num_valid_tileset_dirs++;
+    }
+    if (is_cardinal_tileset_dir(dir)) {
+      cardinal_tileset_dirs[num_cardinal_tileset_dirs] = dir;
+      num_cardinal_tileset_dirs++;
+    }
+
+    dir = dir_cw(dir);
+  } while (dir != DIR8_NORTH);
+
   NORMAL_TILE_WIDTH = secfile_lookup_int(file, "tilespec.normal_tile_width");
   NORMAL_TILE_HEIGHT = secfile_lookup_int(file, "tilespec.normal_tile_height");
   if (is_isometric) {

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9338) RFC: using tileset direction lists, Jason Short <=