Re: [Freeciv-Dev] (PR#40282) Re: Patch: CMA fix when loading saved game

2008-06-16 Thread Patrick Smith

http://bugs.freeciv.org/Ticket/Display.html?id=40282 >

I'm not surprised you didn't want to use my hack.  :-)

I tried your patch against 2.1.4. The changes to packhand.c didn't apply
cleanly and I had to do them by hand. Then when I tried to load a saved
game, I got this when I starting the game:

civclient: agents.c:768: wait_for_requests: Assertion
`agent->first_outstanding_request_id == 0' failed.
Aborted

I'll send you a savegame separately (it's about 700K, so I don't want to CC
[EMAIL PROTECTED], which looks like a list, with it).

Pat

On Sun, Jun 15, 2008 at 10:38 AM, Marko Lindqvist <[EMAIL PROTECTED]> wrote:

> > 2008/6/10 Patrick Smith:
> >> Hi,
> >>
> >> The attached patch seems to fix some CMA problems when loading a saved
> game.
> >> The city report still indicates fairly random CMA choices for cities,
> but
> >> some messages about the governor being confused seem to have
> disappeared,
> >> and I can now set the governor as I wish after loading a game, which
> wasn't
> >> always possible before.
>
>  Your patch was a bit too hackish. For example, it handled only first
> connection client made. If client reconnects to same or another
> server, your fix was not used at all.
>  Based on your comments about the actual problem and its reasons, I
> wrote a bit different patch. It is attached to this email. Can you
> test if it fixes the problems. (This version is written against TRUNK,
> I don't know if it applies cleanly to other branches)
>
>
>  - ML
>

I'm not surprised you didn't want to use my hack.  :-)I tried your patch against 2.1.4. The changes to packhand.c didn't apply cleanly and I had to do them by hand. Then when I tried to load a saved game, I got this when I starting the game:
civclient: agents.c:768: wait_for_requests: Assertion `agent->first_outstanding_request_id == 0' failed.AbortedI'll send you a savegame separately (it's about 700K, so I don't want to CC [EMAIL PROTECTED], which looks like a list, with it).
PatOn Sun, Jun 15, 2008 at 10:38 AM, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> 2008/6/10 Patrick Smith:
>> Hi,
>>
>> The attached patch seems to fix some CMA problems when loading a saved game.
>> The city report still indicates fairly random CMA choices for cities, but
>> some messages about the governor being confused seem to have disappeared,
>> and I can now set the governor as I wish after loading a game, which wasn't
>> always possible before.

 Your patch was a bit too hackish. For example, it handled only first
connection client made. If client reconnects to same or another
server, your fix was not used at all.
 Based on your comments about the actual problem and its reasons, I
wrote a bit different patch. It is attached to this email. Can you
test if it fixes the problems. (This version is written against TRUNK,
I don't know if it applies cleanly to other branches)


 - ML

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


Re: [Freeciv-Dev] (PR#40282) Re: Patch: CMA fix when loading saved game

2008-06-15 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=40282 >

> 2008/6/10 Patrick Smith:
>> Hi,
>>
>> The attached patch seems to fix some CMA problems when loading a saved game.
>> The city report still indicates fairly random CMA choices for cities, but
>> some messages about the governor being confused seem to have disappeared,
>> and I can now set the governor as I wish after loading a game, which wasn't
>> always possible before.

 Your patch was a bit too hackish. For example, it handled only first
connection client made. If client reconnects to same or another
server, your fix was not used at all.
 Based on your comments about the actual problem and its reasons, I
wrote a bit different patch. It is attached to this email. Can you
test if it fixes the problems. (This version is written against TRUNK,
I don't know if it applies cleanly to other branches)


 - ML

diff -Nurd -X.diff_ignore freeciv/client/agents/cma_core.c 
freeciv/client/agents/cma_core.c
--- freeciv/client/agents/cma_core.c2008-03-10 20:08:04.0 +0200
+++ freeciv/client/agents/cma_core.c2008-06-15 20:17:12.0 +0300
@@ -48,6 +48,8 @@
 
 #include "cma_core.h"
 
+static bool cma_frozen;
+
 /*
  * The CMA is an agent. The CMA will subscribe itself to all city
  * events. So if a city changes the callback function city_changed is
@@ -362,6 +364,10 @@
   bool handled;
   int i, city_id = pcity->id;
 
+  if (cma_frozen) {
+return;
+  }
+
   freelog(HANDLE_CITY_LOG_LEVEL,
  "handle_city(city %d=\"%s\") pos=(%d,%d) owner=%s",
  pcity->id,
@@ -505,13 +511,14 @@
 ...
 */
 bool cma_apply_result(struct city *pcity,
-const struct cm_result *const result)
+  const struct cm_result *const result)
 {
   assert(!cma_is_city_under_agent(pcity, NULL));
   if (result->found_a_valid) {
 return apply_result_on_server(pcity, result);
-  } else
+  } else {
 return TRUE; /*  */
+  }
 }
 
 /
@@ -635,3 +642,25 @@
 
   attr_city_set(attr, city_id, SAVED_PARAMETER_SIZE, buffer);
 }
