perf(package): don't run points interval if there are no points

This commit is contained in:
Luke
2023-03-02 10:34:47 +01:00
parent b6af7e7166
commit 8b39f630fd

View File

@@ -42,12 +42,22 @@ export class Point<T = unknown> {
remove = () => { remove = () => {
const coords = Vector3.fromArray(GetEntityCoords(cache.ped, false)); const coords = Vector3.fromArray(GetEntityCoords(cache.ped, false));
const distance = coords.distance(this.coords); const distance = coords.distance(this.coords);
if (distance < this.distance && this.onExit) this.onExit(); if (distance < this.distance) {
this.onExit && this.onExit();
nearbyCount -= 1;
nearbyPoints = nearbyPoints.filter((point) => point.id !== this.id);
if (nearbyCount === 0 && tick) {
clearTick(tick);
tick = undefined;
}
}
points = points.filter((point) => point.id !== this.id); points = points.filter((point) => point.id !== this.id);
}; };
} }
setInterval(() => { setInterval(() => {
if (points.length < 1) return;
if (nearbyCount !== 0) { if (nearbyCount !== 0) {
nearbyPoints = []; nearbyPoints = [];
nearbyCount = 0; nearbyCount = 0;