[Freeciv-Dev] Re: patches
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Better.
But note that the rotational system allows you to code the
DIR_IS_CARDINAL test into the loop parameters so you only
iterate over the right ones in the loop code as well.
All the iterate macros are the same tight loop code just with
different start/stop/increment values as loop parameters.
And there is a sleazy trick that lets you do this even with
the DIR_DX system. Define a mapping array from one to the
other, Do the loop over DIR_DX2 indicies, and do a lookup
aka transformation whenever you need a "dir" value for DIR_DX
i.e. _itr_dir = DX2toDX[_loop_dir].
But it is simpler to just do it right :-).
Cheers,
RossW
At 02:59 PM 01/09/09 -0400, Jason Dorje Short wrote:
>Raimar Falke wrote:
>>
>> On Tue, Aug 28, 2001 at 10:52:16AM +0200, Raimar Falke wrote:
>> > - cartesian_adjacent_iterate (move normalize_map_pos out of switch
>> > statement)
>>
>> Comments?
>
>Looks fine to me. But how about this one instead?
>
>jasonIndex: 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/09 18:55:52
>@@ -456,43 +456,13 @@
> extern const int CAR_DIR_DX[4];
> extern const int CAR_DIR_DY[4];
>
>-#define cartesian_adjacent_iterate(x, y, IAC_x, IAC_y) \
>-{ \
>- int IAC_i; \
>- int IAC_x, IAC_y; \
>- for (IAC_i = 0; IAC_i < 4; IAC_i++) { \
>- switch (IAC_i) { \
>- case 0: \
>- IAC_x = x + 1; \
>- IAC_y = y; \
>- if (!normalize_map_pos(&IAC_x, &IAC_y)) \
>- continue; \
>- break; \
>- case 1: \
>- IAC_x = x; \
>- IAC_y = y + 1; \
>- if (!normalize_map_pos(&IAC_x, &IAC_y)) \
>- continue; \
>- break; \
>- case 2: \
>- IAC_x = x - 1; \
>- IAC_y = y; \
>- if (!normalize_map_pos(&IAC_x, &IAC_y)) \
>- continue; \
>- break; \
>- case 3: \
>- IAC_x = x; \
>- IAC_y = y - 1; \
>- if (!normalize_map_pos(&IAC_x, &IAC_y)) \
>- continue; \
>- break; \
>- default: \
>- abort(); \
>- }
>+#define cartesian_adjacent_iterate(center_x, center_y, itr_x, itr_y)
\
>+ adjc_dir_iterate(center_x, center_y, itr_x, itr_y, _itr_dir) {
\
>+ if (!DIR_IS_CARDINAL(_itr_dir)) continue;
>
>-#define cartesian_adjacent_iterate_end \
>- } \
>-}
>+
>+#define cartesian_adjacent_iterate_end
\
>+ } adjc_dir_iterate_end
>
>
> /*
>
|
|