[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 >
On Fri, 15 Jul 2005, Jason Short wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=13474 >
>
> Vasco Alexandre da Silva Costa wrote:
>
> > Why not do it the other way around? i.e. Replace pcity->is_building_unit
> > and pcity->currently_building with pcity->production which is a cid or
> > wid, whatever?
>
> Because cid is an overloaded integer: not very pretty, not typesafe, etc.
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.
> > A unique identifier for things which can be produced at a city is useful
> > in lots of places and I am uncertain turning this into a struct is a very
> > good idea.
>
> In that case I'd rather have a unique identifier for all items -
> including techs, etc. Tech production works at the player level exactly
> as unit/building production works at the city level.
A unique identifier for all items would also be interesting. Although a
compound id does makes sense. Think of a compound id like telephone
numbers with an area code.
> 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.
---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa
- [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 <=
- [Freeciv-Dev] Re: (PR#13474) a city_production struct, Jason Short, 2005/07/17
- [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
|
|