[Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Mon, Aug 20, 2001 at 11:15:02PM +0300, Markus Linnala wrote:
> Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> writes:
>
> > It is. I would like a discussion what is preferred: id or pointer. If
> > one type is selected we can start our crusade.
I like ids more but a lot of the methods in the call chains need
certain attributes of an object (unit, citiy,...). These attributes
are only accessible with a pointer or accessor methods (which I
consider silly in freeciv). So to me the rule should be to transfer
pointers as arguements and let only handle the lower network layers
with ids.
I see one disadvantage of pointers: the validity isn't automatically
checked. If a method has an id and want to access some attributes it
has to use a find_object_by_id method. Such a method will test if the
given id is still valid. A pointer will always be valid. So a new
field in every struct is needed to indicate invalid structs. Such a
flag will be set if a remove_unit packet is received for example.
> With get_player, I think we need both and both inlined.
> get_player is there to make things more understandable. Maybe we
> should make some extra checks.
>
> ------------------------------------------------------------------------
> struct player *get_player(int player_id)
> {
> assert(player_id >= 0 && player_id < game.max_players);
> return &game.players[player_id];
> }
> int get_player_by_id(struct player *pplayer)
> {
> assert(pplayer->player_no >= 0 && pplayer->player_no < game.max_players);
> return pplayer->player_no;
> }
> ------------------------------------------------------------------------
>
> Or something like that. Well, not so good example. But as simple
> functions as these are, you might get smaller code size and game
> is definitely faster when you get rid of actual function call.
IMHO the access to a id/player_no field shouldn't be made more
complex. However I would like methods like "is_valid_punit" and
"ensure_valid_punit".
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"Windows is the one true OS. MS invented the GUI. MS invented
the 32 bit OS. MS is open and standard. MS loves you. We have
always been at war with Oceana."
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, (continued)
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Raimar Falke, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Justin Moore, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Raimar Falke, 2001/08/22
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Justin Moore, 2001/08/22
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Raimar Falke, 2001/08/22
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Trent Piepho, 2001/08/22
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Justin Moore, 2001/08/23
- Message not available
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Ross W. Wetmore, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Raimar Falke, 2001/08/22
[Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Markus Linnala, 2001/08/20
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand,
Raimar Falke <=
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Trent Piepho, 2001/08/20
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Raimar Falke, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Trent Piepho, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Raimar Falke, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Trent Piepho, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Raimar Falke, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Trent Piepho, 2001/08/21
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Kevin Brown, 2001/08/22
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Erik Sigra, 2001/08/22
- [Freeciv-Dev] Re: [PATCH] Small improvement at genlist and maphand, Raimar Falke, 2001/08/22
|
|