Skip quadtree rechecks when a GameObject has not moved.
Avoid remove/add work for static sprites that still run update each frame.
@@ -41,12 +41,20 @@ class GameObject
41
41
if (!this.quadTree)
42
42
{ return; }
43
43
44
const x = this.transform.position.x;
45
const y = this.transform.position.y;
46
// Skip reinsert when the object has not moved since the last check.
47
if (this.node && this._qtX === x && this._qtY === y)
48
{ return; }
49
this._qtX = x;
50
this._qtY = y;
51
44
52
if (this.node)
45
53
{
46
if (this.transform.position.x < this.node.x1
47
|| this.transform.position.x > this.node.x2
48
|| this.transform.position.y < this.node.y1
49
|| this.transform.position.y > this.node.y2)
54
if (x < this.node.x1
55
|| x > this.node.x2
56
|| y < this.node.y1
57
|| y > this.node.y2)
50
58
{
51
59
this.quadTree.remove(this);
52
60
this.quadTree.add(this);
@@ -41,12 +41,20 @@ class GameObject41
if (!this.quadTree)41
if (!this.quadTree)42
{ return; }42
{ return; }43
43
44
const x = this.transform.position.x;45
const y = this.transform.position.y;46
// Skip reinsert when the object has not moved since the last check.47
if (this.node && this._qtX === x && this._qtY === y)48
{ return; }49
this._qtX = x;50
this._qtY = y;51
44
if (this.node)52
if (this.node)45
{53
{46
if (this.transform.position.x < this.node.x154
if (x < this.node.x147
|| this.transform.position.x > this.node.x255
|| x > this.node.x248
|| this.transform.position.y < this.node.y156
|| y < this.node.y149
|| this.transform.position.y > this.node.y2)57
|| y > this.node.y2)50
{58
{51
this.quadTree.remove(this);59
this.quadTree.remove(this);52
this.quadTree.add(this);60
this.quadTree.add(this);