[Freeciv-Dev] Re: directional system: more magic code cleanups
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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.
If you spent a fraction of this time a month ago, or even in reviewing
what was done again in light of the fact that there is now a recognized
problem, you could be doing more productive things now :-).
Cheers,
RossW
=====
At 06:07 PM 01/09/18 +0200, Raimar Falke wrote:
>On Mon, Sep 17, 2001 at 01:01:51PM -0400, Jason Dorje Short wrote:
>> static int straightest_direction(int src_x, int src_y, int dest_x, int
>> dest_y)
>> {
>> int best_dir = -1, dir;
>> float best = -1;
>> int diff_x, diff_y;
>>
>> /* This code is topology-dependent */
>> diff_x = dest_x - src_x;
>> if (diff_x < -map.xsize / 2) diff_x += map.xsize;
>> if (diff_x > map.xsize / 2) diff_x -= map.xsize;
>> diff_y = dest_y - src_y;
>>
>> for (dir=0; dir<8; dir++) {
>> float product = diff_x * DIR_DX[dir] + diff_y * DIR_DY[dir];
>> product /= sqrt(DIR_DX[dir] * DIR_DX[dir] + DIR_DY[dir] *
>> DIR_DY[dir]);
>>
>> if (product > best) {
>> best = product;
>> best_dir = dir;
>> }
>> }
>>
>> assert(best >= 0 && best_dir >= 0);
>> return best_dir;
>> }
>
>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 Converted: "c:\program files\eudora\attach\diff33"
>
- [Freeciv-Dev] Re: directional system: more magic code cleanups, (continued)
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Gregory Berkolaiko, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Gregory Berkolaiko, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/18
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/18
- [Freeciv-Dev] Re: directional system: more magic code cleanups,
Ross W. Wetmore <=
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/18
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/19
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/20
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/20
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/21
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/21
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/23
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/24
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/24
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Ross W. Wetmore, 2001/09/25
|
|