[Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Fri, Dec 14, 2001 at 09:40:55PM -0500, Ross W. Wetmore wrote:
> At 06:39 PM 01/12/13 +0000, Gregory Berkolaiko wrote:
> > --- Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
> >
> >> Your patch has code like
> >> + generate_warmap(NULL, x, y, NULL);
> >> + boatdist = get_warmap_sea(NULL, x, y);
> >>
> >> if this code uses a non-global warmap (which is the goal) it has to be
> >> changed to:
> >> + generate_warmap(&wm, x, y, NULL);
> >> + boatdist = get_warmap_sea(&wm, x, y);
> >>
> >> If you change your patch so that the code looks like
> >> + pwm = generate_warmap(x, y, NULL, 1);
> >> + boatdist = get_warmap_sea(pwm, x, y);
> >>
> >> that you only have to change the "1" to use a non-global warmap. The
> >> access function calls (get_warmap_sea and get_warmap_land) will remain
> >> unchanged.
> >
> >Aha, I undertand now. One very good argument in favour of not doing it
> >this way was given by Jason. I can only add a stupid argument: if you
> >allocate the memory yourself, you are more likely to remember to free it
> >(btw you forgot that to use non-local warmap, you have to do more than
> >change 0 to 1, you have to free pwm).
>
> Actually, it is not stupid. Forcing the caller to allocate the warmap
> and pass it in, keeps the allocation and deallocation at the same point
> in the code, and the responsibility clearly assigned.
The question is how is the warmap allocated at the caller? Like this:
void foobar(...)
{
int x,y,i;
struct warmap my_warmap;
or
void foobar(...)
{
int x,y,i;
struct warmap *my_warmap=fc_malloc(sizeof(struct warmap));
or
void foobar(...)
{
int x,y,i;
struct warmap *my_warmap=warmap_get_new_instance();
The first two have to be dropped because we agreed that outside code
shouldn't know about the struct. So I have no problem if there are:
struct warmap *warmap_new();
void warmap_init(struct warmap *,struct unit *,struct city *);
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
Windows: Where do you want to go today?
Linux: Where do you want to go tomorrow?
BSD: Are you guys coming or what?
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), (continued)
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Jason Short, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Raimar Falke, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Raimar Falke, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Raimar Falke, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Raimar Falke, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Ross W. Wetmore, 2001/12/14
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108),
Raimar Falke <=
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/15
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Raimar Falke, 2001/12/15
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Raimar Falke, 2001/12/14
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/14
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Raimar Falke, 2001/12/14
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/14
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Jason Short, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Raimar Falke, 2001/12/13
- [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108), Gregory Berkolaiko, 2001/12/14
|
|