BlueGit

timfa frameworkv3

Skip quadtree rechecks when a GameObject has not moved.

Avoid remove/add work for static sprites that still run update each frame.

timfa Tim Falken · pushed by timfa

Authored 2026-09-06 · 2 months ago

Hash
008ac6fe136a2bc3b0cb731a22de98a3cc8c1c9d
Parent
e982b80c
1 file changed +12 −4
framework/engine/gameobject.js +12 −4
@@ -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 GameObject
41 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.x1
54 if (x < this.node.x1
47 || this.transform.position.x > this.node.x2
55 || x > this.node.x2
48 || this.transform.position.y < this.node.y1
56 || y < this.node.y1
49 || 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);