mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
perf(package): only run points loop when there's at least one point
This commit is contained in:
@@ -6,6 +6,7 @@ let nearbyPoints: Point[] = [];
|
||||
let nearbyCount: number = 0;
|
||||
let closestPoint: Point | undefined;
|
||||
let tick: number | undefined;
|
||||
let pointsInterval: CitizenTimer;
|
||||
|
||||
interface LibPoint<T = unknown> {
|
||||
coords: number[];
|
||||
@@ -37,6 +38,9 @@ export class Point<T = unknown> {
|
||||
this.nearby = point.nearby;
|
||||
this.args = point.args;
|
||||
points.push(this);
|
||||
if (points.length === 1) {
|
||||
startPointsInterval();
|
||||
}
|
||||
}
|
||||
|
||||
remove = () => {
|
||||
@@ -51,10 +55,14 @@ export class Point<T = unknown> {
|
||||
}
|
||||
}
|
||||
points = points.filter((point) => point.id !== this.id);
|
||||
if (points.length === 0) {
|
||||
clearInterval(pointsInterval);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
const startPointsInterval = () => {
|
||||
pointsInterval = setInterval(() => {
|
||||
if (points.length < 1) return;
|
||||
|
||||
if (nearbyCount !== 0) {
|
||||
@@ -119,3 +127,4 @@ setInterval(() => {
|
||||
tick = undefined;
|
||||
}
|
||||
}, 300);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user