Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2001:
[Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108)
Home

[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]
To: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Cc: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 15 Dec 2001 15:11:15 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Sat, Dec 15, 2001 at 01:25:49PM +0000, Gregory Berkolaiko wrote:
>  --- Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> wrote: 
> > On Fri, Dec 14, 2001 at 09:40:55PM -0500, Ross W. Wetmore wrote:
> > 
> > > 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 *);
> 
> You might have noticed that my patch already contains:
> ============================================================
> +/************************************************
> + * Allocate new warmap
> + ************************************************/
> +struct move_cost_map *get_new_warmap(void)
> +{
> +  struct move_cost_map *new_warmap;
> +  int x;  
> +  
> +  new_warmap = fc_malloc(sizeof(struct move_cost_map));
> +  for (x = 0; x < map.xsize; x++) {
> +    new_warmap->cost[x]=fc_malloc(map.ysize*sizeof(unsigned char));
> +    new_warmap->seacost[x]=fc_malloc(map.ysize*sizeof(unsigned char));
> +    new_warmap->vector[x]=fc_malloc(map.ysize*sizeof(unsigned char));
> +  }
> +  new_warmap->sea_recycle = FALSE;
> +  new_warmap->land_recycle = FALSE;
> +  return new_warmap;
> +}
> ============================================================
> 
> I am glad that you now think it's ok.

Nitpicking: which isn't exported and results in a compile error if
compiled with strict settings like "-Wmissing-prototypes
-Wmissing-declarations -Werror".

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Python 2.0 beta 1 is now available [...]. There is a long list of new 
  features since Python 1.6, released earlier today. We don't plan on 
  any new releases in the next 24 hours."
    -- Jeremy Hylton at Slashdot


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