Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#6257) recodify map_pos<->index conversion to use n
Home

[Freeciv-Dev] Re: (PR#6257) recodify map_pos<->index conversion to use n

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#6257) recodify map_pos<->index conversion to use native positions
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Sep 2003 12:11:37 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Gregory Berkolaiko wrote:
> On Tue, 23 Sep 2003, Jason Short wrote:
> 
> 
>>Clever.  This is generally the type of thing we want to avoid - since 
>>most of the time it will only lead to misuse - but here it is helpful.
> 
> 
> If you want to discourage people from using the new macros, maybe you 
> should put a comment above their declaration?

Indeed.

jason

? rc
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.153
diff -u -r1.153 map.h
--- common/map.h        2003/09/19 13:17:12     1.153
+++ common/map.h        2003/09/23 18:55:06
@@ -241,15 +241,21 @@
 #define map_to_native_pos(pnat_x, pnat_y, map_x, map_y) \
   (*(pnat_x) = (map_x), *(pnat_y) = (map_y))
 
+/* Use map_to_native_pos instead unless you know what you're doing. */
+#define map_pos_to_native_x(map_x, map_y) (map_x)
+#define map_pos_to_native_y(map_x, map_y) (map_y)
+
 #define map_pos_to_index(map_x, map_y)        \
   (CHECK_MAP_POS((map_x), (map_y)),           \
-   (map_x) + (map_y) * map.xsize)
+   (map_pos_to_native_x(map_x, map_y)         \
+    + map_pos_to_native_y(map_x, map_y) * map.xsize))
 
 /* index_to_map_pos(int *, int *, int) inverts map_pos_to_index */
 #define index_to_map_pos(pmap_x, pmap_y, index) \
   (CHECK_INDEX(index),                          \
    *(pmap_x) = (index) % map.xsize,             \
-   *(pmap_y) = (index) / map.xsize)
+   *(pmap_y) = (index) / map.xsize,             \
+   native_to_map_pos(pmap_x, pmap_y, *(pmap_x), *(pmap_y)))
 
 #define DIRSTEP(dest_x, dest_y, dir)   \
 (    (dest_x) = DIR_DX[(dir)],         \

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