[Freeciv-Dev] Re: the directional system
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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 */
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
--
email: rf13@xxxxxxxxxxxxxxxxx
"At the beginning of the week, we sealed ten BSD programmers
into a computer room with a single distribution of BSD Unix.
Upon opening the room after seven days, we found all ten programmers
dead, clutching each other's throats, and thirteen new flavors of BSD."
- [Freeciv-Dev] the directional system, Jason Dorje Short, 2001/09/07
- [Freeciv-Dev] Re: the directional system, Trent Piepho, 2001/09/07
- [Freeciv-Dev] Re: the directional system, Raimar Falke, 2001/09/07
- [Freeciv-Dev] Re: the directional system, Greg Wooledge, 2001/09/07
- [Freeciv-Dev] Re: the directional system, Ross W. Wetmore, 2001/09/07
- [Freeciv-Dev] Re: the directional system, Raimar Falke, 2001/09/08
- [Freeciv-Dev] Re: the directional system, Gaute B Strokkenes, 2001/09/11
- [Freeciv-Dev] Re: the directional system, Raimar Falke, 2001/09/12
- [Freeciv-Dev] Re: the directional system, Gaute B Strokkenes, 2001/09/13
- [Freeciv-Dev] Re: the directional system, Raimar Falke, 2001/09/14
- [Freeciv-Dev] Re: the directional system,
Raimar Falke <=
- [Freeciv-Dev] Re: the directional system, Reinier Post, 2001/09/16
- [Freeciv-Dev] Re: the directional system, Raimar Falke, 2001/09/16
- [Freeciv-Dev] Re: the directional system, Reinier Post, 2001/09/17
[Freeciv-Dev] Re: the directional system, Raimar Falke, 2001/09/07
|
|