Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: example patch: [xy]_map_iterate
Home

[Freeciv-Dev] Re: example patch: [xy]_map_iterate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: example patch: [xy]_map_iterate
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 4 Oct 2001 12:41:08 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Thu, Oct 04, 2001 at 05:57:09AM -0400, Jason Dorje Short wrote:
> There's a lot of code that can't use whole_map_iterate because the
> iteration has to happen in a certain order.

What code? I don't have a good feeling with code that has such
dependencies. Printing the map?

> I propose to use a new set of iterators to handle these iterations.  To
> begin with, we'll have [xy]_map_iterate which will iterate over the
> *full range* of [xy] values.  With the current rectangular map this is
> simple enough, but say we had an isometric map:
> 
>   0 1 2 3 4
> 0     X
> 1   X X X
> 2 X X X X X
> 3   X X X
> 4     X
> 
> Each of x_map_iterate and y_map_iterate would iterate from 0 to 4.
> 
> (Note: I'm not sure of the nomenclature here.  Are these names okay?)
> 
> In many cases we might then want another pair of iterators, for instance
> yx_map_iterate(y,x_itr) will iterate over the full set of x coordinates
> for the given set of y coordinates (here the naming becomes even
> harder).  For this patch, though, I've just handled a couple cases where
> we iterate over the entire rectangle (in the above case [0..4]x[0..4])
> and do a check for is_normal_map_pos to determine how to handle things
> [1].  The associated code segments, therefore, should work with any
> possible topology assuming x_map_iterate, y_map_iterate, and
> is_normal_map_pos [2] are set up correctly.
> 
> Frankly, I like it a lot.

So there are two possible implementations for whole_map_iterate:

 for(index=0;index<max_index;index++)
 {
   int x,y;
   index_to_map_pos(&x,&y,index);
   /* BODY */
 }

and

  int x,y;
  for(y=0;y < map.ysize; y++)
    for(x=0; x < map.xsize; x++)
      if(is_normal_map_pos(x,y))
         /* BODY */

Correct?

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "The two rules for success in life are:
  1) Never tell them everything you know."


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