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: rf13@xxxxxxxxxxxxxxxxxxxxxx, "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Cc: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Changing interface for generate_warmap (PR#1108)
From: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Date: Sat, 15 Dec 2001 13:25:49 +0000 (GMT)

 --- 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.

G.

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


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