Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: to wrap or not to wrap?
Home

[Freeciv-Dev] Re: to wrap or not to wrap?

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: to wrap or not to wrap?
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 10 Oct 2001 22:20:52 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Wed, Oct 10, 2001 at 12:27:06PM -0400, Jason Dorje Short wrote:
> Raimar Falke wrote:
> > 
> > On Wed, Oct 10, 2001 at 11:39:19AM -0400, Jason Dorje Short wrote:
> > > Raimar Falke wrote:
> > > >
> > > > On Wed, Oct 10, 2001 at 10:34:13AM -0400, Jason Dorje Short wrote:
> 
> > > > > That is, if we limit our topologies to only those that wrap in simple
> > > > > ways, we can write a wrap_map_pos(&vx, &vy) function that will wrap 
> > > > > the
> > > > > given coordinate pair [1] independent of it's being a actual tile.  
> > > > > This
> > > > > can be used practically as-is in the current client implementation,
> > > > > although I strongly feel that this implementation is flawed and should
> > > > > be fixed anyway.
> 
> > > Like I said, it is confusing and will probably lead to misuse.
> > 
> > Usual question: who/what needs this? Note that the only wrapping
> > occurs at the GUI and even this case will be no longer if the client
> > draw each tile only one time.
> 
> AFAIK just the client.
> 
> Right now the client does only draw each tile one time.  However, it
> uses a "trick" to accomplish this:
> 
> /* x0, y0 is corner of canvas */
> /* width, height are dimensions of canvas */
> for (x=0; x<width; x++)
>   for (y=0; y<width; y++) {
>     x1 = x, y1 = y;
>     wrap_map_pos(&x1, &y1);
>     draw_tile(x0+x1, y0+y1);
>   }
> 
> See, (x1, y1) isn't an actual map position!  It's a vector representing
> the position of the tile on the map canvas.  If the canvas is wider than
> the map, then the tile *will* be drawn twice - but it'll be drawn in the
> same position so nobody notices (this could easily be avoided by
> restricting the size of the mapcanvas).  The important point, though, is
> that because (x1, y1) isn't an actual map position normalize_map_pos
> can't be used on it.
> 
> The "correct" way to do the drawing is like this, IMO:
> 
> for (x=0; x<width; x++)
>   for (y=0; y<height; y++) {
>     x1 = x0+x, y1 = y0+y;
>     if (normalize_map_pos(&x1, &y1))
>       draw_tile(x1, y1);
>     else
>       draw_black_tile(x1, y1);
>   }
> 
> This uses only mathematically correct operations on the map position. 
> In the case of the overhead view it is still easy to avoid drawing tiles
> multiple times [1] - 

> you just restrict the size of the map canvas [2]. 

What if in the above loop the width isn't the map canvas width, but
the map.xsize? It should be fine if you blank all tiles before.

> In the case of the isometric view the math would be harder but it would
> still be possible.
> 
> Gaute pointed out before that it doesn't matter which set of coordinates
> you choose to be proper/normal - it's just a convenience to make
> everything happen within map.xsize/map.ysize.  Mathematically this is
> correct, but wrap_map_pos is not mathematically clean - the client MUST
> have each vector returned by wrap_map_pos be exactly correct.
> 
> [1] Personally, I would prefer to have tiles drawn multiple times.  But
> that's just me...

If it is cleaner what is needed for one-drawing and what for the
multiple drawing I don't have a problem. This can be a compile or
run-time constant. However it looks to me that the easier goal of the
next step is the one-time draw solution.

> [2] This really seems like the obvious solution.  Does anyone know why
> it wasn't used before?

So in overall we don't need the method you suggested?!

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "The BeOS takes the best features from the major operating systems. 
  It's got the power and flexibility of Unix, the interface and ease 
  of use of the MacOS, and Minesweeper from Windows."


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