Complete.Org: Mailing Lists: Archives: freeciv-dev: February 1999:
Re: [Freeciv-Dev] new kludge cleanup patch
Home

Re: [Freeciv-Dev] new kludge cleanup patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: Re: [Freeciv-Dev] new kludge cleanup patch
From: Trent Piepho <xyzzy@xxxxxxxxxxxxxxxx>
Date: Wed, 3 Feb 1999 00:58:44 -0800 (PST)

On Wed, 3 Feb 1999, David Pfitzner wrote:
> Though its not entirely clean (using global function pointers!)
> so if anyone wants to write a module in common which does an 
> ident to (unit,city) pointers lookup table, go right aheaad :-)

Why not move the city_id code to common as it is now.  Add a line to
find_city_by_id(), that checks for citycachesize!=0.  For example:

struct city *find_city_by_id(int id)
{
+ if(!citycachesize) return game_find_city_by_id(id);
  if(id<0 || id>=citycachesize) return 0;
  return citycache[id];
}

Put the city cache functions (all 5 of them) and the two static globals into
some common/ file.  Might as well put the city id->pointer functions that
search through lists (ie. game_fcbi) in there as well.

As far as I can tell this should work fine.  Code that wants to use the
citycache for speed should call initialize_city_cache() first, like it does
now.  This will set citycachesize so find_city_by_id() will use the cache. 
Code that doesn't want to use the cache, doesn't initialize it.  Putting a
check for !citycache size in add_city_to_cache() and remove_city_from_cache()
means common code can use those functions as well.  All instances of
game_find_city_by_id() should be changed to find_city_by_id(), which is a good
thing IMHO, having two different function names for the common and server code
is annoying.

Can anyone see any problems with this?  Does it do what the utilities people
need?  Other than moving the code to common, it's only a three line diff.



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