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 13:37:06 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Thu, Oct 04, 2001 at 07:00:01AM -0400, Jason Dorje Short wrote:
> Raimar Falke wrote:
> > 
> > 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?
> 
> Printing the map (to some random text file, I presume) is part of it. 
> Also saving the game and sending tiles across the network.  These depend
> strictly upon the ordering, so are easy to fix using [xy]_map_iterate.

So what code would be used (after preprocessor expansion) instead of

  for(y=0; y<map.ysize; y++) {
    char *terline=secfile_lookup_str(file, "map.l%03d", y);

    for(x=0; x<map.xsize; x++) {
      char ch=terline[x];

with an isometric map? Will there be map.xsize and map.ysize in an
isometric map?

> Other examples don't iterate over the whole map...for instance some
> iterate over just the poles while others skip border positions.  These
> can be done with whole_map_iterate by skipping invalid positions; the
> problem here is that the current definition of "valid" is
> topology-dependent (it assumes the current wrapping system).  These will
> take a little time to figure out.

For the poles I can imagine a rectangle_iterare.

> All in all, there are 30-50 such cases.  Try grepping for
> "for.*x.*map.xsize".  Most of them are in the savegame code, which I'm
> not particularly familiar with.

> >  {
> >    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?
> 
> Yes.
> 
> Here's are some other possible implementations, basically improvements
> on the second one of yours:
> 
>   y_map_iterate(y_itr)
>     x_map_iterate(x_itr)
>       if (is_normal_map_pos(x, y))
>         /* BODY */
> 
> This one is identical to your second case, but with macros (fully
> topology-independent).
> 
>   y_map_iterate(y_itr)
>     yx_map_iterate(y_itr, x_itr)
>       /* BODY */
> 
> This is identical to your second case under the current topology, but
> possibly faster under arbitrary topologies.  Of course, there's no
> yx_map_iterate yet (it iterates over x_itr given y_itr - the
> nomenclature is confusing but I can't think of anything better yet).

column_iterate?

        Raimar
-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "#!/usr/bin/perl -w
  if ( `date +%w` != 1 ) {
    die "This script only works on Mondays." ;
  }"
    -- from chkars.pl by Cornelius Krasel in de.comp.os.linux.misc


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