[Freeciv-Dev] Re: [RFC] Attaching information to objects
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> writes:
> 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.
Rethinking it, perhaps an int as key is actually better, since
otherwise we'd have to do memory management for it, which is not
really nice in C. One could use 4-letter constants like 'GOTO' or
'IMPR' to make it more readable.
Implementation in server could be:
Have a hash_table for each player. It maps the mentioned int keys to a
pointer to another hash_table. This hash table uses as key four bits
for the object type (player, unit, city, tile), and the rest for the
ID[1]. It maps to a pointer to
struct Data {
int length;
char data[1]; /* actually length bytes */
};
which gets dynamically allocated. What do you think about this?
Falk
[1] It seems when using ints as keys, the current code uses the void*
of the hash_bucket to point to the int, instead of stuffing the int
directly into the void* (which should always be at least as large as
an int). Is there a certain reason for this?
|
|