Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2001:
[Freeciv-Dev] Re: Profiling Civserver again
Home

[Freeciv-Dev] Re: Profiling Civserver again

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Profiling Civserver again
From: Jason Dorje Short <jshort@xxxxxxxxxxxxx>
Date: Mon, 30 Jul 2001 02:17:06 -0400

"Ross W. Wetmore" wrote:
> 
> Attached is a quick hack of my accumulated macro patches into map.c, map.h
> for yesterday's CVS.

I'm not sure how to fit these together, but I have made changes to
current CVS that do the following:

- Implement a single adjc_all_iterate macro, and make macros
adjc_iterate, adjc_dir_iterate, and adjc_cart_iterate aliases for it. 
The macro works basically as Trent outlined, a single loop of one
variable using the DIR_DX2/DIR_DY2 variables.  It does not yet use his
algorithm for dealing with border cases, but can easily be extended to
do so.

- Replace all appropriate loops with one of these macros.  There were a
lot of them!

- Upgrade the loops to be consistent with the new system.  In particular
(1) loops that use an optional cardinal-only variable are much easier to
handle and (2) everything in the code uses the DIR_DX2/DIR_DY2
directional system instead of the old DIR_DX/DIR_DY system [1].

- Removed the variables DIR_DX, DIR_DY, DIR_CART_DX, and DIR_CART_DY.

- Wrote a few simple macros, functions, and variables. 
is_normal_map_pos(x, y) returns true iff (x, y) is in its normal
(canonical) form.  get_dir(x, y) returns the direction from the (x,y)
pair.  reverse(dir) returns the reverse of the direction [1].  DIR_NAMES
holds the names ("N", "NW", etc.) of each direction.  is_cardinal(dir)
behaves as you would expect.

- Removed a few manual checks that map positions were real/normal, and
replaced them with is_real_tile/is_normal_map_pos calls.

[1]  The biggest trouble I've had was figuring out that 128>>dir was
really supposed to be 1<<reverse(dir).  That should have been commented!

> The real advantage is probably when you go through a lot of the current
> code and replace the index computations with loop variables, i.e. replace
> MAP(x,y) with a MAP1(_xy) or the equivalent to avoid the endemic
> map.xsize*y+x on every access using base loop variables x,y.

There are three advantages here: the adjc_dir_iterate macro is simpler
(and harder to mess up) than manual iteration.  The new directional
system is _much_ easier to work with.  Finally, enhancing freeciv to
allow different map wrapping systems will be slightly easier.

I haven't quite finished upgrading all references to DIR_DX/DIR_DY, but
when I do I'll send the patch along.  Right now both server and (GTK)
client compile and run just fine (on an AI simulation).  Obviously, it
should not be applied before 1.12.0.

jason


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