Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2004:
[Freeciv-Dev] (PR#8210) WISHLIST: a sliding mapview
Home

[Freeciv-Dev] (PR#8210) WISHLIST: a sliding mapview

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8210) WISHLIST: a sliding mapview
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 19 Mar 2004 12:56:55 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8210 >

With GUI coordinates there are all sorts of cool things we can do. 
Unfortunately the all involve lots of math (straightforward linear 
algebra, but there's a lot of it).

One such thing is a sliding mapview.  Currently when the mapview 
recenters itself, it jumps all in one move.  It would be nice if smooth 
"sliding" would be possible.  I think this would greatly improve the 
feel of the game for new users (advanced users would probably just find 
it slowing them down).

Attached is a demo patch for a sliding mapview.  It achieves 90% of the 
functionality we want.  Unfortunately the other 10% will involve a lot 
of math.

In this patch every time the mapview recenters it does so over a 1s 
interval (this is probably an okay time for a default value).  There are 
several small and one large problem with it, however:

- It takes 1s to recenter no matter how far or short the recenter is. 
On my computer I find sliding halfway across the map in 1s gives a very 
pleasing result.  However moving just 1 tile in 1s is bad.  Using the 
scrollbars is obviously a problem.  This shouldn't be too hard to solve 
just by decreasing the sliding time for short moves.

- Sometimes we don't want to slide.  For instance when you start the 
game and center on your initial unit there shouldn't be sliding.  Here 
we just need a "smooth" parameter to center_tile_mapcanvas.

- The big problem is with wrapping, however.  If you slide in the X 
direction indefinitely, you'll see that when you come to the wrap 
boundaries you slide all the way around the map in the wrong direction. 
  This will take some tricky wrapping math to solve.  Basically we need 
a gui_distance_vector function which can conceal all the math.

This patch is just a demo at this point.  But Freeciv should integrate 
this functionality at some point, now that it's feasible.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.94
diff -u -r1.94 mapview_common.c
--- client/mapview_common.c     19 Mar 2004 20:22:07 -0000      1.94
+++ client/mapview_common.c     19 Mar 2004 20:44:21 -0000
@@ -329,6 +329,10 @@
 static void set_mapview_origin(int gui_x0, int gui_y0)
 {
   int xmin, xmax, ymin, ymax, xsize, ysize;
+  int start_x = mapview_canvas.gui_x0, start_y = mapview_canvas.gui_y0;
+  int diff_x, diff_y;
+  double timing_sec = 1.0, mytime;
+  static struct timer *anim_timer;
 
   /* First wrap/clip the position.  Wrapping is done in native positions
    * while clipping is done in scroll (native) positions. */
@@ -342,24 +346,37 @@
     gui_y0 = CLIP(ymin, gui_y0, ymax - ysize);
   }
 
+  if (mapview_canvas.gui_x0 == gui_x0 && mapview_canvas.gui_y0 == gui_y0) {
+    return;
+  }
+
+  diff_x = gui_x0 - start_x;
+  diff_y = gui_y0 - start_y;
+  anim_timer = renew_timer_start(anim_timer, TIMER_USER, TIMER_ACTIVE);
+
   /* Then update everything. */
-  if (mapview_canvas.gui_x0 != gui_x0 || mapview_canvas.gui_y0 != gui_y0) {
+  do {
     int map_center_x, map_center_y;
 
-    mapview_canvas.gui_x0 = gui_x0;
-    mapview_canvas.gui_y0 = gui_y0;
+    mytime = MIN(read_timer_seconds(anim_timer), timing_sec);
+
+    mapview_canvas.gui_x0 = start_x + diff_x * (mytime / timing_sec);
+    mapview_canvas.gui_y0 = start_y + diff_y * (mytime / timing_sec);
 
     get_center_tile_mapcanvas(&map_center_x, &map_center_y);
     center_tile_overviewcanvas(map_center_x, map_center_y);
     update_map_canvas_visible();
-    update_map_canvas_scrollbars();
     if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL) {
       create_line_at_mouse_pos();
     }
-  }
-  if (rectangle_active) {
-    update_rect_at_mouse_pos();
-  }
+    if (rectangle_active) {
+      update_rect_at_mouse_pos();
+    }
+    flush_dirty();
+    gui_flush();
+  } while (mytime < timing_sec);
+  
+  update_map_canvas_scrollbars();
 }
 
 /****************************************************************************

[Prev in Thread] Current Thread [Next in Thread]