Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] (PR#4004) A canvas_iterate macro for mapview
Home

[Freeciv-Dev] (PR#4004) A canvas_iterate macro for mapview

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#4004) A canvas_iterate macro for mapview
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 14 Apr 2003 10:31:57 -0700
Reply-to: rt@xxxxxxxxxxxxxx

I would like to write a new macro, canvas_iterate, to the mapview code. 
  The interface is

   canvas_iterate(canvas_x0, canvas_y0, width, height, x_itr, y_itr)

and it iterates over the mapview canvas, *in map coordinates*.  Thus to 
iterate over every tile on the canvas we do

   canvas_iterate(0, 0, mapview_canvas.width, mapview_canvas.height,
                  x, y) {
     ...
   } canvas_iterate_end;

and it is useful for just about every iteration we'd ever need.


The problem, naturally, is with implementation.  I haven't thought about 
this much, but the only iteration I can come up with is

   #define canvas_iterate(cx0, cy0, w, h, x, y)
     whole_map_iterate(x, y) {
       int cx, cy;
       map_to_canvas_pos(&cx, &cy, x, y);
       if (cx > cx0 - NORMAL_TILE_WIDTH
           && cy > cy0 - NORMAL_TILE_HEIGHT
           && cx <= cx + w
           && cy <= cy + h) {

which is extremely inefficient.

To make the iterator more useful, it should guarantee the order of 
iteration to be top->bottom, left->right (which the above does not do).


More on this to come.

jason




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