| [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]
 
 
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
 
[Freeciv-Dev] (PR#4004) A canvas_iterate macro for mapview,
Jason Short <=
Message not available
 
 |  |