Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] Re: (PR#11154) client has unrefreshed cities
Home

[Freeciv-Dev] Re: (PR#11154) client has unrefreshed cities

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#11154) client has unrefreshed cities
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Nov 2004 13:25:05 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11154 >

Per I. Mathisen wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=11154 >
> 
> On Tue, 23 Nov 2004, Jason Short wrote:
> 
>>>When cm_query_result is called on a city by the *client*, it is
>>>sometimes called on an unrefreshed city.In this case
>>>pcity->science_bonus == 100, instead of having the correct value.
>>>Calling generic_city_refresh at the start of cm_query_result seems to
>>>fix it but there should be a better way.
>>
>>Here's a patch.It's easy enough to add an assertion here to verify
>>that this actually does change (among other things) pcity->science_bonus.
>>
>>This speeds up the CM slightly at the client: 0.7s instead of 0.8s in my
>>test.
> 
> In the server, cities are always "fresh" (ie whenever something changes,
> we refresh before continuing). So the CM should never refresh a city when
> it runs in the server, I think.

This patch adds a generic_city_refresh to the client any time city data 
is received.

It also adds a sanity check to cm.c.  This may be overkill but it 
shouldn't measurably impact performance.

jason

? new
? orig
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.422
diff -u -r1.422 packhand.c
--- client/packhand.c   22 Nov 2004 19:31:30 -0000      1.422
+++ client/packhand.c   23 Nov 2004 21:23:30 -0000
@@ -579,6 +579,10 @@
 {
   int i;
 
+  if (city_owner(pcity) == game.player_ptr) {
+    generic_city_refresh(pcity, FALSE, 0);
+  }
+
   if(is_new) {
     unit_list_init(&pcity->units_supported);
     unit_list_init(&pcity->info_units_supported);
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.44
diff -u -r1.44 cm.c
--- common/aicore/cm.c  19 Nov 2004 02:31:35 -0000      1.44
+++ common/aicore/cm.c  23 Nov 2004 21:23:30 -0000
@@ -1825,6 +1825,22 @@
 {
   struct cm_state *state = cm_init_state(pcity);
 
+#ifdef DEBUG
+  {
+    struct city old_city = *pcity;
+
+    /* FIXME: there's a bug in the client causing cm_query_result to be called
+     * on unrefreshed cities.  To avoid problems we just call refresh once
+     * here to start. */
+    generic_city_refresh(pcity, FALSE, 0);
+
+    assert(pcity->science_bonus == old_city.science_bonus
+          && pcity->tax_bonus == old_city.tax_bonus
+          && pcity->luxury_bonus == old_city.luxury_bonus
+          && pcity->shield_bonus == old_city.shield_bonus);
+  }
+#endif
+
   cm_find_best_solution(state, param, result);
   cm_free_state(state);
 }

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