Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] bugfix in updating of city descriptions (PR#1327)
Home

[Freeciv-Dev] bugfix in updating of city descriptions (PR#1327)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] bugfix in updating of city descriptions (PR#1327)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Thu, 14 Mar 2002 13:13:39 -0800 (PST)

In the process of looking at the new turns-to-grow part of the city descriptions, I ran across a bug that has bothered me for some time.

Updating of city productions in the city description (on the mapview) is currently not done properly. When you change a production, for instance, the mapview isn't updated. I previously thought this was just an oversight, but it looks like the code is all there to handle this.

But the code is buggy in two ways:

- It only updates when the type of production has changed; i.e. when you build something different. It doesn't update when the amount of production (shields) changes (which would change the turns-to-build, which is also shown).

- There's a timer built-in to prevent updates from happening more than once per second. But, there's a bug in the timer that causes updates to *never* happen (this is the "timer = time(NULL);" line). Oops.

The attached patch fixes these problems. It also makes two minor cleanups: I've reformated the if- into and if-else-if (see patch, it's obvious) and I've explicitly initialized a static variable (for clarity, such initialization is not strictly necessary).

This is a bugfix, pure and simple.  It should go in ASAP.

As the comment on the timer indicates, the time solution is less than perfect. I think a queued update would be better, but this is a topic for another day...

jason
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.228
diff -u -r1.228 packhand.c
--- client/packhand.c   2002/03/08 15:38:18     1.228
+++ client/packhand.c   2002/03/14 21:04:04
@@ -356,10 +356,11 @@
     /* Check if city desciptions should be updated */
     if (draw_city_names && strcmp(pcity->name, packet->name) != 0) {
       update_descriptions = TRUE;
-    }
-    if (draw_city_productions &&
-        ((pcity->is_building_unit != packet->is_building_unit) ||
-         (pcity->currently_building != packet->currently_building))) {
+    } else if (draw_city_productions &&
+               (pcity->is_building_unit != packet->is_building_unit ||
+                pcity->currently_building != packet->currently_building ||
+                pcity->shield_surplus != packet->shield_surplus ||
+                pcity->shield_stock != packet->shield_stock)) {
       update_descriptions = TRUE;
     }
 
@@ -465,14 +466,13 @@
   if (update_descriptions && tile_visible_mapcanvas(pcity->x,pcity->y)) {
     /* update it only every second (because of ChangeAll), this is not
        a perfect solution at all! */
-    static bool timer_initialized;
+    static bool timer_initialized = FALSE;
     static time_t timer;
     bool really_update = TRUE;
     time_t new_timer = time(NULL);
 
     if (timer_initialized) {
       double diff;
-      timer = time(NULL);
       diff = difftime(new_timer,timer);
       if (diff < 1.0) {
        really_update = FALSE;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] bugfix in updating of city descriptions (PR#1327), jdorje <=