[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]
Dnia 2003.09.23 19:46, Jason Short napisa³(a):
>
> 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:
>
>
> 1. Change them both into standard functions.
>
> This is the prettiest solution. The only drawback is that it's
> slower - about a 5-10% slowdown in autogame performance in a few
> tests I did.
>
>
> 2. Change them both into inline functions.
>
> This is almost as pretty, and just as fast as the current code (for
> reasonable compilers). The only real drawback is that we're not
> "supposed" to use inline functions in freeciv. Also compilers that
> don't recognize inline will give warnings in files that don't use the
> functions (unavoidable when using inline).
>
>
> 3. Keep them as macros with temporary (global) variables in the
> header
> file.
>
> The obvious drawback is that this is incredibly ugly. The less
> obvious
> drawback is that the line
>
> array[map_pos_to_index(x, y)] = array[map_pos_to_index(x1, y1)]
>
> is not legal C (just like a ^= b ^= a ^= b). So without some other
> cleverness either all lines like this will have to be changed (see
> settlers.c and mapgen.c) or this is not an option. Gcc 3.2.1 just
> gives
> a warning, and *hopefully* compiles it into the proper code:
>
> settlers.c:167: warning: operation on `_fc_nat_y' may be undefined
> settlers.c:167: warning: operation on `_fc_nat_x' may be undefined
> settlers.c:169: warning: operation on `_fc_nat_y' may be undefined
> settlers.c:169: warning: operation on `_fc_nat_x' may be undefined
>
> If only C had tuples...
>
Jason could you show real map_to_native_pos(...) function/macro.
How complicatet it will be ?
Rafal
|
|