From 82792cf4be100f60af9f06ce77fc430bd45ff14f Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 26 Feb 2013 21:56:30 +0800 Subject: [PATCH] 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; }