[Freeciv-Dev] (PR#8833) improvement to do_move_unit
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8833 >
This patch improves do_move_unit. It cuts out several redraws:
- We don't have to redraw the source tile after the move animation. The
way the animation is buffered it's not necessary.
- Rather than redraw the dest tile after the move animation - and risk
having the caller redraw it as well - only the caller redraws it.
- Invisiblity check is removed. See PR#8831.
jason
? client/output
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.135
diff -u -r1.135 control.c
--- client/control.c 17 May 2004 01:29:46 -0000 1.135
+++ client/control.c 25 May 2004 05:24:09 -0000
@@ -1282,15 +1282,18 @@
/**************************************************************************
Called to have the client move a unit from one location to another,
- updating the graphics if necessary.
+ updating the graphics if necessary. The caller must redraw the target
+ location after the move.
**************************************************************************/
void do_move_unit(struct unit *punit, struct unit *target_unit)
{
int x, y;
- bool was_teleported;
-
+ bool was_teleported, do_animation;
+
was_teleported = !is_tiles_adjacent(punit->x, punit->y,
target_unit->x, target_unit->y);
+ do_animation = (!was_teleported && smooth_move_unit_msec > 0);
+
x = punit->x;
y = punit->y;
@@ -1303,10 +1306,6 @@
unit_list_unlink(&map_get_tile(x, y)->units, punit);
- if (punit->transported_by == -1) {
- refresh_tile_mapcanvas(x, y, FALSE);
- }
-
if (game.player_idx == punit->owner
&& auto_center_on_unit
&& !unit_has_orders(punit)
@@ -1317,15 +1316,20 @@
center_tile_mapcanvas(target_unit->x, target_unit->y);
}
- if (punit->transported_by == -1 && !was_teleported) {
- int dx, dy;
+ if (punit->transported_by == -1) {
+ /* We have to refresh the tile before moving. This will draw
+ * the tile without the unit (because it was unlinked above). */
+ refresh_tile_mapcanvas(x, y, FALSE);
- map_distance_vector(&dx, &dy, punit->x, punit->y,
- target_unit->x, target_unit->y);
- if (smooth_move_unit_msec > 0) {
+ if (do_animation) {
+ int dx, dy;
+
+ /* For the duration of the animation the unit exists at neither
+ * tile. */
+ map_distance_vector(&dx, &dy, punit->x, punit->y,
+ target_unit->x, target_unit->y);
move_unit_map_canvas(punit, x, y, dx, dy);
}
- refresh_tile_mapcanvas(x, y, FALSE);
}
punit->x = target_unit->x;
@@ -1333,25 +1337,6 @@
unit_list_insert(&map_get_tile(punit->x, punit->y)->units, punit);
- square_iterate(punit->x, punit->y, 2, x, y) {
- bool refresh = FALSE;
- unit_list_iterate(map_get_tile(x, y)->units, pu) {
- if (unit_flag(pu, F_PARTIAL_INVIS)) {
- refresh = TRUE;
- goto out;
- }
- } unit_list_iterate_end;
- out:
- if (refresh) {
- refresh_tile_mapcanvas(x, y, FALSE);
- }
- } square_iterate_end;
-
- if (punit->transported_by == -1
- && tile_get_known(punit->x, punit->y) == TILE_KNOWN) {
- refresh_tile_mapcanvas(punit->x, punit->y, FALSE);
- }
-
if (punit_focus == punit) update_menus();
}
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.370
diff -u -r1.370 packhand.c
--- client/packhand.c 23 May 2004 06:10:56 -0000 1.370
+++ client/packhand.c 25 May 2004 05:24:10 -0000
@@ -1095,6 +1095,9 @@
/* Show where the unit is going. */
do_move_unit(punit, packet_unit);
+ if (punit->transported_by != -1) {
+ repaint_unit = TRUE;
+ }
if(pcity) {
if (can_player_see_units_in_city(game.player_ptr, pcity)) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8833) improvement to do_move_unit,
Jason Short <=
|
|