[Freeciv-Dev] Re: (PR#13474) a city_production struct
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13474 >
Vasco Alexandre da Silva Costa wrote:
> Seems fine to me. The low bits are the per-type id, and the high bits are
> the type id. We use bitfields already, this is not *that* different.
>
> As long as it was properly encapsulated, I see no problem. e.g.
>
> typedef uint32_t cid_t;
> typedef uint16_t id_t;
>
> cid_t cid_create(id_t high, id_t low);
> id_t cid_get_low(cid_t cid);
> id_t cid_get_high(cid_t cid);
> cid_t cid_set_low(cid_t cid, id_t low);
> cid_t cid_set_high(cid_t cid, id_t high);
>
> Macros would be faster.
This API is horrid and unreadible because "low" and "high" have no
meanings at all. Using integers for everything also makes it way too
easy to mix items. Taking advantage of C's typechecking is rather
advantageous.
>>If we were object-oriented we could use some sort of class hierarchy.
>>The C version would be to just use a void* (pointer-to-building,
>>pointer-to-unit, pointer-to-tech) and determine the type as needed.
>>
>>Why does a unique identifier need to be an integer rather than a pointer
>>or a struct?
>
> Serialization. An integer is serializable and a pointer is not. This is
> important for network transmission of data and savedgames.
Of course you can serialize a struct. We do exactly that with
req_sources. It doesn't even take any extra code (the analogue of
req_get_values would be needed inside cid_create anyway).
-jason
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Benoit Hudson, 2005/07/14
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Jason Short, 2005/07/14
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Vasco Alexandre da Silva Costa, 2005/07/15
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Vasco Alexandre da Silva Costa, 2005/07/15
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Benoit Hudson, 2005/07/15
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Jason Short, 2005/07/15
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Jason Short, 2005/07/15
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Vasco Alexandre da Silva Costa, 2005/07/16
- [Freeciv-Dev] Re: (PR#13474) a city_production struct,
Jason Short <=
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Vasco Alexandre da Silva Costa, 2005/07/18
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Jason Short, 2005/07/18
- [Freeciv-Dev] (PR#13474) a city_production struct, Jason Short, 2005/07/23
|
|