-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlagreduction.txt
50 lines (41 loc) · 1.64 KB
/
lagreduction.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
GameServer.js
/////////////////////////// ORIGINAL ////////////////////////////////////
GameServer.prototype.updateMoveEngine = function () {
// Sort cells to move the cells close to the mouse first
var srt = [],
len = this.nodesPlayer.length;
for (var i = 0; i < len; i++) {
srt[i] = i;
}
for (var i = 0; i < len; i++) {
// Recycle unused nodes
if (typeof this.nodesPlayer[i] == "undefined") {
this.nodesPlayer.splice(i, 1);
len--;
continue;
}
var clientI = this.nodesPlayer[srt[i]].owner;
for (var j = i + 1; j < len; j++) {
var clientJ = this.nodesPlayer[srt[j]].owner;
if (this.getDist( this.nodesPlayer[srt[i]].position.x, this.nodesPlayer[srt[i]].position.y, clientI.mouse.x, clientI.mouse.y ) >
this.getDist( this.nodesPlayer[srt[j]].position.x, this.nodesPlayer[srt[j]].position.y, clientJ.mouse.x, clientJ.mouse.y )) {
var aux = srt[i];
srt[i] = srt[j];
srt[j] = aux;
}
}
}
// Move player cells
for (var i = 0, len = this.nodesPlayer.length; i < len; i++) {
var cell = this.nodesPlayer[srt[i]];
////////////////////////////// NEW ///////////////////////////////////
GameServer.prototype.updateMoveEngine = function () {
// Move player cells
for (var i = 0, len = this.nodesPlayer.length; i < len; i++) {
var cell = this.nodesPlayer[i];
// Recycle unused nodes
if (typeof cell == "undefined") {
this.nodesPlayer.splice(i, 1);
len--;
continue;
}