Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] the directional system
Home

[Freeciv-Dev] the directional system

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] the directional system
From: Jason Dorje Short <jshort@xxxxxxxxxxxxx>
Date: Fri, 07 Sep 2001 06:59:52 -0400
Reply-to: jdorje@xxxxxxxxxxxxxxxxxxxxx

First, there's an experimental patch for testing attached.  This patch
changes the DIR_D[XY] arrays to use the DIR_D[XY]2 directional system. 
It replaces a last few magic numbers that I've found.  Most importantly,
everything seems to work cleanly (although I have not done real tests
like comparisons of profiles).

Given this, I have to ask you Ross: what was the problem you were having
with changing the DIR_D[XY] arrays?  Can you still reproduce it?


I'd like to bring up the proposed plans for changing the directional
system again:

- Ross's plan is to switch over slowly.  All of the core server and
common code will be changed to use the DIR_DX2 arrays directly.  The GUI
code (that he had had problems with before) will continue to use the
DIR_DX arrays until that problem is solved.

- My plan is to switch over all at once, but not until everything is
ready.  First off drop the DIR_DX2 arrays and just use the DIR_DX ones
for now.  Then find and replace all remaining magic numbers/code so that
the directional system is all encapsulated within map.h.  Finally make
the switchover all at once.


Ross, I did find one extra place where "magic" code is used: get_drawn()
in client/goto.c.  This was easily spotted because the assertions of
July 28th that were added by Thue (before that I'm not sure if there
would have been a failed assertion check).  Could this account for the
problems you were having before?


To move forward on making this changeover, one of the plans needs to be
chosen.  The next step for each of them would be quite different, so
until a decision is made no step can be taken.

Ross: if there is no structural problem with the GUI code preventing the
use of the new system (as it appears to me there is not), would you
still be opposed to my system?  If you can still reproduce the problem
you were having before, I'd like to take a look at it.

jason
? rc
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.20
diff -u -r1.20 goto.c
--- client/goto.c       2001/08/30 10:44:16     1.20
+++ client/goto.c       2001/09/07 10:42:23
@@ -671,8 +671,8 @@
 ***********************************************************************/
 int get_drawn(int x, int y, int dir)
 {
-  if ((y == 0 && dir <= 2)
-      || (y == map.ysize-1 && dir >= 5))
+  if ((y == 0 && DIR_DY[dir] < 0)
+      || (y == map.ysize-1 && DIR_DY[dir] > 0))
     return 0;
 
   return *get_drawn_char(x, y, dir);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.49
diff -u -r1.49 tilespec.c
--- client/tilespec.c   2001/08/24 08:22:01     1.49
+++ client/tilespec.c   2001/09/07 10:42:25
@@ -1097,8 +1097,8 @@
   }
 
   for (dir=0; dir<8; dir++) {
-    int x1 = x + DIR_DX2[dir];
-    int y1 = y + DIR_DY2[dir];
+    int x1 = x + DIR_DX[dir];
+    int y1 = y + DIR_DY[dir];
     if (normalize_map_pos(&x1, &y1)) {
       ttype_near[dir] = map_get_terrain(x1, y1);
       tspecial_near[dir] = map_get_special(x1, y1);
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.84
diff -u -r1.84 map.c
--- common/map.c        2001/09/06 21:23:07     1.84
+++ common/map.c        2001/09/07 10:42:27
@@ -42,16 +42,12 @@
 struct tile_type tile_types[T_LAST];
 
 /* used to compute neighboring tiles */
-const int DIR_DX[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
-const int DIR_DY[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
+const int DIR_DX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
+const int DIR_DY[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
 
 /* like DIR_DX[] and DIR_DY[], only cartesian */
 const int CAR_DIR_DX[4] = {1, 0, -1, 0};
 const int CAR_DIR_DY[4] = {0, 1, 0, -1};
-
-/* used to compute neighboring tiles */
-const int DIR_DX2[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
-const int DIR_DY2[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
 
 /* Names of specials.
  * (These must correspond to enum tile_special_type in terrain.h.)
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.88
diff -u -r1.88 map.h
--- common/map.h        2001/09/06 18:19:09     1.88
+++ common/map.h        2001/09/07 10:42:27
@@ -417,29 +417,29 @@
 y1 = y + DIR_DX[dir];
 will give you the tile as shown below.
 -------
-|0|1|2|
+|7|0|1|
 |-+-+-|
-|3| |4|
+|6| |2|
 |-+-+-|
-|5|6|7|
+|5|4|3|
 -------
  */
 
 enum direction8 {
   /* FIXME: DIR8 is used to avoid conflict with
    * enum Directions in client/tilespec.h */
-  DIR8_NORTHWEST = 0,
-  DIR8_NORTH = 1,
-  DIR8_NORTHEAST = 2,
-  DIR8_WEST = 3,
-  DIR8_EAST = 4,
+  DIR8_NORTHWEST = 7,
+  DIR8_NORTH = 0,
+  DIR8_NORTHEAST = 1,
+  DIR8_WEST = 6,
+  DIR8_EAST = 2,
   DIR8_SOUTHWEST = 5,
-  DIR8_SOUTH = 6,
-  DIR8_SOUTHEAST = 7
+  DIR8_SOUTH = 4,
+  DIR8_SOUTHEAST = 3
 };
 
 /* return the reverse of the direction */
-#define DIR_REVERSE(dir) (7 - (dir))
+#define DIR_REVERSE(dir) (((dir) + 4) % 8)
 
 /* is the direction "cardinal"?  Cardinal directions
  * (also called cartesian) are the four main ones */
@@ -494,23 +494,6 @@
   }                                                    \
 }
 
-
-/*
-used to compute neighboring tiles:
-using
-x1 = x + DIR_DX2[dir];
-y1 = y + DIR_DY2[dir];
-will give you the tile as shown below.
--------
-|7|0|1|
-|-+-+-|
-|6| |2|
-|-+-+-|
-|5|4|3|
--------
- */
-extern const int DIR_DX2[8];
-extern const int DIR_DY2[8];
 
 #define MAP_DEFAULT_HUTS         50
 #define MAP_MIN_HUTS             0
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.111
diff -u -r1.111 gotohand.c
--- server/gotohand.c   2001/08/30 13:00:16     1.111
+++ server/gotohand.c   2001/09/07 10:42:30
@@ -504,13 +504,13 @@
   go_y = dest_y > src_y ? 1 : -1;
 
   if (src_x == dest_x)
-    best_dir = (go_y > 0) ? 6 : 1;
+    best_dir = (go_y > 0) ? DIR8_SOUTH : DIR8_NORTH;
   else if (src_y == dest_y)
-    best_dir = (go_x > 0) ? 4 : 3;
+    best_dir = (go_x > 0) ? DIR8_EAST : DIR8_WEST;
   else if (go_x > 0)
-    best_dir = (go_y > 0) ? 7 : 2;
+    best_dir = (go_y > 0) ? DIR8_SOUTHEAST : DIR8_NORTHEAST;
   else /* go_x < 0 */
-    best_dir = (go_y > 0) ? 5 : 0;
+    best_dir = (go_y > 0) ? DIR8_SOUTHWEST : DIR8_NORTHWEST;
 
   return (best_dir);
 }

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