<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40759 >

> [guest - Sun Apr 12 18:29:01 2009]:
> 
> > > - Perhaps the values of the unit upkeep field should be
> > > sent in unit info packets so that they do not have to
> > > be recomputed at the client side.
> >  
> > I will look into this.
> 
> Should this be something like in the attached file 
> (unit_upkeep_packages.patch.diff)? Or are additional changes needed?

The field 'upkeep' being an array (i.e. pointer) you need to
copy element by element (e.g. with a loop, memcpy, etc.).
Your way would only work if the memory for the unit struct
was not overwritten before the packet is serialized (likely
true, but not a good assumption to make).

Also you would need to "unpack" the value again at the client
side (from packet to unit struct). See unit info handling
functions in client/packhand.c.

I was also wondering whether there are any places in the
client that could make use of this extra information. This
would involve checking where the upkeep calculation functions
are called on the client side and simplifying the calling
code to instead use the punit->upkeep field. Better yet
would be to make an accessor unit_get_upkeep() (or with a
similar name), that would wrap read access to the field.
As a first step it could just use the old upkeep calculation
functions (i.e. so that it ends up executing the old code
path) so that you can test to make sure everything is
alright, then if everything is ok you can make it use
the punit->upkeep field by only having to change that one
function.

Hopefully the client uses the upkeep values in a simple
enough way that this would be possible, that is it avoids
any kind of tricky setting of the values or calculating
"virtual" values (i.e. upkeep for a unit that does not
actually exist in the game).


-----------------------------------------------------------------------
彼は陰険な奴である印象を受けた。

_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to