Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: PATCH: map iteration (PR#1018)
Home

[Freeciv-Dev] Re: PATCH: map iteration (PR#1018)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>, jdorje@xxxxxxxxxxxxxxxxxxxxx, freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: PATCH: map iteration (PR#1018)
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Sat, 20 Oct 2001 11:03:00 -0400

At 09:51 AM 01/10/20 +0200, Raimar Falke wrote:
>On Fri, Oct 19, 2001 at 09:15:46PM -0400, Ross W. Wetmore wrote:
>> The is_normal_map_pos() solution is really just a bad hack because you 
>> aren't willing to think about the case and fix it right at the moment :-).
>> 
>> But in most cases, the right fix it is far easier than what you are 
>> proposing.
>> 
>> The examples below should use whole_map_iterate(). When you get weird
>> maps, then whole_map_iterate() will become weird, but until then it will
>> remain as is, i.e. efficient iteration over the whole map. The change
>> when needed is to 1 line of code in a header.
>
>Yes whole_map_iterate should be prefered. However whole_map_iterate
>doesn't allow an action if the map position is unreal or an extra
>action for every new line.

All the *_iterate macros can be coded to have the form

  <loop stuff>
  if( normalize_map_pos() ) {
  
    <User code here>

  } <end loop stuff>

There is no problem with <User code here> haviing the form

    <real User code >
  } else {
    <unreal User code>

So, you may just have to do a little more standardizing in the iterate
macros to make a nice general condition into part of the interface.

Cheers,
RossW
=====

>What about a new macro:
>
>#define whole_map_iterate(x_itr, y_itr,new_line_code,real_code, unreal_code)
>{
>  int x_itr, y_itr;
>  for (y_itr = 0; y_itr < map.ysize; y_itr++){
>       new_line_code;
>    for (x_itr = 0; x_itr < map.xsize; x_itr++)
>    {
>       if(is_normal_map_pos(...))
>       {
>               real_code;
>       }
>       else
>       {
>               unreal_code;
>       }
>    }
>
>???
>
>> You want to use square_iterate() or block_iterate() in most of the 
>> other cases. These functions do the right thing by definition. They
>> will also not change until they need to.
>
>       Raimar
>
>-- 
> email: rf13@xxxxxxxxxxxxxxxxx
>    1) Customers cause problems.
>    2) Marketing is trying to create more customers.
>  Therefore:
>    3) Marketing is evil.
>



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