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: freeciv development list <freeciv-ai@xxxxxxxxxxx>
Subject: [freeciv-ai] Re: [Freeciv-Dev] Re: [RFC] Path finding interface #9
From: Per I Mathisen <per@xxxxxxxxxxx>
Date: Sat, 25 May 2002 19:40:32 +0200 (MEST)

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);

?

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.

I mean...

void pf_get_path(pf_map_t pf_map, int end_x, int end_y, struct pf_path *path);
void pf_construct_path(pf_map_t pf_map, struct pf_path *path,
                       const pf_location_t location);
bool pf_get_next_location(pf_map_t pf_map, pf_location_t *location);

...should be...

struct pf_path *pf_get_path(pf_map_t pf_map, int end_x, int end_y);
struct pf_path * pf_construct_path(pf_map_t pf_map, const pf_location_t 
location);
struct pf_location_t *pf_get_next_location(pf_map_t pf_map);

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);

compared to

        struct pf_path *path;
        ...
        path = pf_get_path(map,x,y);
        ...
        free(path);
        path = pf_get_path(map,x,y);

Yours,
Per

"It is difficult to catch a black cat in a
dark room. Especially if there is no cat
there." - Confucius



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