BlueGit

timfa frameworkv3

optmisih

timfa Tim · pushed by timfa

Authored 2022-10-20 · 4 years ago

Hash
68c624b69546adb726825964295bf99cdb578e15
Parent
c604ca78
2 files changed +19 −4
framework/engine/objectComponents/collider.js +3 −2
@@ -82,9 +82,10 @@ class Collider
82 82 {
83 83 if (this.enabled && !this.gameObject.destroyed)
84 84 {
85 for (var i = 0; i < this.gameObject.scene.activeObjects.length; i++)
86 {
85 let offset = this.gameObject.scene.activeObjects.indexOf(this) + 1;
87 86
87 for (var i = offset; i < this.gameObject.scene.activeObjects.length; i++)
88 {
88 89 if (this.gameObject.scene.activeObjects[i] != this && this.gameObject.scene.activeObjects[i].collider.enabled)
89 90 {
90 91 if (this.widestDiagonal + this.gameObject.scene.activeObjects[i].collider.widestDiagonal < this.gameObject.transform.position.distanceTo(this.gameObject.scene.activeObjects[i].transform.position))
@@ -82,9 +82,10 @@ class Collider
82 {
82 {
83 if (this.enabled && !this.gameObject.destroyed)
83 if (this.enabled && !this.gameObject.destroyed)
84 {
84 {
85 for (var i = 0; i < this.gameObject.scene.activeObjects.length; i++)
85 let offset = this.gameObject.scene.activeObjects.indexOf(this) + 1;
86 {
87
86
87 for (var i = offset; i < this.gameObject.scene.activeObjects.length; i++)
88 {
88 if (this.gameObject.scene.activeObjects[i] != this && this.gameObject.scene.activeObjects[i].collider.enabled)
89 if (this.gameObject.scene.activeObjects[i] != this && this.gameObject.scene.activeObjects[i].collider.enabled)
89 {
90 {
90 if (this.widestDiagonal + this.gameObject.scene.activeObjects[i].collider.widestDiagonal < this.gameObject.transform.position.distanceTo(this.gameObject.scene.activeObjects[i].transform.position))
91 if (this.widestDiagonal + this.gameObject.scene.activeObjects[i].collider.widestDiagonal < this.gameObject.transform.position.distanceTo(this.gameObject.scene.activeObjects[i].transform.position))
framework/engine/scene.js +16 −2
@@ -12,6 +12,8 @@ class Scene
12 12 parentScene = null;
13 13 renderBackground = true;
14 14
15 pendingRemoval = [];
16
15 17 g_primary = false;
16 18
17 19 static DisplayModes = { absolute: 0, relativeToParent: 1 };
@@ -106,9 +108,10 @@ class Scene
106 108
107 109 removeObject (obj)
108 110 {
109 if (this.activeObjects.contains(obj))
111 let index = this.activeObjects.indexOf(obj);
112 if (index >= 0)
110 113 {
111 this.activeObjects.remove(obj);
114 this.pendingRemoval.push(index);
112 115 }
113 116 }
114 117
@@ -118,6 +121,17 @@ class Scene
118 121 {
119 122 this.activeObjects[i].update(deltaTime);
120 123 }
124
125 if (this.pendingRemoval.length)
126 {
127 this.pendingRemoval.sort();
128
129 for (let i = this.pendingRemoval.length; i >= 0; i++)
130 {
131 if (this.activeObjects[this.pendingRemoval[i]].destroyed)
132 this.activeObjects.removeAt(this.pendingRemoval[i]);
133 }
134 }
121 135 }
122 136
123 137 draw ()
@@ -12,6 +12,8 @@ class Scene
12 parentScene = null;
12 parentScene = null;
13 renderBackground = true;
13 renderBackground = true;
14
14
15 pendingRemoval = [];
16
15 g_primary = false;
17 g_primary = false;
16
18
17 static DisplayModes = { absolute: 0, relativeToParent: 1 };
19 static DisplayModes = { absolute: 0, relativeToParent: 1 };
@@ -106,9 +108,10 @@ class Scene
106
108
107 removeObject (obj)
109 removeObject (obj)
108 {
110 {
109 if (this.activeObjects.contains(obj))
111 let index = this.activeObjects.indexOf(obj);
112 if (index >= 0)
110 {
113 {
111 this.activeObjects.remove(obj);
114 this.pendingRemoval.push(index);
112 }
115 }
113 }
116 }
114
117
@@ -118,6 +121,17 @@ class Scene
118 {
121 {
119 this.activeObjects[i].update(deltaTime);
122 this.activeObjects[i].update(deltaTime);
120 }
123 }
124
125 if (this.pendingRemoval.length)
126 {
127 this.pendingRemoval.sort();
128
129 for (let i = this.pendingRemoval.length; i >= 0; i++)
130 {
131 if (this.activeObjects[this.pendingRemoval[i]].destroyed)
132 this.activeObjects.removeAt(this.pendingRemoval[i]);
133 }
134 }
121 }
135 }
122
136
123 draw ()
137 draw ()