From caff9340d3a65aef70f30ba95c595681f286d0fc Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Fri, 24 Oct 2014 00:59:31 +0100 Subject: [PATCH] various tweaks to how IITC requests data tiles from the servers - change TILES_PER_REQUEST to 25, instead of 10 - to match current stock intel site - modify the zoom level faking IITC does. it still makes good use of IITC's caching, but no longer switches to a zoom level with larger tiles. recent changes to tile parameters for L8 portals on the standard intel site suggests that it's nicer to the servers to request more, but smaller, tiles, than fewer but larger ones - restored the 'show less portals when zoomed out' plugin. however, this works differently now. rather than faking the zoom level for larger tiles, it now effectively applies the portal level filter used by the standard site. just as many requests as stock, but much smaller responses with fewer portals, so faster rendering --- code/map_data_calc_tools.js | 97 ++++++++++---------- code/map_data_request.js | 12 ++- plugins/show-less-portals-zoomed-out.user.js | 27 +++++- 3 files changed, 80 insertions(+), 56 deletions(-) diff --git a/code/map_data_calc_tools.js b/code/map_data_calc_tools.js index dae02f93..7f0407eb 100755 --- a/code/map_data_calc_tools.js +++ b/code/map_data_calc_tools.js @@ -17,9 +17,36 @@ window.getMapZoomTileParameters = function(zoom) { MAX_TILES_PER_EDGE = 9000; ZOOM_TO_LEVEL = [8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1]; + // the current API allows the client to request a minimum portal level. the ZOOM_TO_LEVEL list are minimums + // however, in my view, this can return excessive numbers of portals in many cases. let's try an optional reduction + // of detail level at some zoom levels + + var level = ZOOM_TO_LEVEL[zoom] || 0; // default to level 0 (all portals) if not in array + + if (window.CONFIG_ZOOM_SHOW_LESS_PORTALS_ZOOMED_OUT) { + switch(level) { + case 7: + // usually L7+ portals - switch to L8 only + level = 8; + break; + case 6: + // usually L6+ portals - switch to L7+ + level = 7; + break; + + case 5: + case 4: + // level 4+ and 5+ - switch to L6+ + level = 6; + break; + + // no modifications for lower levels + } + } return { - level: ZOOM_TO_LEVEL[zoom] || 0, // default to level 0 (all portals) if not in array + level: level, + maxLevel: ZOOM_TO_LEVEL[zoom] || 0, // for reference, for log purposes, etc tilesPerEdge: ZOOM_TO_TILES_PER_EDGE[zoom] || MAX_TILES_PER_EDGE, zoom: zoom // include the zoom level, for reference }; @@ -37,63 +64,31 @@ window.getDataZoomForMapZoom = function(zoom) { zoom = 20; } + var origTileParams = getMapZoomTileParameters(zoom); + if (!window.CONFIG_ZOOM_DEFAULT_DETAIL_LEVEL) { - // some reasonable optimisations of data retreival - switch(zoom) { - case 2: - case 3: - // L8 portals - fall back to the furthest out view. less detail, faster retreival. cache advantages when zooming - // (note: iitc + stock both limited so zoom 0 never possible) - zoom = 1; - break; - - case 4: - // default is L7 - but this is a crazy number of tiles. fall back to L8 (but higher detail than above) - // (the back-end does, unfortunately, rarely (never?) returns large fields with L8-only portals - zoom = 3; - break; - - case 5: - case 6: - // default L7 - pull out to furthest L7 zoom - zoom = 4; - break; - - case 8: - // default L6 - pull back to highest L6 zoom - zoom = 7; - break; - - // L5 portals - only one zoom level - - case 11: - // default L4 - pull back to lower detail L4 - zoom = 10; - break; - - // L3 portals - only one zoom level - - case 14: - // L2 portals - pull back to furthest - zoom = 13; - break; - - case 16: - // L1 portals - pull back to furthest zoom - zoom = 15; - break; - - default: - if (zoom >= 18) { - // all portals - pull back to furthest zoom - zoom = 17; - } + // to improve the cacheing performance, we try and limit the number of zoom levels we retrieve data for + // to avoid impacting server load, we keep ourselves restricted to a zoom level with the sane numbre + // of tilesPerEdge and portal levels visible + + while (zoom > 1) { + var newTileParams = getMapZoomTileParameters(zoom-1); + if (newTileParams.tilesPerEdge != origTileParams.tilesPerEdge || newTileParams.level != origTileParams.level) { + // switching to zoom-1 would result in a different detail level - so we abort changing things break; + } else { + // changing to zoom = zoom-1 results in identical tile parameters - so we can safely step back + // with no increase in either server load or number of requests + zoom = zoom-1; + } } + } if (window.CONFIG_ZOOM_SHOW_MORE_PORTALS) { + // this is, in theory, slightly 'unfriendly' to the servers. in practice, this isn't the case - and it can even be nicer + // as it vastly improves cacheing in IITC and also reduces the amount of panning/zooming a user would do if (zoom >= 15 && zoom <= 16) { //L1+ and closer zooms. the 'all portals' zoom uses the same tile size, so it's no harm to request things at that zoom level zoom = 17; diff --git a/code/map_data_request.js b/code/map_data_request.js index 702b3463..fe9f22ab 100644 --- a/code/map_data_request.js +++ b/code/map_data_request.js @@ -25,7 +25,7 @@ window.MapDataRequest = function() { this.MAX_REQUESTS = 5; // this many tiles in one request - this.NUM_TILES_PER_REQUEST = 10; + this.NUM_TILES_PER_REQUEST = 25; // number of times to retry a tile after an error (including "error: TIMEOUT" now - as stock intel does) // TODO? different retry counters for TIMEOUT vs other errors..? @@ -232,7 +232,15 @@ window.MapDataRequest.prototype.refresh = function() { this.render.processGameEntities(artifact.getArtifactEntities()); - console.log('requesting data tiles at zoom '+dataZoom+' (L'+tileParams.level+'+ portals, '+tileParams.tilesPerEdge+' tiles per global edge), map zoom is '+mapZoom); + var logMessage = 'requesting data tiles at zoom '+dataZoom; + if (tileParams.level != tileParams.maxLevel) { + logMessage += ' (L'+tileParams.level+'+ portals - could have doneug L'+tileParams.maxLevel+'+'; + } else { + logMessage += ' (L'+tileParams.level+'+ portals'; + } + logMessage += ', '+tileParams.tilesPerEdge+' tiles per global edge), map zoom is '+mapZoom; + + console.log(logMessage); this.cachedTileCount = 0; diff --git a/plugins/show-less-portals-zoomed-out.user.js b/plugins/show-less-portals-zoomed-out.user.js index c18ae0c2..cd58731b 100644 --- a/plugins/show-less-portals-zoomed-out.user.js +++ b/plugins/show-less-portals-zoomed-out.user.js @@ -1,12 +1,12 @@ // ==UserScript== // @id iitc-plugin-show-less-portals@jonatkins // @name IITC plugin: Show less portals when zoomed out -// @category Deleted -// @version 0.2.0.@@DATETIMEVERSION@@ +// @category Tweaks +// @version 0.3.0.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ -// @description [@@BUILDNAME@@-@@BUILDDATE@@] IITC now defaults to showing fewer portals when zoomed out, making this plugin unnecessary. +// @description [@@BUILDNAME@@-@@BUILDDATE@@] Vastly reduce the detail level when zoomed out to level 11 or less (L4+ portals), to significantly reduce data usage when viewing large areas. // @include https://www.ingress.com/intel* // @include http://www.ingress.com/intel* // @match https://www.ingress.com/intel* @@ -14,3 +14,24 @@ // @grant none // ==/UserScript== +@@PLUGINSTART@@ + +// PLUGIN START //////////////////////////////////////////////////////// + + +// use own namespace for plugin +window.plugin.showLessPortalsZoomedOut = function() {}; + +window.plugin.showLessPortalsZoomedOut.setup = function() { + +// NOTE: the logic required is closely tied to the IITC+stock map detail level code - so the logic is moved there now +// and just enabled by this flag + window.CONFIG_ZOOM_SHOW_LESS_PORTALS_ZOOMED_OUT=true; + +}; + +var setup = window.plugin.showLessPortalsZoomedOut.setup; + +// PLUGIN END ////////////////////////////////////////////////////////// + +@@PLUGINEND@@