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

[Freeciv-Dev] Re: directional system: more magic code cleanups

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: jdorje@xxxxxxxxxxxxxxxxxxxxx, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: directional system: more magic code cleanups
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Tue, 18 Sep 2001 23:57:06 -0400

Attached is a copy of straightest_dir with yet another explanation 
of the algorithm embedded as comments in hopes that repetition will
eventually penetrate those that still haven't got it :-).

Note that to choose one of 8 directions, the absolute minimum work
is 3 binary compares, so there is still room for improvement in the
attached algorithm.

This should be compared to Raimar's latest compute intensive for loop
version, noting that they are both directional system dependent in
that they assume 2-D rectangular coordinate system x,y arguments, and 
return one of the 8 possible directions in this type of system.

This one deals with any of the 4 topologies obtained by wrapping one
of the 4 directions, but can be trivially modified to work with a
standard map, either by redefining the has_mapwrap function to return
constant values (compiler should optimize) or removing the appropriate 
tests manually.

Cheers,
RossW
=====

At 08:56 PM 01/09/18 -0400, Ross W. Wetmore wrote:
>Both of these are pretty expensive replacements for something that
>takes 4-6 compares and about the same number of arithmetic operations.
>
>I think in the end this will follow the same path as the previously
>submitted patch, modulo how you actually handle the case where the
>two directions are equal. In this case the earlier patch chooses
>diagonal over cartesian, which leaves the most flexibilty for the
>final moves.
[...]
>>I have attached a version which doesn't use float and sqrt. Please
>>review.
>>
>>      Raimar
>>-- 
>> email: rf13@xxxxxxxxxxxxxxxxx
>>  Living on earth may be expensive, but it includes an annual free trip
>>  around the sun.

Attachment: straightest_dir.c
Description: Text document






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