From 17a81c09d9680a75cb2d9bee507a811db4feca65 Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 26 Feb 2013 17:34:59 +0800 Subject: [PATCH 1/3] New Feature: Remove lower level portal when portal render limit reached --- code/map_data.js | 4 +++- code/utils_misc.js | 60 +++++++++++++++++++++++++++++++++++++++++++++- main.js | 1 + 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/code/map_data.js b/code/map_data.js index 196a975e..3fbddbef 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -70,6 +70,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { // https://github.com/Leaflet/Leaflet/issues/185 var ppp = []; var p2f = {}; + PRL.resetOrInit(); $.each(m, function(qk, val) { $.each(val.deletedGameEntityGuids, function(ind, guid) { if(getTypeByGuid(guid) === TYPE_FIELD && window.fields[guid] !== undefined) { @@ -98,7 +99,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { ) return; - + PRL.pushPortal(ent); ppp.push(ent); // delay portal render } else if(ent[2].edge !== undefined) { renderLink(ent); @@ -147,6 +148,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { if(portalUpdateAvailable) renderPortalDetails(selectedPortal); resolvePlayerNames(); + renderUpdateStatus(); } // removes entities that are still handled by Leaflet, although they diff --git a/code/utils_misc.js b/code/utils_misc.js index 1f640e78..c4e9cdc7 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -2,6 +2,60 @@ // UTILS + MISC /////////////////////////////////////////////////////// +// PRL - Portal Render Limit +window.PRL = function() {} + +window.PRL.resetOrInit = function () { + PRL.initialized = true; + PRL.minLevel = -1; + PRL.minLevelSet = false; + PRL.newPortalsPerLevel = new Array(MAX_PORTAL_LEVEL+1); + for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) { + PRL.newPortalsPerLevel[i] = 0; + } +} + +window.PRL.pushPortal = function(ent) { + var portalGuid = ent[0]; + var portalLevel = parseInt(getPortalLevel(ent[2])); + var layerGroup = portalsLayers[portalLevel]; + + if(findEntityInLeaflet(layerGroup, window.portals, ent[0])) return; + PRL.newPortalsPerLevel[portalLevel]++; +} + +window.PRL.getMinLevel = function() { + if(!PRL.initialized) return -1; + if(!PRL.minLevelSet) PRL.setMinLevel(); + return PRL.minLevel; +} + +window.PRL.setMinLevel = function() { + var totalPortalsCount = 0; + PRL.minLevel = MAX_PORTAL_LEVEL + 1; + + // Find the min portal level under render limit + while(PRL.minLevel > 0) { + var oldPortalCount = layerGroupLength(portalsLayers[PRL.minLevel - 1]); + totalPortalsCount += oldPortalCount + PRL.newPortalsPerLevel[PRL.minLevel - 1]; + if(totalPortalsCount >= MAX_DRAWN_PORTALS) + break; + PRL.minLevel--; + } + + // If render limit reached at max portal level, still let portal at max level render + if(PRL.minLevel === MAX_PORTAL_LEVEL + 1) PRL.minLevel = MAX_PORTAL_LEVEL; + PRL.minLevelSet = true; +} + +window.layerGroupLength = function(layerGroup) { + var layersCount = 0; + var layers = layerGroup._layers; + if (layers) + layersCount = Object.keys(layers).length; + return layersCount; +} + // retrieves parameter from the URL?query=string. window.getURLParam = function(param) { var v = document.URL; @@ -152,7 +206,11 @@ window.getMinPortalLevel = function() { var z = map.getZoom(); if(z >= 16) return 0; var conv = ['impossible', 8,7,7,6,6,5,5,4,4,3,3,2,2,1,1]; - return conv[z]; + var minLevelByRenderLimit = PRL.getMinLevel(); + var result = minLevelByRenderLimit > conv[z] + ? minLevelByRenderLimit + : conv[z]; + return result; } // returns number of pixels left to scroll down before reaching the diff --git a/main.js b/main.js index 4523e8b4..97cf6a52 100644 --- a/main.js +++ b/main.js @@ -186,6 +186,7 @@ window.DESTROY_FIELD = 750; //AP for destroying field window.CAPTURE_PORTAL = 500; //AP for capturing a portal window.DEPLOY_RESONATOR = 125; //AP for deploying a resonator window.COMPLETION_BONUS = 250; //AP for deploying all resonators on portal +window.MAX_PORTAL_LEVEL = 8; // OTHER MORE-OR-LESS CONSTANTS ////////////////////////////////////// window.TEAM_NONE = 0; From 82792cf4be100f60af9f06ce77fc430bd45ff14f Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 26 Feb 2013 21:56:30 +0800 Subject: [PATCH 2/3] Bug Fix: minLevel of Portal Render Limit handler now persistent in same batch of request. --- code/map_data.js | 5 ++++- code/utils_misc.js | 25 ++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/code/map_data.js b/code/map_data.js index 3fbddbef..52e6a170 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -43,6 +43,8 @@ window.requestData = function() { } } + // Reset previous result of Portal Render Limit handler + PRL.init(); // finally send ajax requests $.each(tiles, function(ind, tls) { data = { minLevelOfDetail: -1 }; @@ -70,7 +72,8 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { // https://github.com/Leaflet/Leaflet/issues/185 var ppp = []; var p2f = {}; - PRL.resetOrInit(); + // Reset new portals count of Portal Render Limit handler + PRL.resetCounting(); $.each(m, function(qk, val) { $.each(val.deletedGameEntityGuids, function(ind, guid) { if(getTypeByGuid(guid) === TYPE_FIELD && window.fields[guid] !== undefined) { diff --git a/code/utils_misc.js b/code/utils_misc.js index c4e9cdc7..856232fa 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -2,14 +2,19 @@ // UTILS + MISC /////////////////////////////////////////////////////// -// PRL - Portal Render Limit +// PRL - Portal Render Limit handler window.PRL = function() {} -window.PRL.resetOrInit = function () { +window.PRL.init = function () { PRL.initialized = true; PRL.minLevel = -1; + PRL.resetCounting(); +} + +window.PRL.resetCounting = function() { PRL.minLevelSet = false; - PRL.newPortalsPerLevel = new Array(MAX_PORTAL_LEVEL+1); + if(!PRL.newPortalsPerLevel) + PRL.newPortalsPerLevel = new Array(MAX_PORTAL_LEVEL+1); for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) { PRL.newPortalsPerLevel[i] = 0; } @@ -32,19 +37,21 @@ window.PRL.getMinLevel = function() { window.PRL.setMinLevel = function() { var totalPortalsCount = 0; - PRL.minLevel = MAX_PORTAL_LEVEL + 1; + var newMinLevel = MAX_PORTAL_LEVEL + 1; // Find the min portal level under render limit - while(PRL.minLevel > 0) { - var oldPortalCount = layerGroupLength(portalsLayers[PRL.minLevel - 1]); - totalPortalsCount += oldPortalCount + PRL.newPortalsPerLevel[PRL.minLevel - 1]; + while(newMinLevel > 0) { + var oldPortalCount = layerGroupLength(portalsLayers[newMinLevel - 1]); + totalPortalsCount += oldPortalCount + PRL.newPortalsPerLevel[newMinLevel - 1]; if(totalPortalsCount >= MAX_DRAWN_PORTALS) break; - PRL.minLevel--; + newMinLevel--; } // If render limit reached at max portal level, still let portal at max level render - if(PRL.minLevel === MAX_PORTAL_LEVEL + 1) PRL.minLevel = MAX_PORTAL_LEVEL; + if(newMinLevel === MAX_PORTAL_LEVEL + 1) newMinLevel = MAX_PORTAL_LEVEL; + + if(newMinLevel > PRL.minLevel) PRL.minLevel = newMinLevel; PRL.minLevelSet = true; } From f4f3e7791faf90ec1e2203610a0eeafb93bcda87 Mon Sep 17 00:00:00 2001 From: Xelio Date: Wed, 27 Feb 2013 01:14:18 +0800 Subject: [PATCH 3/3] Code restructure of portal render limit handler --- code/map_data.js | 6 +-- code/portal_render_limit.js | 80 +++++++++++++++++++++++++++++++++++++ code/utils_misc.js | 55 +------------------------ 3 files changed, 84 insertions(+), 57 deletions(-) create mode 100644 code/portal_render_limit.js diff --git a/code/map_data.js b/code/map_data.js index 52e6a170..363240c4 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -44,7 +44,7 @@ window.requestData = function() { } // Reset previous result of Portal Render Limit handler - PRL.init(); + portalRenderLimit.init(); // finally send ajax requests $.each(tiles, function(ind, tls) { data = { minLevelOfDetail: -1 }; @@ -73,7 +73,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { var ppp = []; var p2f = {}; // Reset new portals count of Portal Render Limit handler - PRL.resetCounting(); + portalRenderLimit.resetCounting(); $.each(m, function(qk, val) { $.each(val.deletedGameEntityGuids, function(ind, guid) { if(getTypeByGuid(guid) === TYPE_FIELD && window.fields[guid] !== undefined) { @@ -102,7 +102,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { ) return; - PRL.pushPortal(ent); + portalRenderLimit.pushPortal(ent); ppp.push(ent); // delay portal render } else if(ent[2].edge !== undefined) { renderLink(ent); diff --git a/code/portal_render_limit.js b/code/portal_render_limit.js new file mode 100644 index 00000000..58961023 --- /dev/null +++ b/code/portal_render_limit.js @@ -0,0 +1,80 @@ + +// PORTAL RENDER LIMIT HANDLER /////////////////////////////////////// +// Functions to handle hiding low level portal when portal render +// limit is reached. +// +// After initialized and reset in window.requestData(), portals in +// response data will pass to function "pushPortal". Each new portal +// not on the map will add 1 to newPortalsPerLevel[portal level]. +// +// "getMinLevel" will be called by "getMinPortalLevel" in utils_misc.js +// to determine min portal level to draw on map. +// +// "getMinLevel" will return minLevel and call "setMinLevel" if +// minLevel hasn't set yet. +// +// In "setMinLevel", it will loop through all portal level from +// high to low, and sum total portal count (old + new) to check +// minLevel. +// +// In each call of window.handleDataResponse(), it will call +// "resetCounting" to reset previous response data. But minLevel +// is preserved and only replaced when render limit reached in +// higher level, until next window.requestData() called and reset. +// + +window.portalRenderLimit = function() {} + +window.portalRenderLimit.initialized = false; +window.portalRenderLimit.minLevelSet = false; +window.portalRenderLimit.minLevel = -1; +window.portalRenderLimit.newPortalsPerLevel = new Array(MAX_PORTAL_LEVEL + 1); + +window.portalRenderLimit.init = function () { + portalRenderLimit.initialized = true; + portalRenderLimit.minLevel = -1; + portalRenderLimit.resetCounting(); +} + +window.portalRenderLimit.resetCounting = function() { + portalRenderLimit.minLevelSet = false; + for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) { + portalRenderLimit.newPortalsPerLevel[i] = 0; + } +} + +window.portalRenderLimit.pushPortal = function(ent) { + var portalGuid = ent[0]; + var portalLevel = parseInt(getPortalLevel(ent[2])); + var layerGroup = portalsLayers[portalLevel]; + + if(findEntityInLeaflet(layerGroup, window.portals, ent[0])) return; + portalRenderLimit.newPortalsPerLevel[portalLevel]++; +} + +window.portalRenderLimit.getMinLevel = function() { + if(!portalRenderLimit.initialized) return -1; + if(!portalRenderLimit.minLevelSet) portalRenderLimit.setMinLevel(); + return portalRenderLimit.minLevel; +} + +window.portalRenderLimit.setMinLevel = function() { + var totalPortalsCount = 0; + var newMinLevel = MAX_PORTAL_LEVEL + 1; + + // Find the min portal level under render limit + while(newMinLevel > 0) { + var oldPortalCount = layerGroupLength(portalsLayers[newMinLevel - 1]); + var newPortalCount = portalRenderLimit.newPortalsPerLevel[newMinLevel - 1]; + totalPortalsCount += oldPortalCount + newPortalCount; + if(totalPortalsCount >= MAX_DRAWN_PORTALS) + break; + newMinLevel--; + } + + // If render limit reached at max portal level, still let portal at max level render + newMinLevel = Math.min(newMinLevel, MAX_PORTAL_LEVEL); + + portalRenderLimit.minLevel = Math.max(newMinLevel, portalRenderLimit.minLevel); + portalRenderLimit.minLevelSet = true; +} diff --git a/code/utils_misc.js b/code/utils_misc.js index 856232fa..8519a801 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -2,59 +2,6 @@ // UTILS + MISC /////////////////////////////////////////////////////// -// PRL - Portal Render Limit handler -window.PRL = function() {} - -window.PRL.init = function () { - PRL.initialized = true; - PRL.minLevel = -1; - PRL.resetCounting(); -} - -window.PRL.resetCounting = function() { - PRL.minLevelSet = false; - if(!PRL.newPortalsPerLevel) - PRL.newPortalsPerLevel = new Array(MAX_PORTAL_LEVEL+1); - for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) { - PRL.newPortalsPerLevel[i] = 0; - } -} - -window.PRL.pushPortal = function(ent) { - var portalGuid = ent[0]; - var portalLevel = parseInt(getPortalLevel(ent[2])); - var layerGroup = portalsLayers[portalLevel]; - - if(findEntityInLeaflet(layerGroup, window.portals, ent[0])) return; - PRL.newPortalsPerLevel[portalLevel]++; -} - -window.PRL.getMinLevel = function() { - if(!PRL.initialized) return -1; - if(!PRL.minLevelSet) PRL.setMinLevel(); - return PRL.minLevel; -} - -window.PRL.setMinLevel = function() { - var totalPortalsCount = 0; - var newMinLevel = MAX_PORTAL_LEVEL + 1; - - // Find the min portal level under render limit - while(newMinLevel > 0) { - var oldPortalCount = layerGroupLength(portalsLayers[newMinLevel - 1]); - totalPortalsCount += oldPortalCount + PRL.newPortalsPerLevel[newMinLevel - 1]; - if(totalPortalsCount >= MAX_DRAWN_PORTALS) - break; - newMinLevel--; - } - - // If render limit reached at max portal level, still let portal at max level render - if(newMinLevel === MAX_PORTAL_LEVEL + 1) newMinLevel = MAX_PORTAL_LEVEL; - - if(newMinLevel > PRL.minLevel) PRL.minLevel = newMinLevel; - PRL.minLevelSet = true; -} - window.layerGroupLength = function(layerGroup) { var layersCount = 0; var layers = layerGroup._layers; @@ -213,7 +160,7 @@ window.getMinPortalLevel = function() { var z = map.getZoom(); if(z >= 16) return 0; var conv = ['impossible', 8,7,7,6,6,5,5,4,4,3,3,2,2,1,1]; - var minLevelByRenderLimit = PRL.getMinLevel(); + var minLevelByRenderLimit = portalRenderLimit.getMinLevel(); var result = minLevelByRenderLimit > conv[z] ? minLevelByRenderLimit : conv[z];