@@ -13,6 +13,9 @@ onmessage = function (e) {
1313 }
1414 }
1515 }
16+ //if (!this.entityAreas) {
17+ // this.entityAreas = new Map();
18+ //}
1619 if ( ! this . streamedIn ) {
1720 this . streamedIn = new Map ( ) ;
1821 }
@@ -64,6 +67,14 @@ function addEntityToArea(entity) {
6467 for ( let i = startingYIndex ; i <= stoppingYIndex ; i ++ ) {
6568 for ( let j = startingXIndex ; j <= stoppingXIndex ; j ++ ) {
6669 this . areas [ j ] [ i ] . push ( entity ) ;
70+ /*let entityAreasArr;
71+ if (!this.entityAreas.has(entity.id)) {
72+ entityAreasArr = [];
73+ this.entityAreas.set(entity.id, entityAreasArr);
74+ } else {
75+ entityAreasArr = this.entityAreas.get(entity.id);
76+ }
77+ entityAreasArr.push([this.areas[j][i], this.areas[j][i].length - 1]);*/
6778 }
6879 }
6980}
@@ -88,11 +99,26 @@ function calcStartStopIndex(entity) {
8899}
89100
90101function removeEntityFromArea ( entity ) {
102+ /*if (this.entityAreas.has(entity.id)) {
103+ for (const [areaArr, index] of this.entityAreas.get(entity.id)) {
104+ areaArr.splice(index, 1);
105+ console.log("index to remove", index);
106+ console.log("new arr", areaArr);
107+ // Finds entities stored behind that and decrement the stored indexes by one
108+ for (let i = index; i < areaArr.length; i++) {
109+ if (this.entityAreas.has(areaArr[i].id)) {
110+ const [entityAreaArr, entityIndex] = this.entityAreas.get(areaArr[i].id);
111+ console.log("index to update", entityIndex);
112+ this.entityAreas.set(areaArr[i].id, [entityAreaArr, entityIndex - 1]);
113+ }
114+ }
115+ }
116+ }*/
91117 const [ startingYIndex , startingXIndex , stoppingYIndex , stoppingXIndex ] = calcStartStopIndex ( entity ) ;
92118 if ( startingYIndex == null || startingXIndex == null || stoppingYIndex == null || stoppingXIndex == null ) return ;
93119 for ( let i = startingYIndex ; i <= stoppingYIndex ; i ++ ) {
94120 for ( let j = startingXIndex ; j <= stoppingXIndex ; j ++ ) {
95- this . areas [ j ] [ i ] . filter ( ( arrEntity ) => arrEntity . id !== entity . id )
121+ this . areas [ j ] [ i ] = this . areas [ j ] [ i ] . filter ( ( arrEntity ) => arrEntity . id !== entity . id ) ;
96122 }
97123 }
98124}
0 commit comments