improve refresh handling
- increase timeout on zoom/move end to 0.8 seconds - prevent repeated refreshes faster than every 5 seconds - delay initial refresh on load - should prevent immediate refresh after page load fix #200
This commit is contained in:
12
code/boot.js
12
code/boot.js
@ -226,14 +226,16 @@ window.setupMap = function() {
|
|||||||
|
|
||||||
// update map hooks
|
// update map hooks
|
||||||
map.on('movestart zoomstart', window.requests.abort);
|
map.on('movestart zoomstart', window.requests.abort);
|
||||||
map.on('moveend zoomend', function() { window.startRefreshTimeout(500) });
|
map.on('moveend zoomend', function() { console.log('map moveend'); window.startRefreshTimeout(ON_MOVE_REFRESH*1000) });
|
||||||
|
|
||||||
// run once on init
|
|
||||||
window.requestData();
|
|
||||||
window.startRefreshTimeout();
|
|
||||||
|
|
||||||
window.addResumeFunction(window.requestData);
|
window.addResumeFunction(window.requestData);
|
||||||
window.requests.addRefreshFunction(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
|
// renders player details into the website. Since the player info is
|
||||||
|
@ -8,6 +8,10 @@ window.failedRequestCount = 0;
|
|||||||
|
|
||||||
window.requests = function() {}
|
window.requests = function() {}
|
||||||
|
|
||||||
|
//time of last refresh
|
||||||
|
window.requests._lastRefreshTime = 0;
|
||||||
|
window.requests._quickRefreshPending = false;
|
||||||
|
|
||||||
window.requests.add = function(ajax) {
|
window.requests.add = function(ajax) {
|
||||||
window.activeRequests.push(ajax);
|
window.activeRequests.push(ajax);
|
||||||
renderUpdateStatus();
|
renderUpdateStatus();
|
||||||
@ -38,17 +42,19 @@ window.renderUpdateStatus = function() {
|
|||||||
if(mapRunsUserAction)
|
if(mapRunsUserAction)
|
||||||
t += 'paused during interaction';
|
t += 'paused during interaction';
|
||||||
else if(isIdle())
|
else if(isIdle())
|
||||||
t += '<span style="color:red">Idle, not updating.</span>';
|
t += '<span style="color:#888">Idle, not updating.</span>';
|
||||||
else if(window.activeRequests.length > 0)
|
else if(window.activeRequests.length > 0)
|
||||||
t += window.activeRequests.length + ' requests running.';
|
t += window.activeRequests.length + ' requests running.';
|
||||||
|
else if(window.requests._quickRefreshPending)
|
||||||
|
t += 'refreshing...';
|
||||||
else
|
else
|
||||||
t += 'Up to date.';
|
t += 'Up to date.';
|
||||||
|
|
||||||
if(renderLimitReached())
|
if(renderLimitReached())
|
||||||
t += ' <span style="color:red" class="help" title="Can only render so much before it gets unbearably slow. Not all entities are shown. Zoom in or increase the limit (search for MAX_DRAWN_*).">RENDER LIMIT</span> '
|
t += ' <span style="color:#f66" class="help" title="Can only render so much before it gets unbearably slow. Not all entities are shown. Zoom in or increase the limit (search for MAX_DRAWN_*).">RENDER LIMIT</span> '
|
||||||
|
|
||||||
if(window.failedRequestCount > 0)
|
if(window.failedRequestCount > 0)
|
||||||
t += ' <span style="color:red">' + window.failedRequestCount + ' failed</span>.'
|
t += ' <span style="color:#f66">' + window.failedRequestCount + ' failed</span>.'
|
||||||
|
|
||||||
t += '<br/>(';
|
t += '<br/>(';
|
||||||
var minlvl = getMinPortalLevel();
|
var minlvl = getMinPortalLevel();
|
||||||
@ -78,19 +84,28 @@ window.startRefreshTimeout = function(override) {
|
|||||||
if(refreshTimeout) clearTimeout(refreshTimeout);
|
if(refreshTimeout) clearTimeout(refreshTimeout);
|
||||||
var t = 0;
|
var t = 0;
|
||||||
if(override) {
|
if(override) {
|
||||||
|
window.requests._quickRefreshPending = true;
|
||||||
t = override;
|
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 {
|
} else {
|
||||||
|
window.requests._quickRefreshPending = false;
|
||||||
t = REFRESH*1000;
|
t = REFRESH*1000;
|
||||||
var adj = ZOOM_LEVEL_ADJ * (18 - window.map.getZoom());
|
var adj = ZOOM_LEVEL_ADJ * (18 - window.map.getZoom());
|
||||||
if(adj > 0) t += adj*1000;
|
if(adj > 0) t += adj*1000;
|
||||||
}
|
}
|
||||||
var next = new Date(new Date().getTime() + t).toLocaleTimeString();
|
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);
|
refreshTimeout = setTimeout(window.requests._callOnRefreshFunctions, t);
|
||||||
|
renderUpdateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.requests._onRefreshFunctions = [];
|
window.requests._onRefreshFunctions = [];
|
||||||
window.requests._callOnRefreshFunctions = function() {
|
window.requests._callOnRefreshFunctions = function() {
|
||||||
|
console.log('running refresh at ' + new Date().toLocaleTimeString());
|
||||||
startRefreshTimeout();
|
startRefreshTimeout();
|
||||||
|
|
||||||
if(isIdle()) {
|
if(isIdle()) {
|
||||||
@ -101,6 +116,9 @@ window.requests._callOnRefreshFunctions = function() {
|
|||||||
|
|
||||||
console.log('refreshing');
|
console.log('refreshing');
|
||||||
|
|
||||||
|
//store the timestamp of this refresh
|
||||||
|
window.requests._lastRefreshTime = new Date().getTime();
|
||||||
|
|
||||||
$.each(window.requests._onRefreshFunctions, function(ind, f) {
|
$.each(window.requests._onRefreshFunctions, function(ind, f) {
|
||||||
f();
|
f();
|
||||||
});
|
});
|
||||||
|
4
main.js
4
main.js
@ -112,8 +112,10 @@ function wrapper() {
|
|||||||
L_PREFER_CANVAS = false;
|
L_PREFER_CANVAS = false;
|
||||||
|
|
||||||
// CONFIG OPTIONS ////////////////////////////////////////////////////
|
// 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.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.REFRESH_GAME_SCORE = 5*60; // refresh game score every 5 minutes
|
||||||
window.MAX_IDLE_TIME = 4; // stop updating map after 4min idling
|
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
|
window.PRECACHE_PLAYER_NAMES_ZOOM = 17; // zoom level to start pre-resolving player names
|
||||||
|
Reference in New Issue
Block a user