diff --git a/code/boot.js b/code/boot.js
index 3fde7730..29b052cc 100644
--- a/code/boot.js
+++ b/code/boot.js
@@ -226,14 +226,16 @@ window.setupMap = function() {
// update map hooks
map.on('movestart zoomstart', window.requests.abort);
- map.on('moveend zoomend', function() { window.startRefreshTimeout(500) });
-
- // run once on init
- window.requestData();
- window.startRefreshTimeout();
+ map.on('moveend zoomend', function() { console.log('map moveend'); window.startRefreshTimeout(ON_MOVE_REFRESH*1000) });
window.addResumeFunction(window.requestData);
window.requests.addRefreshFunction(window.requestData);
+
+ // start the refresh process with a small timeout, so the first data request happens quickly
+ // (the code originally called the request function directly, and triggered a normal delay for the nxt refresh.
+ // however, the moveend/zoomend gets triggered on map load, causing a duplicate refresh. this helps prevent that
+ window.startRefreshTimeout(ON_MOVE_REFRESH*1000);
+
};
// renders player details into the website. Since the player info is
diff --git a/code/request_handling.js b/code/request_handling.js
index 6766fd5f..84617d54 100644
--- a/code/request_handling.js
+++ b/code/request_handling.js
@@ -8,6 +8,10 @@ window.failedRequestCount = 0;
window.requests = function() {}
+//time of last refresh
+window.requests._lastRefreshTime = 0;
+window.requests._quickRefreshPending = false;
+
window.requests.add = function(ajax) {
window.activeRequests.push(ajax);
renderUpdateStatus();
@@ -38,17 +42,19 @@ window.renderUpdateStatus = function() {
if(mapRunsUserAction)
t += 'paused during interaction';
else if(isIdle())
- t += 'Idle, not updating.';
+ t += 'Idle, not updating.';
else if(window.activeRequests.length > 0)
t += window.activeRequests.length + ' requests running.';
+ else if(window.requests._quickRefreshPending)
+ t += 'refreshing...';
else
t += 'Up to date.';
if(renderLimitReached())
- t += ' RENDER LIMIT '
+ t += ' RENDER LIMIT '
if(window.failedRequestCount > 0)
- t += ' ' + window.failedRequestCount + ' failed.'
+ t += ' ' + window.failedRequestCount + ' failed.'
t += '
(';
var minlvl = getMinPortalLevel();
@@ -78,19 +84,28 @@ window.startRefreshTimeout = function(override) {
if(refreshTimeout) clearTimeout(refreshTimeout);
var t = 0;
if(override) {
+ window.requests._quickRefreshPending = true;
t = override;
+ //ensure override can't cause too fast a refresh if repeatedly used (e.g. lots of scrolling/zooming)
+ timeSinceLastRefresh = new Date().getTime()-window.requests._lastRefreshTime;
+ if(timeSinceLastRefresh < 0) timeSinceLastRefresh = 0; //in case of clock adjustments
+ if(timeSinceLastRefresh < MINIMUM_OVERRIDE_REFRESH*1000)
+ t = (MINIMUM_OVERRIDE_REFRESH*1000-timeSinceLastRefresh);
} else {
+ window.requests._quickRefreshPending = false;
t = REFRESH*1000;
var adj = ZOOM_LEVEL_ADJ * (18 - window.map.getZoom());
if(adj > 0) t += adj*1000;
}
var next = new Date(new Date().getTime() + t).toLocaleTimeString();
- console.log('planned refresh: ' + next);
+ console.log('planned refresh in ' + (t/1000) + ' seconds, at ' + next);
refreshTimeout = setTimeout(window.requests._callOnRefreshFunctions, t);
+ renderUpdateStatus();
}
window.requests._onRefreshFunctions = [];
window.requests._callOnRefreshFunctions = function() {
+ console.log('running refresh at ' + new Date().toLocaleTimeString());
startRefreshTimeout();
if(isIdle()) {
@@ -101,6 +116,9 @@ window.requests._callOnRefreshFunctions = function() {
console.log('refreshing');
+ //store the timestamp of this refresh
+ window.requests._lastRefreshTime = new Date().getTime();
+
$.each(window.requests._onRefreshFunctions, function(ind, f) {
f();
});
@@ -121,4 +139,4 @@ window.requests.isLastRequest = function(action) {
}
});
return result;
-}
\ No newline at end of file
+}
diff --git a/main.js b/main.js
index 73ffe9d0..0431d98e 100644
--- a/main.js
+++ b/main.js
@@ -112,8 +112,10 @@ function wrapper() {
L_PREFER_CANVAS = false;
// CONFIG OPTIONS ////////////////////////////////////////////////////
-window.REFRESH = 30; // refresh view every 30s (base time)
+window.REFRESH = 60; // refresh view every 60s (base time)
window.ZOOM_LEVEL_ADJ = 5; // add 5 seconds per zoom level
+window.ON_MOVE_REFRESH = 0.8; //refresh time to use after a movement event
+window.MINIMUM_OVERRIDE_REFRESH = 5; //limit on refresh time since previous refresh, limiting repeated move refresh rate
window.REFRESH_GAME_SCORE = 5*60; // refresh game score every 5 minutes
window.MAX_IDLE_TIME = 4; // stop updating map after 4min idling
window.PRECACHE_PLAYER_NAMES_ZOOM = 17; // zoom level to start pre-resolving player names