Skip to content

Commit c58c6d8

Browse files
Fix entity delete in worker
1 parent 54993ea commit c58c6d8

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

api/AltV.Net.NetworkingEntity/Client/proto.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Proto {
1010
this.ServerEvent = root.lookupType("Entity.ServerEvent");
1111
this.AuthEvent = root.lookupType("Entity.AuthEvent");
1212
this.EntityStreamInEvent = root.lookupType("Entity.EntityStreamInEvent");
13-
this.EntityStreamOutEvent= root.lookupType("Entity.EntityStreamOutEvent");
13+
this.EntityStreamOutEvent = root.lookupType("Entity.EntityStreamOutEvent");
1414
}
1515
}
1616

api/AltV.Net.NetworkingEntity/Client/streaming-worker.mjs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

90101
function 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

Comments
 (0)