perf: isCollidingWith to array

This commit is contained in:
cha0s 2019-05-01 17:34:24 -05:00
parent 1e5df2d9f5
commit ad7b03ee35

View File

@ -26,12 +26,16 @@ export class Collider extends decorate(Trait) {
initialize() {
this._collisionGroup = this.params.get('collisionGroup');
this._collidesWithGroups = this.params.get('collidesWithGroups').toJS();
this._isCollidingWith = {};
this._isCollidingWith = [];
this._isSensor = this.params.get('isSensor');
}
destroy() {
this._isCollidingWith = {};
for (let i = 0; i < this._isCollidingWith.length; i++) {
const entity = this._isCollidingWith[i];
entity.emit('collisionEnd', this.entity);
}
this._isCollidingWith = [];
}
get collisionGroup() {
@ -54,11 +58,17 @@ export class Collider extends decorate(Trait) {
return {
collisionEnd: (other) => {
delete this._isCollidingWith[other.instanceUuid];
const index = this._isCollidingWith.indexOf(other);
if (-1 !== index) {
this._isCollidingWith.splice(index, 1);
}
},
collisionStart: (other) => {
this._isCollidingWith[other.instanceUuid] = other;
const index = this._isCollidingWith.indexOf(other);
if (-1 === index) {
this._isCollidingWith.push(other);
}
},
};