+
+/**
+  Freeze CMA not to act while cities have inconsistent state.
+**/
+void cma_freeze(void)
+{
+  cma_frozen = TRUE;
+}
+
+/**
+  Thaw CMA when cities reach consistent state.
+**/
+void cma_thaw(void)
+{
+  cma_frozen = FALSE;
+
+  cities_iterate(pcity) {
+if (cma_is_city_under_agent(pcity, NULL)) {
+  city_changed(pcity->id);
+}
+  } cities_iterate_end;
+}
diff -Nurd -X.diff_ignore freeciv/client/agents/cma_core.h 
freeciv/client/agents/cma_core.h
--- freeciv/client/agents/cma_core.h2007-08-04 18:38:37.0 +0300
+++ freeciv/client/agents/cma_core.h2008-06-15 20:18:20.0 +0300
@@ -37,6 +37,10 @@
  */
 void cma_init(void);
 
+/* Freeze cma for the time cities have inconsistent state */
+void cma_freeze(void);
+void cma_thaw(void);
+
 /* Change the actual city setting. */
 bool cma_apply_result(struct city *pcity,
  const struct cm_result *const result);
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c   2008-05-13 13:26:10.0 +0300
+++ freeciv/client/packhand.c   2008-06-15 20:27:01.0 +0300
@@ -18,16 +18,19 @@
 #include 
 #include 
 
+/* utility */
 #include "capability.h"
 #include "capstr.h"
-#include "events.h"
 #include "fcintl.h"
+#include "log.h"
+#include "mem.h"
+
+/* common */
+#include "events.h"
 #include "game.h"
 #include "government.h"
 #include "idex.h"
-#include "log.h"
 #include "map.h"
-#include "mem.h"
 #include "nation.h"
 #include "packets.h"
 #include "player.h"
@@ -38,7 +41,7 @@
 #include "unitlist.h"
 #include "worklist.h"
 
-#include "agents.h"
+/* client */
 #include "attribute.h"
 #include "audio.h"
 #include "chatline_g.h"
@@ -70,6 +73,10 @@
 #include "tilespec.h"
 #include "wldlg_g.h"
 
+/* agents */
+#include "agents.h"
+#include "cma_core.h"
+
 #include "packhand.h"
 
 static void city_packet_common(struct city *pcity, struct tile *pcenter,
@@ -1061,6 +1068,9 @@
 {
   freelog(LOG_DEBUG, "handle_begin_turn()");
 
+  /* Cities are guaranteed to be in consistent state. */
+  cma_thaw();
+
   /* probably duplicate insurance */
   update_client_state(C_S_RUNNING);
 
@@ -2433,6 +2443,9 @@
 {
   int i;
 
+  /* Cities will have inconsistent state until told otherwise */
+  cma_freeze();
+
   update_client_state(C_S_PREPARING);
 
   ruleset_data_free();
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#40282) Re: Patch: CMA fix when loading saved game

2008-06-15 Thread Marko Lindqvist

http://bugs.freeciv.org/Ticket/Display.html?id=40282 >

 Forwarding to tracker so patch is not ignored and lost.

2008/6/10 Patrick Smith:
> Hi,
>
> The attached patch seems to fix some CMA problems when loading a saved game.
> The city report still indicates fairly random CMA choices for cities, but
> some messages about the governor being confused seem to have disappeared,
> and I can now set the governor as I wish after loading a game, which wasn't
> always possible before.

 Do you have instructions how to reliably reproduce the problem?
 It would be great if you have savegame from which this is
reproducible. Of course, due to nature of the problem, this might be
hard to get. It would require savegame which can be loaded ok, but
would, when saved and reloaded again, produce the buggy behavior.


 - ML



patch
Description: Binary data
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev