Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2001:
[Freeciv-Dev] [RFC] Attaching information to objects
Home

[Freeciv-Dev] [RFC] Attaching information to objects

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] [RFC] Attaching information to objects
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 13 Jan 2001 12:41:41 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxxxx

For various reasons a way to attach additional information to cities,
units and players is needed.

The data has to be on the server since it should be included in the
savegame. Since the information should be extendible I would propose a
hash. The type of the key could be int or string. I would propose
int. The type of the value could be int, string, fixed array of
ints. Fixed array of ints would allow better performance for large
data however I don't thing it is worth the extra effort. So I propose
int for the value type. This is a problem if some code wants to attach
strings to objects. I don't expect any strings.

The result are methods like:

   void {city,unit,player}_set_storage(int key, int value);
   int {city,unit,player}_get_storage(int key, int default_value);

The default_value will be returned if the key is unset. The keys can
be dense (an enum for example) or spare (every part interrested will
get a range). Dense keys are easier to implement. However for large
data especially arrays a range may be easier to use. I didn't make a
decision yet.

The key spaces for each object type should be different.

Implementation:

If the keys will be dense and allocated by an enum per object type a
static array in the object type could be coded very easy. The client
will hold its own set of data and so cache the server data. If
set_storage will be called the client will send an update packet to
the server. The client cache can be filled lazy or after the first
contact of the client with the object.

What do you think?

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 1 + 1 = 3, for large values of 1



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