Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] (PR#3444) index_to_map_pos macro
Home

[Freeciv-Dev] (PR#3444) index_to_map_pos macro

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3444) index_to_map_pos macro
From: "Gregory Berkolaiko" <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Sun, 16 Feb 2003 08:57:25 -0800
Reply-to: rt@xxxxxxxxxxxxxx

The macro inverts the action of map_inx: extracts the map coordinates from 
the index.  Also added are macros CHECK_INDEX (similar to CHECK_MAP_POS) 
and MAX_INDEX for sanity checking and allocations.

I intend to adapt the PF code to use this and map_inx code shortly, so 
please commit.

G.


? mmm.gz
? common/aicore/path_finding.c
? common/aicore/path_finding.h
? common/aicore/pf_tools.c
? common/aicore/pf_tools.h
? common/aicore/pqueue.c
? common/aicore/pqueue.h
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.135
diff -u -r1.135 map.h
--- common/map.h        2003/02/10 21:43:41     1.135
+++ common/map.h        2003/02/16 16:35:04
@@ -222,6 +222,21 @@
 #define map_inx(x,y) \
   (CHECK_MAP_POS((x),(y)), (x)+(y)*map.xsize)
 
+/* Maximum value of index (for sanity checks and allocations) */
+#define MAX_INDEX map.xsize * map.ysize
+
+#ifdef DEBUG
+#define CHECK_INDEX(index) assert((index) >= 0 && (index) < MAX_INDEX)
+#else
+#define CHECK_INDEX(index) ((void)0)
+#endif
+
+/* index_to_map_pos(int, int *, int *) inverts map_inx */
+#define index_to_map_pos(index, x, y) \
+(    CHECK_INDEX(index),              \
+     *(x) = (index) % map.xsize,      \
+     *(y) = (index) / map.ysize)
+
 #define DIRSTEP(dest_x, dest_y, dir)   \
 (    (dest_x) = DIR_DX[(dir)],         \
      (dest_y) = DIR_DY[(dir)])

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