Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2002:
[Freeciv-Dev] Re: Question about attributes
Home

[Freeciv-Dev] Re: Question about attributes

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Teemu Kurppa <tkurppa@xxxxxxxxxx>
Cc: freeciv-dev <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Question about attributes
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 Jan 2002 17:13:08 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Tue, Jan 08, 2002 at 07:26:05PM +0200, Teemu Kurppa wrote:
> On Tue, 8 Jan 2002, Raimar Falke wrote:
> 
> > On Tue, Jan 08, 2002 at 02:51:30PM +0200, Teemu Kurppa wrote:
> > > This makes coding a little bit cumbersome compared to solution, in
> > > which persistent data is restored to client side data structures,
> > > when client reconnects.
> > 
> > Can you save the client side data structures directly in the
> > attributes?
> 
> With a current data structure, list, no. And I think that a list is a
> natural choice for markers. I'd like to keep them in list instead of
> an array.

You do something like this:

+struct tile_marker* find_marker_at(int x, int y)
+{
   int i, size, markers;
   struct tile_marker *p;

   size=attr_player_get(ATTR_TILE_MARKERS, game.player_idx, 0, NULL);
   markers=size/sizeof(struct tile_marker);
   p=malloc(size);
   attr_player_get(ATTR_TILE_MARKERS, game.player_idx, size, p);

   for(i=0;i<markers;i++)
   {
     if(p[i]->x == x && p[i]->y == y) {
       return marker_clone(p[i]);         // needed because p gets freed
     }
   }
   free(p);
}

and
+void add_marker(struct tile_marker* pnew)
{
   int i, old_size, new_size, new_marker;
   struct tile_marker *p;

   old_size=attr_player_get(ATTR_TILE_MARKERS, game.player_idx, 0, NULL);
   new_size=old_size+sizeof(struct tile_marker);
   new_marker=old_size/sizeof(struct tile_marker);
   p=malloc(new_size);
   attr_player_get(ATTR_TILE_MARKERS, game.player_idx, old_size, p);
   p[new_marker]->x=pnew->x;
   p[new_marker]->y=pnew->y;
   p[new_marker]->num=pnew->num;
   attr_player_get(ATTR_TILE_MARKERS, game.player_idx, new_size, p);
}
  
> > > Another concern: I think that a client should flush attributes to a
> > > server, when a player decides to disconnect. Currently it flushes them
> > > only at the end of turn.
> > 
> > Same as above: attributes aren't yet used. I agree. Note that you can
> > also manually flush them.
> 
> Yeah I know, and attached "patch" will flush attributes, when player
> disconnects ;)  

Applied.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Life is too short for reboots."


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