[Freeciv-Dev] (PR#7251) new macros native_pos <-> index
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7251 >
The attached patch adds macros native_pos_to_index and index_to_native_pos.
These accomplish two things:
- They make the steps in the other macros more explicit.
- They will be of use in future functions that access values by native
position.
Because of their extremely heavy use they obviously have to be macros
(or inline functions).
jason
? diff
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.166
diff -u -r1.166 map.h
--- common/map.h 2004/01/13 03:20:17 1.166
+++ common/map.h 2004/01/16 05:00:20
@@ -209,6 +209,12 @@
#define CHECK_INDEX(index) ((void)0)
#endif
+#define native_pos_to_index(nat_x, nat_y) \
+ ((nat_x) + (nat_y) * map.xsize)
+#define index_to_native_pos(pnat_x, pnat_y, index) \
+ (*(pnat_x) = (index) % map.xsize, \
+ *(pnat_y) = (index) / map.xsize)
+
/* Obscure math. See explanation in doc/HACKING. */
#define native_to_map_pos(pmap_x, pmap_y, nat_x, nat_y) \
(topo_has_flag(TF_ISO) \
@@ -227,8 +233,7 @@
/* 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, \
+ index_to_native_pos(pmap_x, pmap_y, index), \
native_to_map_pos(pmap_x, pmap_y, *(pmap_x), *(pmap_y)))
#define DIRSTEP(dest_x, dest_y, dir) \
@@ -683,7 +688,7 @@
CHECK_MAP_POS(map_x, map_y);
map_to_native_pos(&nat_x, &nat_y, map_x, map_y);
- return nat_x + nat_y * map.xsize;
+ return native_pos_to_index(nat_x, nat_y);
}
#endif /* FC__MAP_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#7251) new macros native_pos <-> index,
Jason Short <=
|
|