From 2c3a6c2df34b6a0de8f4a2f28bf79e1439edc306 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Fri, 1 May 2009 13:00:10 -0400 Subject: [PATCH] Merge map_load_visible_tiles and view_load_visible_tiles --- champlain/champlain-map.c | 83 -------------------------------------- champlain/champlain-view.c | 78 ++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 84 deletions(-) diff --git a/champlain/champlain-map.c b/champlain/champlain-map.c index 570af3f..8dacd1a 100644 --- a/champlain/champlain-map.c +++ b/champlain/champlain-map.c @@ -55,89 +55,6 @@ map_load_level(Map *map, NULL); } -void -map_load_visible_tiles (Map *map, - ChamplainView *view, - ChamplainMapSource *source, - ChamplainRectangle viewport) -{ - gint size; - - size = champlain_map_source_get_tile_size (source); - - if (viewport.x < 0) - viewport.x = 0; - if (viewport.y < 0) - viewport.y = 0; - - gint x_count = ceil((float)viewport.width / size) + 1; - gint y_count = ceil((float)viewport.height / size) + 1; - - gint x_first = viewport.x / size; - gint y_first = viewport.y / size; - - x_count += x_first; - y_count += y_first; - - if(x_count > champlain_zoom_level_get_width (map->current_level)) - x_count = champlain_zoom_level_get_width (map->current_level); - if(y_count > champlain_zoom_level_get_height (map->current_level)) - y_count = champlain_zoom_level_get_height (map->current_level); - - DEBUG ("Range %d, %d to %d, %d", x_first, y_first, x_count, y_count); - - int i, j; - guint k; - - // Get rid of old tiles first - for (k = 0; k < champlain_zoom_level_tile_count (map->current_level); k++) - { - ChamplainTile *tile = champlain_zoom_level_get_nth_tile (map->current_level, k); - gint tile_x = champlain_tile_get_x (tile); - gint tile_y = champlain_tile_get_y (tile); - if (tile_x < x_first || tile_x > x_count || - tile_y < y_first || tile_y > y_count) - { - ClutterActor *group, *actor; - if (champlain_tile_get_state (tile) == CHAMPLAIN_STATE_DONE) - { - actor = champlain_tile_get_actor (tile); - group = champlain_zoom_level_get_actor (map->current_level); - clutter_container_remove_actor (CLUTTER_CONTAINER (group), actor); - } - champlain_zoom_level_remove_tile (map->current_level, tile); - } - } - - //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 (map->current_level) && !exist; k++) - { - ChamplainTile *tile = champlain_zoom_level_get_nth_tile (map->current_level, k); - 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) - { - DEBUG ("Loading tile %d, %d, %d", champlain_zoom_level_get_zoom_level (map->current_level), i, j); - ChamplainTile *tile = champlain_tile_new (); - g_object_set (G_OBJECT (tile), "x", i, "y", j, NULL); - champlain_map_source_get_tile (source, view, map->current_level, tile); - champlain_zoom_level_add_tile (map->current_level, tile); - g_object_unref (tile); - } - } - } -} - gboolean map_zoom_in (Map *map, ChamplainMapSource *source) diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index 33fbc15..7bb520c 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -1430,11 +1430,86 @@ view_load_visible_tiles (ChamplainView *view) { ChamplainViewPrivate *priv = view->priv; ChamplainRectangle viewport = priv->viewport_size; + gint size; + ChamplainZoomLevel *level; viewport.x += priv->anchor.x; viewport.y += priv->anchor.y; - map_load_visible_tiles (priv->map, view, priv->map_source, viewport); + size = champlain_map_source_get_tile_size (priv->map_source); + level = priv->map->current_level; + + if (viewport.x < 0) + viewport.x = 0; + if (viewport.y < 0) + viewport.y = 0; + + gint x_count = ceil((float)viewport.width / size) + 1; + gint y_count = ceil((float)viewport.height / size) + 1; + + gint x_first = viewport.x / size; + gint y_first = viewport.y / size; + + x_count += x_first; + y_count += y_first; + + if(x_count > champlain_zoom_level_get_width (level)) + x_count = champlain_zoom_level_get_width (level); + if(y_count > champlain_zoom_level_get_height (level)) + y_count = champlain_zoom_level_get_height (level); + + DEBUG ("Range %d, %d to %d, %d", x_first, y_first, x_count, y_count); + + int i, j; + guint k; + + // Get rid of old tiles first + for (k = 0; k < champlain_zoom_level_tile_count (level); k++) + { + ChamplainTile *tile = champlain_zoom_level_get_nth_tile (level, k); + gint tile_x = champlain_tile_get_x (tile); + gint tile_y = champlain_tile_get_y (tile); + if (tile_x < x_first || tile_x > x_count || + tile_y < y_first || tile_y > y_count) + { + ClutterActor *group, *actor; + if (champlain_tile_get_state (tile) == CHAMPLAIN_STATE_DONE) + { + actor = champlain_tile_get_actor (tile); + group = champlain_zoom_level_get_actor (level); + clutter_container_remove_actor (CLUTTER_CONTAINER (group), actor); + } + champlain_zoom_level_remove_tile (level, tile); + } + } + + //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); + 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) + { + 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, NULL); + champlain_map_source_get_tile (priv->map_source, view, level, tile); + champlain_zoom_level_add_tile (level, tile); + g_object_unref (tile); + } + } + } view_update_state (view); } @@ -1920,3 +1995,4 @@ view_set_zoom_level_at (ChamplainView *view, g_object_notify (G_OBJECT (view), "zoom-level"); return TRUE; } + -- 2.39.5