refactor: don't juggle types; avoid getter

This commit is contained in:
cha0s 2019-05-02 20:01:09 -05:00
parent 7ccb89226c
commit b899a9dc48

View File

@ -6,8 +6,8 @@ export class Listed extends Trait {
initialize() { initialize() {
this._list = undefined; this._list = undefined;
this.quadTreeAabb = undefined; this.quadTreeAabb = [];
this.quadTreeNodes = undefined; this.quadTreeNodes = [];
} }
destroy() { destroy() {
@ -51,14 +51,6 @@ export class Listed extends Trait {
} }
get doesNeedReset() { get doesNeedReset() {
if (AVOCADO_CLIENT) {
return false;
}
if (!this.quadTreeAabb) {
return true;
}
const aabb = this.entity.visibleAabb;
return !Rectangle.isInside(this.quadTreeAabb, aabb);
} }
removeQuadTreeNodes() { removeQuadTreeNodes() {
@ -66,18 +58,25 @@ export class Listed extends Trait {
if (!list) { if (!list) {
return; return;
} }
if (this.quadTreeNodes) { if (this.quadTreeNodes.length > 0) {
const quadTree = list.quadTree; const quadTree = list.quadTree;
for (const node of this.quadTreeNodes) { for (const node of this.quadTreeNodes) {
quadTree.remove(node); quadTree.remove(node);
} }
this.quadTreeAabb = undefined; this.quadTreeAabb = [];
this.quadTreeNodes = undefined; this.quadTreeNodes = [];
} }
} }
resetQuadTreeNodes() { resetQuadTreeNodes() {
if (!this.doesNeedReset) { if (AVOCADO_CLIENT) {
return;
}
const aabb = this.entity.visibleAabb;
if (
this.quadTreeAabb.length > 0
&& Rectangle.isInside(this.quadTreeAabb, aabb)
) {
return; return;
} }
this.removeQuadTreeNodes(); this.removeQuadTreeNodes();