Index: client/clinet.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v retrieving revision 1.67 diff -u -r1.67 clinet.c --- client/clinet.c 2002/03/05 15:46:19 1.67 +++ client/clinet.c 2002/03/17 14:28:56 @@ -73,6 +73,7 @@ #include "plrdlg_g.h" #include "repodlgs_g.h" #include "agents.h" +#include "mapview_common.h" /* unqueue_mapview_update */ #include "clinet.h" @@ -332,6 +333,8 @@ } else { close_socket_callback(&aconnection); } + + unqueue_mapview_update(); } /************************************************************************** @@ -380,6 +383,8 @@ close_socket_callback(&aconnection); } } + + unqueue_mapview_update(); } #ifdef WIN32_NATIVE Index: client/mapview_common.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v retrieving revision 1.11 diff -u -r1.11 mapview_common.c --- client/mapview_common.c 2002/02/26 19:57:08 1.11 +++ client/mapview_common.c 2002/03/17 14:28:56 @@ -17,6 +17,7 @@ #include +#include "log.h" #include "map.h" #include "support.h" @@ -348,5 +349,43 @@ my_snprintf(buffer, buffer_len, "%s -", pimprovement_type->name); } + } +} + +static bool need_mapview_update = FALSE; + +/************************************************************************** + This function, along with unqueue_mapview_update(), helps in updating + the mapview when a packet is received. Previously, we just called + update_map_canvas when (for instance) a city update was received. + Not only would this often end up with a lot of duplicated work, but it + would also draw over the city descriptions, which would then just + "disappear" from the mapview. The hack is to instead call + queue_mapview_update in place of this update, and later (after all + packets have been read) call unqueue_mapview_update. The functions + don't track which areas of the screen need updating, rather when the + unqueue is done we just update the whole visible mapqueue, and redraw + the city descriptions. + + Using these functions, updates are done correctly, and are probably + faster too. But it's a bit of a hack to insert this code into the + packet-handling code. +**************************************************************************/ +void queue_mapview_update(void) +{ + need_mapview_update = TRUE; +} + +/************************************************************************** + See comment for queue_mapview_update(). +**************************************************************************/ +void unqueue_mapview_update(void) +{ + freelog(LOG_DEBUG, "unqueue_mapview_update: need_update=%d", + need_mapview_update ? 1 : 0); + + if (need_mapview_update) { + update_map_canvas_visible(); + need_mapview_update = FALSE; } } Index: client/mapview_common.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v retrieving revision 1.5 diff -u -r1.5 mapview_common.h --- client/mapview_common.h 2002/02/26 10:27:37 1.5 +++ client/mapview_common.h 2002/03/17 14:28:56 @@ -65,4 +65,7 @@ void get_city_mapview_production(struct city *pcity, char *buf, size_t buf_len); +void queue_mapview_update(void); +void unqueue_mapview_update(void); + #endif /* FC__MAPVIEW_COMMON_H */ Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.229 diff -u -r1.229 packhand.c --- client/packhand.c 2002/03/17 09:40:04 1.229 +++ client/packhand.c 2002/03/17 14:28:58 @@ -334,7 +334,6 @@ bool city_is_new, city_has_changed_owner = FALSE, need_effect_update = FALSE; struct city *pcity; bool popup; - bool update_descriptions = FALSE; pcity=find_city_by_id(packet->id); @@ -351,18 +350,26 @@ idex_register_city(pcity); } else { + bool update_descriptions = FALSE; + city_is_new = FALSE; /* 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; } + /* update the descriptions if necessary */ + if (update_descriptions && tile_visible_mapcanvas(packet->x, packet->y)) { + queue_mapview_update(); + } + assert(pcity->id == packet->id); } @@ -461,31 +468,6 @@ handle_city_packet_common(pcity, city_is_new, popup, packet->diplomat_investigate); - /* update the descriptions if necessary */ - 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 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; - } - } - - if (really_update) { - update_city_descriptions(); - timer = new_timer; - timer_initialized = TRUE; - } - } - try_update_effects(need_effect_update); } @@ -515,12 +497,7 @@ } if (draw_map_grid && get_client_state() == CLIENT_GAME_RUNNING_STATE) { - int r = ((CITY_MAP_SIZE + 1) / 2); - int d = (2 * r) + 1; - int x = pcity->x - r; - int y = pcity->y - r; - normalize_map_pos(&x, &y); - update_map_canvas(x, y, d, d, TRUE); + queue_mapview_update(); } else { refresh_tile_mapcanvas(pcity->x, pcity->y, TRUE); }