[Freeciv-Dev] Re: (PR#7860) smoother unit "animation"
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7860 >
Jason Short wrote:
> My proposeal is that instead of specifying the number of steps, the user
> specifies the animation time (default 60 ms). Now in the animation
> instead of the current loop
>
> for (each step) {
> animate()
> wait_until_next_step()
> }
>
> we'd have
>
> while (time_is_remaining()) {
> animate_to_where_we_should_be()
> }
And the patch.
I personally can't see any difference in quality. However on my
computer there are 33 different steps (i.e., all of them) being drawn in
the same amount of time as the original 3 steps were being drawn.
Another advantage is that two of the client options are merged.
jason
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.129
diff -u -r1.129 control.c
--- client/control.c 24 Feb 2004 23:52:08 -0000 1.129
+++ client/control.c 13 Mar 2004 20:24:33 -0000
@@ -1227,7 +1227,7 @@
map_distance_vector(&dx, &dy, punit->x, punit->y,
target_unit->x, target_unit->y);
- if (smooth_move_units) {
+ if (smooth_move_unit_msec > 0) {
move_unit_map_canvas(punit, x, y, dx, dy);
}
refresh_tile_mapcanvas(x, y, FALSE);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.90
diff -u -r1.90 mapview_common.c
--- client/mapview_common.c 13 Mar 2004 19:07:29 -0000 1.90
+++ client/mapview_common.c 13 Mar 2004 20:24:34 -0000
@@ -1611,7 +1611,7 @@
void move_unit_map_canvas(struct unit *punit,
int map_x, int map_y, int dx, int dy)
{
- static struct timer *anim_timer = NULL;
+ static struct timer *anim_timer = NULL;
int dest_x, dest_y;
/* only works for adjacent-square moves */
@@ -1619,6 +1619,9 @@
return;
}
+ /* Go ahead and start the timer. */
+ anim_timer = renew_timer_start(anim_timer, TIMER_USER, TIMER_ACTIVE);
+
if (punit == get_unit_in_focus() && hover_state != HOVER_NONE) {
set_hover_state(NULL, HOVER_NONE);
update_unit_info_label(punit);
@@ -1632,9 +1635,11 @@
if (tile_visible_mapcanvas(map_x, map_y)
|| tile_visible_mapcanvas(dest_x, dest_y)) {
- int i, steps;
int start_x, start_y;
int canvas_dx, canvas_dy;
+ double timing_sec = (double)smooth_move_unit_msec / 1000.0, mytime;
+
+ assert(smooth_move_unit_msec > 0);
if (is_isometric) {
if (dx == 0) {
@@ -1667,50 +1672,40 @@
canvas_dy = NORMAL_TILE_HEIGHT * dy;
}
- /* Sanity check on the number of steps. */
- if (smooth_move_unit_steps < 2) {
- steps = 2;
- } else if (smooth_move_unit_steps > MAX(abs(canvas_dx),
- abs(canvas_dy))) {
- steps = MAX(abs(canvas_dx), abs(canvas_dy));
- } else {
- steps = smooth_move_unit_steps;
- }
-
map_to_canvas_pos(&start_x, &start_y, map_x, map_y);
if (is_isometric) {
start_y -= NORMAL_TILE_HEIGHT / 2;
}
- for (i = 1; i <= steps; i++) {
- int this_x, this_y;
+ /* Flush before we start animating. */
+ flush_dirty();
+ gui_flush();
- anim_timer = renew_timer_start(anim_timer, TIMER_USER, TIMER_ACTIVE);
+ do {
+ int new_x, new_y;
- this_x = start_x + (i * canvas_dx) / steps;
- this_y = start_y + (i * canvas_dy) / steps;
+ mytime = MIN(read_timer_seconds(anim_timer), timing_sec);
+
+ new_x = start_x + canvas_dx * (mytime / timing_sec);
+ new_y = start_y + canvas_dy * (mytime / timing_sec);
/* Backup the canvas store to the single_tile canvas. */
canvas_copy(mapview_canvas.single_tile, mapview_canvas.store,
- this_x, this_y, 0, 0, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
+ new_x, new_y, 0, 0, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
/* Draw */
- put_unit_full(punit, mapview_canvas.store, this_x, this_y);
- dirty_rect(this_x, this_y, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
+ put_unit_full(punit, mapview_canvas.store, new_x, new_y);
+ dirty_rect(new_x, new_y, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
/* Flush. */
flush_dirty();
gui_flush();
- if (i < steps) {
- usleep_since_timer_start(anim_timer, 10000);
- }
-
- /* Restore the backup. */
+ /* Restore the backup. It won't take effect until the next flush. */
canvas_copy(mapview_canvas.store, mapview_canvas.single_tile,
- 0, 0, this_x, this_y, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
- dirty_rect(this_x, this_y, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
- }
+ 0, 0, new_x, new_y, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
+ dirty_rect(new_x, new_y, UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
+ } while (mytime < timing_sec);
}
}
Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.94
diff -u -r1.94 options.c
--- client/options.c 6 Mar 2004 11:13:04 -0000 1.94
+++ client/options.c 13 Mar 2004 20:24:34 -0000
@@ -55,8 +55,7 @@
bool solid_color_behind_units = FALSE;
bool sound_bell_at_new_turn = FALSE;
-bool smooth_move_units = TRUE;
-int smooth_move_unit_steps = 3;
+int smooth_move_unit_msec = 30;
bool do_combat_animation = TRUE;
bool ai_popup_windows = FALSE;
bool ai_manual_turn_done = FALSE;
@@ -94,8 +93,8 @@
GEN_BOOL_OPTION(solid_color_behind_units, N_("Solid unit background color")),
GEN_BOOL_OPTION(sound_bell_at_new_turn, N_("Sound bell at new turn")),
- GEN_BOOL_OPTION(smooth_move_units, N_("Smooth unit moves")),
- GEN_INT_OPTION(smooth_move_unit_steps, N_("Smooth unit move steps")),
+ GEN_INT_OPTION(smooth_move_unit_msec,
+ N_("Unit movement animation time (milliseconds)")),
GEN_BOOL_OPTION(do_combat_animation, N_("Show combat animation")),
GEN_BOOL_OPTION(ai_popup_windows, N_("Popup dialogs in AI Mode")),
GEN_BOOL_OPTION(ai_manual_turn_done, N_("Manual Turn Done in AI Mode")),
Index: client/options.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.h,v
retrieving revision 1.35
diff -u -r1.35 options.h
--- client/options.h 6 Feb 2004 01:01:11 -0000 1.35
+++ client/options.h 13 Mar 2004 20:24:34 -0000
@@ -28,8 +28,7 @@
extern bool solid_color_behind_units;
extern bool sound_bell_at_new_turn;
-extern bool smooth_move_units;
-extern int smooth_move_unit_steps;
+extern int smooth_move_unit_msec;
extern bool do_combat_animation;
extern bool ai_popup_windows;
extern bool ai_manual_turn_done;
|
|