Simplified auto update code. Removed pointless tile updating when there are only player updates. Removed redundant JSON parsing.

This commit is contained in:
Sascha L. Teichmann 2015-03-13 15:43:59 +01:00
parent 71636a5b4c
commit c3b634669a

View File

@ -74,48 +74,39 @@ L.Control.AutoUpdate = L.Control.extend({
this.socket.onmessage = function(evt) {
var updatePlayers = function(json) {
if (!(typeof json === "string")) {
return;
}
var players;
try {
players = JSON.parse(json);
}
catch (err) {
return;
}
var json = evt.data;
if (!(typeof json === "string")) {
return;
}
if (players.players) {
me.options.layer.clearLayers();
me.options.layer.addData(players.players);
}
}(evt.data);
var msg;
try {
msg = JSON.parse(json);
}
catch (err) {
return;
}
var invalidate = function(json) {
var invalidateAll = function(x, y, z) { return true; };
if (msg.players) {
me.options.layer.clearLayers();
me.options.layer.addData(msg.players);
}
if (!(typeof json === "string")) {
return invalidateAll;
}
var tiles;
var tileData;
try {
var tileData = JSON.parse(json);
} catch (err) {
return invalidateAll;
}
if (!tileData.tiles) {
return invalidateAll;
}
tiles = tileData.tiles;
var tilesData = msg.tiles;
if (!tilesData) {
return;
}
console.log("tiles found")
var invalidate = function(td) {
var pyramid = new Array(9);
var last = new Object();
pyramid[8] = last;
for (var i = 0; i < tiles.length; i++) {
var xz = tiles[i];
for (var i = 0; i < td.length; i++) {
var xz = td[i];
last[xz.X + "#" + xz.Z] = xz;
}
for (var p = 7; p >= 0; p--) {
@ -140,7 +131,8 @@ L.Control.AutoUpdate = L.Control.extend({
var k = x + "#" + z;
return level.hasOwnProperty(k);
};
} (evt.data);
} (tilesData);
var tiles = document.getElementsByTagName('img');
var re = /\/map\/([0-9]+)\/([0-9]+)\/([0-9]+).*/;