[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 11:35:07 -0700 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
Gregory Berkolaiko wrote:
> On Tue, 23 Sep 2003, Jason Short wrote:
>
>
>>Index positions are ordered based off of native ones. So the current
>>conversion operations (e.g., map_pos_to_index and index_to_map_pos) are
>>no good when we start using native positions.
>>
>>Unfortunately going through native coordinates requires an intermediate
>>pair of variables, which is a problem with macros. There are three
>>possible solutions:
>
>
> How about introducing 2 new macros
> map_to_native_x
> map_to_native_y
> ?
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.
Patch attached.
Note that for for iso-maps the calculation will be something like
y: (map_x + map_y - map.xsize)
x: (map_x - map_y + map.xsize - (map_x + map_y - map.xsize) & 1) / 2
which is why both map x and y values are needed for the macros (which is
why taking them individually is generally a bad idea).
I used map_pos_to_native_[xy] for the names - along the lines of
map_pos_to_index. Making them longer discourages people from using them
needlessly :-).
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:31:48
@@ -241,15 +241,20 @@
#define map_to_native_pos(pnat_x, pnat_y, map_x, map_y) \
(*(pnat_x) = (map_x), *(pnat_y) = (map_y))
+#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)], \
|
|