[libchamplain/libchamplain-0-4] Load tiles near the middle first



commit dbc5d903cee920bb8899a0f67ea840adc2a50fe4
Author: Jason Woofenden <jason309 herkamire com>
Date:   Thu Jan 28 08:58:41 2010 -0500

    Load tiles near the middle first
    
    It starts just up/left of center, and loads tiles in concentric squares. Going
    clockwise (right, down, left, up).

 champlain/champlain-view.c |   77 +++++++++++++++++++++++++++----------------
 1 files changed, 48 insertions(+), 29 deletions(-)
---
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index b078cb0..b019f47 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -2330,40 +2330,59 @@ view_load_visible_tiles (ChamplainView *view)
     }
 
   //Load new tiles if needed
-  for (i = x_first; i < x_count; i++)
     {
-      for (j = y_first; j < y_count; j++)
-        {
-          gboolean exist = FALSE;
-          for (k = 0; k < champlain_zoom_level_tile_count (level) && !exist; k++)
-            {
-              ChamplainTile *tile = champlain_zoom_level_get_nth_tile (level, k);
-
-              if (tile == NULL)
-                continue;
+      // this all looks wrong because y_count/x_count are the max, not the width
+      gint arm_size, arm_max, spiral_pos;
+      gint dirs[5] = {0, 1, 0, -1, 0};
 
-              gint tile_x = champlain_tile_get_x (tile);
-              gint tile_y = champlain_tile_get_y (tile);
-
-              if ( tile_x == i && tile_y == j)
-                exist = TRUE;
-            }
+      i = x_first + (x_count - x_first) / 2 - 1;
+      j = y_first + (y_count - y_first) / 2 - 1;
+      arm_max = MAX(x_count - x_first, y_count - y_first) + 2;
 
-          if(!exist)
+      for (arm_size = 1; arm_size < arm_max; arm_size += 2)
+        {
+          for (spiral_pos = 0; spiral_pos < arm_size * 4; spiral_pos++)
             {
-              DEBUG ("Loading tile %d, %d, %d", champlain_zoom_level_get_zoom_level (level), i, j);
-              ChamplainTile *tile = champlain_tile_new ();
-              g_object_set (G_OBJECT (tile), "x", i, "y", j, "zoom-level", champlain_zoom_level_get_zoom_level (level), NULL);
-
-              g_signal_connect (tile, "notify::state", G_CALLBACK (tile_state_notify), view);
-              clutter_container_add (CLUTTER_CONTAINER (champlain_zoom_level_get_actor (level)),
-                  champlain_tile_get_actor (tile), NULL);
-
-              champlain_zoom_level_add_tile (level, tile);
-              champlain_map_source_fill_tile (priv->map_source, tile);
-
-              g_object_unref (tile);
+              if (j >= y_first && j < y_count && i >= x_first && i < x_count)
+                {
+                  gboolean exist = FALSE;
+
+                  for (k = 0; k < champlain_zoom_level_tile_count (level) && !exist; k++)
+                    {
+                      ChamplainTile *tile = champlain_zoom_level_get_nth_tile (level, k);
+
+                      if (tile == NULL)
+                        continue;
+
+                      gint tile_x = champlain_tile_get_x (tile);
+                      gint tile_y = champlain_tile_get_y (tile);
+
+                      if ( tile_x == i && tile_y == j)
+                        exist = TRUE;
+                    }
+
+                  if(!exist)
+                    {
+                      ChamplainTile *tile;
+
+                      DEBUG ("Loading tile %d, %d, %d", champlain_zoom_level_get_zoom_level (level), i, j);
+                      tile = champlain_tile_new ();
+                      g_object_set (G_OBJECT (tile), "x", i, "y", j, "zoom-level", champlain_zoom_level_get_zoom_level (level), NULL);
+                      g_signal_connect (tile, "notify::state", G_CALLBACK (tile_state_notify), view);
+                      clutter_container_add (CLUTTER_CONTAINER (champlain_zoom_level_get_actor (level)),
+                          champlain_tile_get_actor (tile), NULL);
+
+                      champlain_zoom_level_add_tile (level, tile);
+                      champlain_map_source_fill_tile (priv->map_source, tile);
+
+                      g_object_unref (tile);
+                    }
+                }
+              i += dirs[spiral_pos / arm_size + 1];
+              j += dirs[spiral_pos / arm_size];
             }
+          i--;
+          j--;
         }
     }
   view_update_state (view);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]