some refactoring and improvements in rendering

- don't render portals or links outside the bounds. the backend returns lots of link, and some portals, outside of the data tiles
- moved more of the render pass start process inside startRenderPass function, rather than having to call separate functions in the data request code
This commit is contained in:
Jon Atkins 2014-03-23 01:23:36 +00:00
parent f47b1211d2
commit 95ed0ddd7b
2 changed files with 28 additions and 57 deletions

View File

@ -14,14 +14,12 @@ window.Render = function() {
// under the portals // under the portals
this.LINK_VISIBLE_PIXEL_LENGTH = this.CLUSTER_SIZE; this.LINK_VISIBLE_PIXEL_LENGTH = this.CLUSTER_SIZE;
this.entityVisibilityZoom = undefined;
this.portalMarkerScale = undefined; this.portalMarkerScale = undefined;
} }
// start a render pass. called as we start to make the batch of data requests to the servers // start a render pass. called as we start to make the batch of data requests to the servers
window.Render.prototype.startRenderPass = function() { window.Render.prototype.startRenderPass = function(level,bounds) {
this.isRendering = true; this.isRendering = true;
this.deletedGuid = {}; // object - represents the set of all deleted game entity GUIDs seen in a render pass this.deletedGuid = {}; // object - represents the set of all deleted game entity GUIDs seen in a render pass
@ -29,6 +27,16 @@ window.Render.prototype.startRenderPass = function() {
this.seenPortalsGuid = {}; this.seenPortalsGuid = {};
this.seenLinksGuid = {}; this.seenLinksGuid = {};
this.seenFieldsGuid = {}; this.seenFieldsGuid = {};
this.bounds = bounds;
this.clearPortalsBelowLevel(level);
this.resetPortalClusters();
this.resetLinkVisibility();
this.rescalePortalMarkers();
} }
window.Render.prototype.clearPortalsBelowLevel = function(level) { window.Render.prototype.clearPortalsBelowLevel = function(level) {
@ -44,40 +52,6 @@ window.Render.prototype.clearPortalsBelowLevel = function(level) {
console.log('Render: deleted '+count+' portals by level'); console.log('Render: deleted '+count+' portals by level');
} }
window.Render.prototype.clearEntitiesOutsideBounds = function(bounds) {
var pcount=0, lcount=0, fcount=0;
for (var guid in window.portals) {
var p = portals[guid];
if (!bounds.contains (p.getLatLng()) && guid !== selectedPortal && !artifact.isInterestingPortal(guid)) {
this.deletePortalEntity(guid);
pcount++;
}
}
for (var guid in window.links) {
var l = links[guid];
if (!bounds.intersects (l.getBounds())) {
this.deleteLinkEntity(guid);
lcount++;
}
}
for (var guid in window.fields) {
var f = fields[guid];
if (!bounds.intersects (f.getBounds())) {
this.deleteFieldEntity(guid);
fcount++;
}
}
console.log('Render: deleted '+pcount+' portals, '+lcount+' links, '+fcount+' fields by bounds check');
}
// TODO? as well as clearing portals by level, and clearing entities outside the bounds...
// can we clear unneeded 'fake' links after zooming out? based on the portals no longer being available to construct
// the data? (not *required* - as they'll be removed in the endRenderPass code - but clearing things earlier rather than
// later is preferred, if possible)
// process deleted entity list and entity data // process deleted entity list and entity data
window.Render.prototype.processTileData = function(tiledata) { window.Render.prototype.processTileData = function(tiledata) {
@ -406,21 +380,15 @@ window.Render.prototype.createLinkEntity = function(ent,faked) {
window.Render.prototype.updateEntityVisibility = function() { window.Render.prototype.rescalePortalMarkers = function() {
if (this.entityVisibilityZoom === undefined || this.entityVisibilityZoom != map.getZoom()) { if (this.portalMarkerScale === undefined || this.portalMarkerScale != portalMarkerScale()) {
this.entityVisibilityZoom = map.getZoom(); this.portalMarkerScale = portalMarkerScale();
this.resetPortalClusters(); console.log('Render: map zoom '+map.getZoom()+' changes portal scale to '+portalMarkerScale()+' - redrawing all portals');
this.resetLinkVisibility();
if (this.portalMarkerScale === undefined || this.portalMarkerScale != portalMarkerScale()) { //NOTE: we're not calling this because it resets highlights - we're calling it as it
this.portalMarkerScale = portalMarkerScale(); // resets the style (inc size) of all portal markers, applying the new scale
resetHighlightedPortals();
console.log('Render: map zoom '+map.getZoom()+' changes portal scale to '+portalMarkerScale()+' - redrawing all portals');
//NOTE: we're not calling this because it resets highlights - we're calling it as it resets the style (inc size) of all portal markers
resetHighlightedPortals();
}
} }
} }
@ -458,7 +426,7 @@ window.Render.prototype.resetPortalClusters = function() {
var guid = c[i]; var guid = c[i];
var p = window.portals[guid]; var p = window.portals[guid];
var layerGroup = portalsFactionLayers[parseInt(p.options.level)][p.options.team]; var layerGroup = portalsFactionLayers[parseInt(p.options.level)][p.options.team];
if (i<this.CLUSTER_PORTAL_LIMIT || p.options.guid == selectedPortal || artifact.isInterestingPortal(p.options.guid)) { if ((i<this.CLUSTER_PORTAL_LIMIT || p.options.guid == selectedPortal || artifact.isInterestingPortal(p.options.guid)) && this.bounds.contains(p.getLatLng())) {
if (!layerGroup.hasLayer(p)) { if (!layerGroup.hasLayer(p)) {
layerGroup.addLayer(p); layerGroup.addLayer(p);
} }
@ -485,7 +453,9 @@ window.Render.prototype.addPortalToMapLayer = function(portal) {
// however, it won't make a lot of visible difference compared to just pushing to the end of the list, then // however, it won't make a lot of visible difference compared to just pushing to the end of the list, then
// adding to the visible layer if the list is below the limit // adding to the visible layer if the list is below the limit
if (this.portalClusters[cid].length < this.CLUSTER_PORTAL_LIMIT || portal.options.guid == selectedPortal || artifact.isInterestingPortal(portal.options.guid)) { if (this.portalClusters[cid].length < this.CLUSTER_PORTAL_LIMIT || portal.options.guid == selectedPortal || artifact.isInterestingPortal(portal.options.guid)) {
portalsFactionLayers[parseInt(portal.options.level)][portal.options.team].addLayer(portal); if (this.bounds.contains(portal.getLatLng())) {
portalsFactionLayers[parseInt(portal.options.level)][portal.options.team].addLayer(portal);
}
} }
} }
@ -501,7 +471,7 @@ window.Render.prototype.removePortalFromMapLayer = function(portal) {
var index = this.portalClusters[cid].indexOf(portal.options.guid); var index = this.portalClusters[cid].indexOf(portal.options.guid);
if (index >= 0) { if (index >= 0) {
this.portalClusters[cid].splice(index,1); this.portalClusters[cid].splice(index,1);
// FIXME? if this portal was in on the screen (in the first 10), and we still have 10+ portals, add the new 10to to the screen? // FIXME? if this portal was in on the screen (in the first 10), and we still have 10+ portals, add the new 10th to the screen?
} }
} }
} }
@ -520,6 +490,10 @@ window.Render.prototype.getPortalClusterID = function(portal) {
window.Render.prototype.linkVisible = function(link) { window.Render.prototype.linkVisible = function(link) {
if (!this.bounds.intersects(link.getBounds())) {
return false;
}
var lengthSquared = this.getLinkPixelLengthSquared (link); var lengthSquared = this.getLinkPixelLengthSquared (link);
return lengthSquared >= this.LINK_VISIBLE_PIXEL_LENGTH*this.LINK_VISIBLE_PIXEL_LENGTH; return lengthSquared >= this.LINK_VISIBLE_PIXEL_LENGTH*this.LINK_VISIBLE_PIXEL_LENGTH;

View File

@ -227,11 +227,8 @@ window.MapDataRequest.prototype.refresh = function() {
window.runHooks ('mapDataRefreshStart', {bounds: bounds, mapZoom: mapZoom, dataZoom: dataZoom, minPortalLevel: tileParams.level, tileBounds: dataBounds}); window.runHooks ('mapDataRefreshStart', {bounds: bounds, mapZoom: mapZoom, dataZoom: dataZoom, minPortalLevel: tileParams.level, tileBounds: dataBounds});
this.render.startRenderPass(); this.render.startRenderPass(tileParams.level, dataBounds);
this.render.clearPortalsBelowLevel(tileParams.level);
this.render.clearEntitiesOutsideBounds(dataBounds);
this.render.updateEntityVisibility();
this.render.processGameEntities(artifact.getArtifactEntities()); this.render.processGameEntities(artifact.getArtifactEntities());