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

[Freeciv-Dev] Re: [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] Re: [RFC] Attaching information to objects
From: Falk Hueffner <falk.hueffner@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: 13 Jan 2001 16:16:09 +0100

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?



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