Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: the directional system
Home

[Freeciv-Dev] Re: the directional system

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx (Freeciv developers)
Subject: [Freeciv-Dev] Re: the directional system
From: Reinier Post <rp@xxxxxxxxxx>
Date: Sun, 16 Sep 2001 12:50:02 +0200

On Fri, Sep 14, 2001 at 08:55:03PM +0200, Raimar Falke wrote:
> On Fri, Sep 07, 2001 at 02:18:45PM +0200, Raimar Falke wrote:
> > On Fri, Sep 07, 2001 at 04:51:36AM -0700, Trent Piepho wrote:
> > > On Fri, 7 Sep 2001, Jason Dorje Short wrote:
> > > 
> > > +#define DIR_REVERSE(dir) (((dir) + 4) % 8)
> > > 
> > > This is a faster way to do it.  Modulus operations are very expensive, 
> > > but a
> > > bitwise and is very cheap.
> > > 
> > > +#define DIR_REVERSE(dir) (((dir) + 4) & 7)
> 
> As one last experiment I change the current (7-dir) to the general
> form which will always work in every direction system:
> 
> diff -urd -X freeciv.current/diff_ignore freeciv.current/common/map.h 
> work/common/map.h
> --- freeciv.current/common/map.h        Fri Sep 14 09:31:33 2001
> +++ work/common/map.h   Fri Sep 14 18:47:39 2001
> @@ -442,7 +442,16 @@
>  };
> 
>  /* return the reverse of the direction */
> -#define DIR_REVERSE(dir) (7 - (dir))
> +#define DIR_REVERSE(dir) \
> +((dir)==DIR8_WEST?DIR8_EAST: \
> + ((dir)==DIR8_EAST?DIR8_WEST: \
> +  ((dir)==DIR8_NORTH?DIR8_SOUTH: \
> +   ((dir)==DIR8_SOUTH?DIR8_NORTH: \
> +    ((dir)==DIR8_NORTHWEST?DIR8_SOUTHEAST: \
> +     ((dir)==DIR8_NORTHEAST?DIR8_SOUTHWEST: \
> +      ((dir)==DIR8_SOUTHWEST?DIR8_NORTHEAST: \
> +       ((dir)==DIR8_SOUTHEAST?DIR8_NORTHWEST: \
> +       (dir)/0))))))))
> 
>  /* is the direction "cardinal"?  Cardinal directions
>   * (also called cartesian) are the four main ones */

This way you hardwire a 'chess-like' grid, which is less general than
a general rotational system.  For example, the 3 other types of regular
Cartesian grids (triangular, square without diagonals, hexagonal) cannot
be expressed in this way, while they would be fairly easy to implement
in Freeciv.

> So what do you expect as a slowdown? 10%? 5%? 2%? 1%? 0.1%? Not
> measurable?
> 
> 7-dir:
> user    1m32.890s
> user    1m32.730s
> user    1m33.030s
> user    1m32.890s
> user    1m32.460s
> user    1m32.720s
> user    1m32.750s
> average: 92.781s
> 
> general way:
> user    1m33.800s
> user    1m33.730s
> user    1m33.540s
> user    1m33.790s
> user    1m33.810s
> user    1m33.860s
> user    1m33.610s
> average: 93.734s
> 
> So the general form is 1% slower.
> 
>       Raimar

That's acceptable, and as long as no other grid types are supported,
it's obvious makes the code easier to understand.

-- 
Reinier


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