Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] Re: (PR#13474) a city_production struct
Home

[Freeciv-Dev] Re: (PR#13474) a city_production struct

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13474) a city_production struct
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 17 Jul 2005 04:23:16 -0700
Reply-to: bugs@xxxxxxxxxxx

<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





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