Re: [Freeciv-Dev] grid lines
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Thu, 18 Mar 1999, Vasco Alexandre Da Silva Costa wrote:
> Why are you doing that x*NORMAL_TILE_WIDTH stuff over and over again?
> Most things can be precalculated...
>
> n_tile_x *= NORMAL_TILE_WIDTH;
> n_width *= NORMAL_TILE_WIDTH;
>
> n_tile_y *= NORMAL_TILE_HEIGHT;
> n_height *= NORMAL_TILE_HEIGHT;
>
> for(x=tile_x; x<=n_tile_x+n_width; x+=NORMAL_TILE_WIDTH)
> XDrawLine(display, map_canvas_store, civ_gc,
> x, n_tile_y,
> x, n_tile_y+n_height);
>
> for(y=tile_y; y<=n_tile_y+n_height; y+=NORMAL_TILE_HEIGHT)
> XDrawLine(display, map_canvas_store, civ_gc,
> n_tile_x, y,
> n_tile_x+n_width, y);
Why do n_tile_x+n_width over and over again? That's another loop invariant
that can be moved out.
y1 = tile_y*NORMAL_TILE_HEIGHT; y2 = (tile_y+height)*NORMAL_TILE_HEIGHT;
x1 = tile_x*NORMAL_TILE_WIDTH; x2 = (tile_x+width)*NORMAL_TILE_WIDTH;
for(x=x1; x<=x2; x+=NORMAL_TILE_WIDTH)
XDrawLine(display, map_canvas_store, civ_gc, x, y1, x, y2);
for(y=y1; y<=y2; y+=NORMAL_TILE_HEIGHT)
XDrawLine(display, map_canvas_store, civ_gc, x1, y, x2, y);
I thought gcc would be smart enought to notice the loop invariants, but it
seems it isn't. It doesn't make a lot of difference though. I tried timing
both versions with the pentium cycle counter, and there's really no detectable
difference.
|
|