Complete.Org: Mailing Lists: Archives: freeciv-ai: May 2002:
[freeciv-ai] Re: [Freeciv-Dev] Re: [RFC] Path finding interface #9
Home

[freeciv-ai] Re: [Freeciv-Dev] Re: [RFC] Path finding interface #9

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Per I Mathisen <per@xxxxxxxxxxx>
Cc: freeciv development list <freeciv-ai@xxxxxxxxxxx>
Subject: [freeciv-ai] Re: [Freeciv-Dev] Re: [RFC] Path finding interface #9
From: Raimar Falke <rf13@xxxxxxxxxxxxxxxxx>
Date: Sat, 25 May 2002 20:03:58 +0200

On Sat, May 25, 2002 at 07:40:32PM +0200, Per I Mathisen wrote:
> What is the practical difference between
> 
> /*
>  * Tries to find the best path in the given map to the given
>  * destination position. The path will be written in the given struct
>  * pf_path. The caller should test path->found_a_valid.
>  */
> void pf_get_path(pf_map_t pf_map, int end_x, int end_y, struct pf_path *path);
> 
> and
> 
> /*
>  * Construct the whole path to the given location and write it into
>  * the given path. The location has to be obtained from
>  * pf_get_next_location.
>  */
> void pf_construct_path(pf_map_t pf_map, struct pf_path *path,
>                      const pf_location_t location);
> 
> ?

In the first the caller can directly specify the destination. In the
second case the destination is wrapped inside the opaque pf_location_t
which the caller gets from pf_get_next_location.

> Also, even though this is a more dangerous way to code, please make these
> functions give pointers to allocated structures as return values instead
> of passing pointers to existing structures by reference.

No. Either the pf_* functions allocate the space (and the callers
frees it. This malloc/free is unnecessary and will eat CPU cycles) or
the pf_* functions have static variables (which we want to avoid too
since. Look at the current warmap code).
 
> This way they become _a lot_ more readable, as we know what is happening
> just by looking at the code.
> 
> ie
>       struct pf_path path;
>       ...
>       pf_get_path(map,x,y,path);
>       ...
>       pf_get_path(map,x,y,path);

So what? path will deallocated if we leave to scope.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Reality? That's where the pizza delivery guy comes from!"


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