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:
parent
f47b1211d2
commit
95ed0ddd7b
@ -14,14 +14,12 @@ window.Render = function() {
|
||||
// under the portals
|
||||
this.LINK_VISIBLE_PIXEL_LENGTH = this.CLUSTER_SIZE;
|
||||
|
||||
this.entityVisibilityZoom = undefined;
|
||||
|
||||
this.portalMarkerScale = undefined;
|
||||
}
|
||||
|
||||
|
||||
// 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.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.seenLinksGuid = {};
|
||||
this.seenFieldsGuid = {};
|
||||
|
||||
this.bounds = bounds;
|
||||
|
||||
this.clearPortalsBelowLevel(level);
|
||||
|
||||
this.resetPortalClusters();
|
||||
this.resetLinkVisibility();
|
||||
|
||||
this.rescalePortalMarkers();
|
||||
|
||||
}
|
||||
|
||||
window.Render.prototype.clearPortalsBelowLevel = function(level) {
|
||||
@ -44,40 +52,6 @@ window.Render.prototype.clearPortalsBelowLevel = function(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
|
||||
window.Render.prototype.processTileData = function(tiledata) {
|
||||
@ -406,23 +380,17 @@ window.Render.prototype.createLinkEntity = function(ent,faked) {
|
||||
|
||||
|
||||
|
||||
window.Render.prototype.updateEntityVisibility = function() {
|
||||
if (this.entityVisibilityZoom === undefined || this.entityVisibilityZoom != map.getZoom()) {
|
||||
this.entityVisibilityZoom = map.getZoom();
|
||||
|
||||
this.resetPortalClusters();
|
||||
this.resetLinkVisibility();
|
||||
|
||||
window.Render.prototype.rescalePortalMarkers = function() {
|
||||
if (this.portalMarkerScale === undefined || this.portalMarkerScale != portalMarkerScale()) {
|
||||
this.portalMarkerScale = portalMarkerScale();
|
||||
|
||||
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
|
||||
//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, applying the new scale
|
||||
resetHighlightedPortals();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -458,7 +426,7 @@ window.Render.prototype.resetPortalClusters = function() {
|
||||
var guid = c[i];
|
||||
var p = window.portals[guid];
|
||||
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)) {
|
||||
layerGroup.addLayer(p);
|
||||
}
|
||||
@ -485,9 +453,11 @@ 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
|
||||
// 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.bounds.contains(portal.getLatLng())) {
|
||||
portalsFactionLayers[parseInt(portal.options.level)][portal.options.team].addLayer(portal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.Render.prototype.removePortalFromMapLayer = function(portal) {
|
||||
|
||||
@ -501,7 +471,7 @@ window.Render.prototype.removePortalFromMapLayer = function(portal) {
|
||||
var index = this.portalClusters[cid].indexOf(portal.options.guid);
|
||||
if (index >= 0) {
|
||||
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) {
|
||||
if (!this.bounds.intersects(link.getBounds())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var lengthSquared = this.getLinkPixelLengthSquared (link);
|
||||
|
||||
return lengthSquared >= this.LINK_VISIBLE_PIXEL_LENGTH*this.LINK_VISIBLE_PIXEL_LENGTH;
|
||||
|
@ -227,11 +227,8 @@ window.MapDataRequest.prototype.refresh = function() {
|
||||
|
||||
window.runHooks ('mapDataRefreshStart', {bounds: bounds, mapZoom: mapZoom, dataZoom: dataZoom, minPortalLevel: tileParams.level, tileBounds: dataBounds});
|
||||
|
||||
this.render.startRenderPass();
|
||||
this.render.clearPortalsBelowLevel(tileParams.level);
|
||||
this.render.clearEntitiesOutsideBounds(dataBounds);
|
||||
this.render.startRenderPass(tileParams.level, dataBounds);
|
||||
|
||||
this.render.updateEntityVisibility();
|
||||
|
||||
this.render.processGameEntities(artifact.getArtifactEntities());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user